use of org.apache.commons.lang3.StringUtils.isEmpty in project ice by JBEI.
the class FileResource method downloadSequence.
@GET
@Path("{partId}/sequence/{type}")
public Response downloadSequence(@PathParam("partId") final String partId, @PathParam("type") final String downloadType, @DefaultValue("-1") @QueryParam("remoteId") long remoteId, @QueryParam("sid") String sid) {
if (StringUtils.isEmpty(sessionId))
sessionId = sid;
final String userId = getUserId(sessionId);
if (remoteId != -1) {
RemoteSequence sequence = new RemoteSequence(remoteId, Long.decode(partId));
final InputStreamWrapper wrapper = sequence.get(downloadType);
StreamingOutput stream = output -> IOUtils.copy(wrapper.getInputStream(), output);
return addHeaders(Response.ok(stream), wrapper.getName());
} else {
InputStreamWrapper wrapper = new PartSequence(userId, partId).toFile(SequenceFormat.fromString(downloadType), true);
StreamingOutput stream = output -> IOUtils.copy(wrapper.getInputStream(), output);
return addHeaders(Response.ok(stream), wrapper.getName());
}
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project jena by apache.
the class FusekiConfig method oldStyleCompat.
/**
* Old style compatibility.
* For each endpoint in "endpoints1", ensure there is an endpoint on the dataset (endpoint name "") itself.
* Combine the authentication as "AND" of named endpoints authentication.
*/
private static Collection<Endpoint> oldStyleCompat(DataService.Builder dataService, Set<Endpoint> endpoints1) {
Map<Operation, Endpoint> endpoints3 = new HashMap<>();
endpoints1.forEach(ep -> {
Operation operation = ep.getOperation();
AuthPolicy auth = ep.getAuthPolicy();
if (!StringUtils.isEmpty(ep.getName())) {
if (endpoints3.containsKey(operation)) {
Endpoint ep1 = endpoints3.get(operation);
// Accumulate Authorization.
auth = AuthPolicyList.merge(ep1.getAuthPolicy(), auth);
Endpoint ep2 = Endpoint.create(ep.getOperation(), "", auth);
endpoints3.put(operation, ep2);
} else {
Endpoint ep2 = Endpoint.create(operation, "", auth);
endpoints3.put(operation, ep2);
}
}
});
// Now, after making all legacy endpoints, remove any that are explicit defined in endpoints1.
// Given the small numbers involved, it is easier to do it this way than
// additional logic in the first pass over endpoints1.
endpoints1.stream().filter(ep -> StringUtils.isEmpty(ep.getName())).forEach(ep -> endpoints3.remove(ep.getOperation()));
return endpoints3.values();
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project dhis2-core by dhis2.
the class AbstractEnrollmentService method validateRequest.
private ImportSummary validateRequest(Program program, org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance, Enrollment enrollment, OrganisationUnit organisationUnit, ImportOptions importOptions) {
ImportSummary importSummary = new ImportSummary(enrollment.getEnrollment());
String error = validateProgramForEnrollment(program, enrollment, organisationUnit, importOptions);
if (!StringUtils.isEmpty(error)) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setDescription(error);
importSummary.incrementIgnored();
return importSummary;
}
ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
params.setOrganisationUnitMode(OrganisationUnitSelectionMode.ALL);
params.setSkipPaging(true);
params.setProgram(program);
params.setTrackedEntityInstanceUid(entityInstance.getUid());
// endpoint is used for bulk import and sync purposes as well
if (enrollment.getStatus() != EnrollmentStatus.CANCELLED) {
List<Enrollment> enrollments = getEnrollments(programInstanceService.getProgramInstances(params));
Set<Enrollment> activeEnrollments = enrollments.stream().filter(e -> e.getStatus() == EnrollmentStatus.ACTIVE).collect(Collectors.toSet());
// needed
if (!activeEnrollments.isEmpty() && enrollment.getStatus() == EnrollmentStatus.ACTIVE) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setDescription("TrackedEntityInstance " + entityInstance.getUid() + " already has an active enrollment in program " + program.getUid());
importSummary.incrementIgnored();
return importSummary;
}
// imported enrollment has a state other than CANCELLED
if (program.getOnlyEnrollOnce()) {
Set<Enrollment> activeOrCompletedEnrollments = enrollments.stream().filter(e -> e.getStatus() == EnrollmentStatus.ACTIVE || e.getStatus() == EnrollmentStatus.COMPLETED).collect(Collectors.toSet());
if (!activeOrCompletedEnrollments.isEmpty()) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setDescription("TrackedEntityInstance " + entityInstance.getUid() + " already has an active or completed enrollment in program " + program.getUid() + ", and this program only allows enrolling one time");
importSummary.incrementIgnored();
return importSummary;
}
}
}
checkAttributes(entityInstance, enrollment, importOptions, importSummary);
if (importSummary.hasConflicts()) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.incrementIgnored();
}
return importSummary;
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method linkEnrollmentSummaries.
// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
private void linkEnrollmentSummaries(ImportSummaries importSummaries, ImportSummaries enrollmentImportSummaries, List<Enrollment> enrollments) {
importSummaries.getImportSummaries().forEach(is -> is.setEnrollments(new ImportSummaries()));
Map<String, List<Enrollment>> enrollmentsGroupedByTe = enrollments.stream().filter(en -> !StringUtils.isEmpty(en.getTrackedEntityInstance())).collect(Collectors.groupingBy(Enrollment::getTrackedEntityInstance));
Map<String, List<ImportSummary>> summariesGroupedByReference = importSummaries.getImportSummaries().stream().filter(en -> !StringUtils.isEmpty(en.getReference())).collect(Collectors.groupingBy(ImportSummary::getReference));
Map<String, List<ImportSummary>> enrollmentSummariesGroupedByReference = enrollmentImportSummaries.getImportSummaries().stream().filter(en -> !StringUtils.isEmpty(en.getReference())).collect(Collectors.groupingBy(ImportSummary::getReference));
for (Map.Entry<String, List<Enrollment>> set : enrollmentsGroupedByTe.entrySet()) {
if (!summariesGroupedByReference.containsKey(set.getKey())) {
continue;
}
ImportSummary importSummary = summariesGroupedByReference.get(set.getKey()).get(0);
ImportSummaries enrollmentSummaries = new ImportSummaries();
for (Enrollment enrollment : set.getValue()) {
if (!enrollmentSummariesGroupedByReference.containsKey(enrollment.getEnrollment())) {
continue;
}
ImportSummary enrollmentSummary = enrollmentSummariesGroupedByReference.get(enrollment.getEnrollment()).get(0);
enrollmentSummaries.addImportSummary(enrollmentSummary);
}
if (enrollmentImportSummaries.getImportSummaries().isEmpty()) {
continue;
}
importSummary.setEnrollments(enrollmentSummaries);
}
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project dhis2-core by dhis2.
the class AbstractEnrollmentService method linkEventSummaries.
// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
private void linkEventSummaries(ImportSummaries importSummaries, ImportSummaries eventImportSummaries, List<Event> events) {
importSummaries.getImportSummaries().forEach(is -> is.setEvents(new ImportSummaries()));
Map<String, List<Event>> eventsGroupedByEnrollment = events.stream().filter(ev -> !StringUtils.isEmpty(ev.getEnrollment())).collect(Collectors.groupingBy(Event::getEnrollment));
Map<String, List<ImportSummary>> summariesGroupedByReference = importSummaries.getImportSummaries().stream().filter(ev -> !StringUtils.isEmpty(ev.getReference())).collect(Collectors.groupingBy(ImportSummary::getReference));
Map<String, List<ImportSummary>> eventSummariesGroupedByReference = eventImportSummaries.getImportSummaries().stream().filter(ev -> !StringUtils.isEmpty(ev.getReference())).collect(Collectors.groupingBy(ImportSummary::getReference));
for (Map.Entry<String, List<Event>> set : eventsGroupedByEnrollment.entrySet()) {
if (!summariesGroupedByReference.containsKey(set.getKey())) {
continue;
}
ImportSummary importSummary = summariesGroupedByReference.get(set.getKey()).get(0);
ImportSummaries eventSummaries = new ImportSummaries();
for (Event event : set.getValue()) {
if (!eventSummariesGroupedByReference.containsKey(event.getEvent())) {
continue;
}
ImportSummary enrollmentSummary = eventSummariesGroupedByReference.get(event.getEvent()).get(0);
eventSummaries.addImportSummary(enrollmentSummary);
}
if (eventImportSummaries.getImportSummaries().isEmpty()) {
continue;
}
importSummary.setEvents(eventSummaries);
}
}
Aggregations