Skip to content

Commit

Permalink
Merge pull request #133 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Nov 12, 2020
2 parents d35e15e + f2fd613 commit f41ebfc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## [Unreleased]
### Added
- A method to emit a log entry for a certain item:
com.epam.reportportal.service.ReportPortal.emitLog(io.reactivex.Maybe<java.lang.String>, java.util.function.Function<java.lang.String,com.epam.ta.reportportal.ws.model.log.SaveLogRQ>)
### Changed
- Apache Tika was updated on version 1.20

## [5.0.14]
### Changed
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies {
shadow 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
shadow 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
shadow 'io.reactivex.rxjava2:rxjava:2.2.10'
shadow 'org.apache.tika:tika-core:1.4'
shadow 'org.apache.tika:tika-core:1.20'
shadow 'org.slf4j:slf4j-api:1.7.25'

testImplementation('org.junit.platform:junit-platform-runner:1.6.0') {
Expand Down
36 changes: 25 additions & 11 deletions src/main/java/com/epam/reportportal/service/LoggingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.reactivex.subjects.PublishSubject;
import org.reactivestreams.Publisher;

import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
Expand Down Expand Up @@ -126,23 +127,36 @@ public static Completable complete() {

}

private SaveLogRQ prepareRequest(String launchId, String itemId, final java.util.function.Function<String, SaveLogRQ> logSupplier)
throws IOException {
final SaveLogRQ rq = logSupplier.apply(itemId);
rq.setLaunchUuid(launchId);
SaveLogRQ.File file = rq.getFile();
if (convertImages && null != file && isImage(file.getContentType())) {
final TypeAwareByteSource source = convert(ByteSource.wrap(file.getContent()));
file.setContent(source.read());
file.setContentType(source.getMediaType());
}
return rq;
}

/**
* Emits log. Basically, put it into processing pipeline
*
* @param logSupplier Log Message Factory. Key if the function is actual test item ID
*/
public void emit(final java.util.function.Function<String, SaveLogRQ> logSupplier) {
emitter.onNext(launchUuid.zipWith(itemUuid, (launchId, itemId) -> {
final SaveLogRQ rq = logSupplier.apply(itemId);
rq.setLaunchUuid(launchId);
SaveLogRQ.File file = rq.getFile();
if (convertImages && null != file && isImage(file.getContentType())) {
final TypeAwareByteSource source = convert(ByteSource.wrap(file.getContent()));
file.setContent(source.read());
file.setContentType(source.getMediaType());
}
return rq;
}));
emitter.onNext(launchUuid.zipWith(itemUuid, (launchId, itemId) -> prepareRequest(launchId, itemId, logSupplier)));
}

/**
* Emits log. Basically, put it into processing pipeline
*
* @param logItemUuid Test Item ID promise
* @param logSupplier Log Message Factory. Key if the function is actual test item ID
*/
public void emit(final Maybe<String> logItemUuid, final java.util.function.Function<String, SaveLogRQ> logSupplier) {
emitter.onNext(launchUuid.zipWith(logItemUuid, (launchId, itemId) -> prepareRequest(launchId, itemId, logSupplier)));
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/epam/reportportal/service/ReportPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ public static boolean emitLaunchLog(final Function<String, SaveLogRQ> logSupplie
return false;
}

/**
* Emits log message if there is any active context attached to the current thread
*
* @param itemUuid Test Item ID promise
* @param logSupplier Log supplier. Converts current Item ID to the {@link SaveLogRQ} object
* @return true if log has been emitted
*/
public static boolean emitLog(Maybe<String> itemUuid, final Function<String, SaveLogRQ> logSupplier) {
final LoggingContext loggingContext = LoggingContext.CONTEXT_THREAD_LOCAL.get().peek();
if (null != loggingContext) {
loggingContext.emit(itemUuid, logSupplier);
return true;
}
return false;
}

/**
* Emits log message if there is any active context attached to the current thread
*
Expand Down

0 comments on commit f41ebfc

Please sign in to comment.