Search in sources :

Example 16 with StringUtils.isEmpty

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());
    }
}
Also used : RemoteSequence(org.jbei.ice.lib.net.RemoteSequence) AttachmentInfo(org.jbei.ice.lib.dto.entry.AttachmentInfo) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) ConfigurationSettings(org.jbei.ice.lib.config.ConfigurationSettings) Sequences(org.jbei.ice.lib.entry.sequence.Sequences) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) Setting(org.jbei.ice.lib.dto.Setting) TraceSequences(org.jbei.ice.lib.entry.sequence.analysis.TraceSequences) ConfigurationKey(org.jbei.ice.lib.dto.ConfigurationKey) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Entries(org.jbei.ice.lib.entry.Entries) MediaType(javax.ws.rs.core.MediaType) DAOFactory(org.jbei.ice.storage.DAOFactory) Logger(org.jbei.ice.lib.common.logging.Logger) ByteArrayInputStream(java.io.ByteArrayInputStream) FileBulkUpload(org.jbei.ice.lib.bulkupload.FileBulkUpload) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) SequenceFormat(org.jbei.ice.lib.entry.sequence.SequenceFormat) EntryType(org.jbei.ice.lib.dto.entry.EntryType) Utils(org.jbei.ice.lib.utils.Utils) EntrySelection(org.jbei.ice.lib.entry.EntrySelection) Files(java.nio.file.Files) FileUtils(org.apache.commons.io.FileUtils) StreamingOutput(javax.ws.rs.core.StreamingOutput) IOException(java.io.IOException) InputStreamWrapper(org.jbei.ice.lib.entry.sequence.InputStreamWrapper) Collectors(java.util.stream.Collectors) EntryFieldLabel(org.jbei.ice.lib.dto.entry.EntryFieldLabel) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) Attachments(org.jbei.ice.lib.entry.attachment.Attachments) RemoteEntries(org.jbei.ice.lib.net.RemoteEntries) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ShotgunSequenceDAO(org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO) TraceSequence(org.jbei.ice.storage.model.TraceSequence) EntriesAsCSV(org.jbei.ice.lib.entry.EntriesAsCSV) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) ShotgunSequence(org.jbei.ice.storage.model.ShotgunSequence) InputStream(java.io.InputStream) InputStreamWrapper(org.jbei.ice.lib.entry.sequence.InputStreamWrapper) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) StreamingOutput(javax.ws.rs.core.StreamingOutput) RemoteSequence(org.jbei.ice.lib.net.RemoteSequence)

Example 17 with StringUtils.isEmpty

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();
}
Also used : Context(org.apache.jena.sparql.util.Context) java.util(java.util) RDF(org.apache.jena.vocabulary.RDF) Auth(org.apache.jena.fuseki.auth.Auth) AuthPolicy(org.apache.jena.fuseki.auth.AuthPolicy) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) FmtUtils(org.apache.jena.sparql.util.FmtUtils) StringUtils(org.apache.commons.lang3.StringUtils) StrUtils(org.apache.jena.atlas.lib.StrUtils) RDFParserRegistry.isRegistered(org.apache.jena.riot.RDFParserRegistry.isRegistered) JA(org.apache.jena.assembler.JA) DirectoryStream(java.nio.file.DirectoryStream) QuerySolution(org.apache.jena.query.QuerySolution) GraphUtils(org.apache.jena.sparql.util.graph.GraphUtils) Fuseki(org.apache.jena.fuseki.Fuseki) FusekiException(org.apache.jena.fuseki.FusekiException) Method(java.lang.reflect.Method) Path(java.nio.file.Path) Dataset(org.apache.jena.query.Dataset) BuildLib.nodeLabel(org.apache.jena.fuseki.build.BuildLib.nodeLabel) FusekiVocab(org.apache.jena.fuseki.server.FusekiVocab) Lang(org.apache.jena.riot.Lang) Logger(org.slf4j.Logger) Assembler(org.apache.jena.assembler.Assembler) Files(java.nio.file.Files) ActionService(org.apache.jena.fuseki.servlets.ActionService) BuildLib.getZeroOrOne(org.apache.jena.fuseki.build.BuildLib.getZeroOrOne) IOException(java.io.IOException) org.apache.jena.fuseki.server(org.apache.jena.fuseki.server) String.format(java.lang.String.format) RDFLanguages.filenameToLang(org.apache.jena.riot.RDFLanguages.filenameToLang) File(java.io.File) org.apache.jena.rdf.model(org.apache.jena.rdf.model) IRILib(org.apache.jena.atlas.lib.IRILib) FusekiConfigException(org.apache.jena.fuseki.FusekiConfigException) Collectors.toList(java.util.stream.Collectors.toList) Util(org.apache.jena.rdf.model.impl.Util) Node(org.apache.jena.graph.Node) XSDDatatype(org.apache.jena.datatypes.xsd.XSDDatatype) ReadWrite(org.apache.jena.query.ReadWrite) Pair(org.apache.jena.atlas.lib.Pair) AssemblerUtils(org.apache.jena.sparql.core.assembler.AssemblerUtils) JenaException(org.apache.jena.shared.JenaException) AuthPolicyList(org.apache.jena.fuseki.auth.AuthPolicyList) ResultSet(org.apache.jena.query.ResultSet) AuthPolicy(org.apache.jena.fuseki.auth.AuthPolicy)

Example 18 with StringUtils.isEmpty

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;
}
Also used : Authorities(org.hisp.dhis.security.Authorities) FIRST_PAGE(org.hisp.dhis.common.SlimPager.FIRST_PAGE) EventService(org.hisp.dhis.dxf2.events.event.EventService) Date(java.util.Date) Restrictions(org.hisp.dhis.query.Restrictions) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) StringUtils(org.apache.commons.lang3.StringUtils) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) ProgramStageInstanceService(org.hisp.dhis.program.ProgramStageInstanceService) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EnrollmentEvaluationEvent(org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent) Map(java.util.Map) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) NoteHelper(org.hisp.dhis.dxf2.events.NoteHelper) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) SetValuedMap(org.apache.commons.collections4.SetValuedMap) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) Query(org.hisp.dhis.query.Query) UserService(org.hisp.dhis.user.UserService) Transactional(javax.transaction.Transactional) OrganisationUnitSelectionMode(org.hisp.dhis.common.OrganisationUnitSelectionMode) Collection(java.util.Collection) Set(java.util.Set) SchemaService(org.hisp.dhis.schema.SchemaService) Collectors(java.util.stream.Collectors) Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) QueryService(org.hisp.dhis.query.QueryService) Event(org.hisp.dhis.dxf2.events.event.Event) Objects(java.util.Objects) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) TEA_VALUE_MAX_LENGTH(org.hisp.dhis.trackedentity.TrackedEntityAttributeService.TEA_VALUE_MAX_LENGTH) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) TrackerEnrollmentWebHookEvent(org.hisp.dhis.programrule.engine.TrackerEnrollmentWebHookEvent) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) TrackedEntityCommentService(org.hisp.dhis.trackedentitycomment.TrackedEntityCommentService) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramEnrollmentNotificationEvent(org.hisp.dhis.program.notification.event.ProgramEnrollmentNotificationEvent) Constants(org.hisp.dhis.dxf2.Constants) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) GeoUtils(org.hisp.dhis.system.util.GeoUtils) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Notifier(org.hisp.dhis.system.notification.Notifier) RelationshipParams(org.hisp.dhis.dxf2.events.RelationshipParams) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) SlimPager(org.hisp.dhis.common.SlimPager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) ImportConflicts(org.hisp.dhis.dxf2.importsummary.ImportConflicts) User(org.hisp.dhis.user.User) IdentifiableObjectCallable(org.hisp.dhis.system.callable.IdentifiableObjectCallable) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) I18nManager(org.hisp.dhis.i18n.I18nManager) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) IdSchemes(org.hisp.dhis.common.IdSchemes) Pager(org.hisp.dhis.common.Pager) RelationshipService(org.hisp.dhis.dxf2.events.relationship.RelationshipService) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DEFAULT_PAGE_SIZE(org.hisp.dhis.common.Pager.DEFAULT_PAGE_SIZE) InvalidIdentifierReferenceException(org.hisp.dhis.common.exception.InvalidIdentifierReferenceException) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Maps(com.google.common.collect.Maps) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) DebugUtils(org.hisp.dhis.commons.util.DebugUtils) Note(org.hisp.dhis.dxf2.events.event.Note) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ProgramStatus(org.hisp.dhis.program.ProgramStatus) Collectors.toList(java.util.stream.Collectors.toList) CollectionUtils(org.hisp.dhis.commons.collection.CollectionUtils) FeatureType(org.hisp.dhis.organisationunit.FeatureType) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CachingMap(org.hisp.dhis.commons.collection.CachingMap) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ERROR(org.hisp.dhis.system.notification.NotificationLevel.ERROR) CodeGenerator(org.hisp.dhis.common.CodeGenerator) ProgramService(org.hisp.dhis.program.ProgramService) Collections(java.util.Collections) DateUtils(org.hisp.dhis.util.DateUtils) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams)

Example 19 with StringUtils.isEmpty

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);
    }
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Authorities(org.hisp.dhis.security.Authorities) Date(java.util.Date) Restrictions(org.hisp.dhis.query.Restrictions) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) TrackedEntityInstanceAuditService(org.hisp.dhis.trackedentity.TrackedEntityInstanceAuditService) ReservedValueService(org.hisp.dhis.reservedvalue.ReservedValueService) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) StringUtils(org.apache.commons.lang3.StringUtils) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) RelationshipService(org.hisp.dhis.relationship.RelationshipService) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Map(java.util.Map) ProgramInstance(org.hisp.dhis.program.ProgramInstance) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) TrackedEntityAttributeStore(org.hisp.dhis.trackedentity.TrackedEntityAttributeStore) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) Query(org.hisp.dhis.query.Query) UserService(org.hisp.dhis.user.UserService) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Collection(java.util.Collection) Set(java.util.Set) SchemaService(org.hisp.dhis.schema.SchemaService) Collectors(java.util.stream.Collectors) QueryService(org.hisp.dhis.query.QueryService) TrackedEntityProgramOwner(org.hisp.dhis.trackedentity.TrackedEntityProgramOwner) ImportReportMode(org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode) Objects(java.util.Objects) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) TEA_VALUE_MAX_LENGTH(org.hisp.dhis.trackedentity.TrackedEntityAttributeService.TEA_VALUE_MAX_LENGTH) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) Optional(java.util.Optional) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Geometry(org.locationtech.jts.geom.Geometry) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityInstanceAggregate(org.hisp.dhis.dxf2.events.aggregates.TrackedEntityInstanceAggregate) TrackedEntityTypeService(org.hisp.dhis.trackedentity.TrackedEntityTypeService) Constants(org.hisp.dhis.dxf2.Constants) AuditType(org.hisp.dhis.common.AuditType) GeoUtils(org.hisp.dhis.system.util.GeoUtils) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Notifier(org.hisp.dhis.system.notification.Notifier) RelationshipParams(org.hisp.dhis.dxf2.events.RelationshipParams) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) ImportConflicts(org.hisp.dhis.dxf2.importsummary.ImportConflicts) User(org.hisp.dhis.user.User) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) TrackedEntityInstanceAudit(org.hisp.dhis.audit.payloads.TrackedEntityInstanceAudit) IdSchemes(org.hisp.dhis.common.IdSchemes) FileResource(org.hisp.dhis.fileresource.FileResource) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) DebugUtils(org.hisp.dhis.commons.util.DebugUtils) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) FeatureType(org.hisp.dhis.organisationunit.FeatureType) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CachingMap(org.hisp.dhis.commons.collection.CachingMap) ERROR(org.hisp.dhis.system.notification.NotificationLevel.ERROR) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Collections(java.util.Collections) DateUtils(org.hisp.dhis.util.DateUtils) Transactional(org.springframework.transaction.annotation.Transactional) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) CachingMap(org.hisp.dhis.commons.collection.CachingMap)

Example 20 with StringUtils.isEmpty

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);
    }
}
Also used : Authorities(org.hisp.dhis.security.Authorities) FIRST_PAGE(org.hisp.dhis.common.SlimPager.FIRST_PAGE) EventService(org.hisp.dhis.dxf2.events.event.EventService) Date(java.util.Date) Restrictions(org.hisp.dhis.query.Restrictions) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) StringUtils(org.apache.commons.lang3.StringUtils) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) ProgramStageInstanceService(org.hisp.dhis.program.ProgramStageInstanceService) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EnrollmentEvaluationEvent(org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent) Map(java.util.Map) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) NoteHelper(org.hisp.dhis.dxf2.events.NoteHelper) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) SetValuedMap(org.apache.commons.collections4.SetValuedMap) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) Query(org.hisp.dhis.query.Query) UserService(org.hisp.dhis.user.UserService) Transactional(javax.transaction.Transactional) OrganisationUnitSelectionMode(org.hisp.dhis.common.OrganisationUnitSelectionMode) Collection(java.util.Collection) Set(java.util.Set) SchemaService(org.hisp.dhis.schema.SchemaService) Collectors(java.util.stream.Collectors) Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) QueryService(org.hisp.dhis.query.QueryService) Event(org.hisp.dhis.dxf2.events.event.Event) Objects(java.util.Objects) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) TEA_VALUE_MAX_LENGTH(org.hisp.dhis.trackedentity.TrackedEntityAttributeService.TEA_VALUE_MAX_LENGTH) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) TrackerEnrollmentWebHookEvent(org.hisp.dhis.programrule.engine.TrackerEnrollmentWebHookEvent) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) TrackedEntityCommentService(org.hisp.dhis.trackedentitycomment.TrackedEntityCommentService) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramEnrollmentNotificationEvent(org.hisp.dhis.program.notification.event.ProgramEnrollmentNotificationEvent) Constants(org.hisp.dhis.dxf2.Constants) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) GeoUtils(org.hisp.dhis.system.util.GeoUtils) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Notifier(org.hisp.dhis.system.notification.Notifier) RelationshipParams(org.hisp.dhis.dxf2.events.RelationshipParams) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) SlimPager(org.hisp.dhis.common.SlimPager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) ImportConflicts(org.hisp.dhis.dxf2.importsummary.ImportConflicts) User(org.hisp.dhis.user.User) IdentifiableObjectCallable(org.hisp.dhis.system.callable.IdentifiableObjectCallable) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) I18nManager(org.hisp.dhis.i18n.I18nManager) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) IdSchemes(org.hisp.dhis.common.IdSchemes) Pager(org.hisp.dhis.common.Pager) RelationshipService(org.hisp.dhis.dxf2.events.relationship.RelationshipService) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DEFAULT_PAGE_SIZE(org.hisp.dhis.common.Pager.DEFAULT_PAGE_SIZE) InvalidIdentifierReferenceException(org.hisp.dhis.common.exception.InvalidIdentifierReferenceException) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Maps(com.google.common.collect.Maps) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) DebugUtils(org.hisp.dhis.commons.util.DebugUtils) Note(org.hisp.dhis.dxf2.events.event.Note) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ProgramStatus(org.hisp.dhis.program.ProgramStatus) Collectors.toList(java.util.stream.Collectors.toList) CollectionUtils(org.hisp.dhis.commons.collection.CollectionUtils) FeatureType(org.hisp.dhis.organisationunit.FeatureType) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CachingMap(org.hisp.dhis.commons.collection.CachingMap) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ERROR(org.hisp.dhis.system.notification.NotificationLevel.ERROR) CodeGenerator(org.hisp.dhis.common.CodeGenerator) ProgramService(org.hisp.dhis.program.ProgramService) Collections(java.util.Collections) DateUtils(org.hisp.dhis.util.DateUtils) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EnrollmentEvaluationEvent(org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent) Event(org.hisp.dhis.dxf2.events.event.Event) TrackerEnrollmentWebHookEvent(org.hisp.dhis.programrule.engine.TrackerEnrollmentWebHookEvent) ProgramEnrollmentNotificationEvent(org.hisp.dhis.program.notification.event.ProgramEnrollmentNotificationEvent) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) SetValuedMap(org.apache.commons.collections4.SetValuedMap) CachingMap(org.hisp.dhis.commons.collection.CachingMap)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)76 List (java.util.List)53 Collectors (java.util.stream.Collectors)40 ArrayList (java.util.ArrayList)39 Map (java.util.Map)39 HashMap (java.util.HashMap)28 IOException (java.io.IOException)26 Collections (java.util.Collections)25 Set (java.util.Set)25 Logger (org.slf4j.Logger)25 Arrays (java.util.Arrays)24 LoggerFactory (org.slf4j.LoggerFactory)24 Optional (java.util.Optional)22 HashSet (java.util.HashSet)18 Collection (java.util.Collection)14 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Objects (java.util.Objects)12 UUID (java.util.UUID)11 java.util (java.util)10 Component (org.springframework.stereotype.Component)10