Search in sources :

Example 1 with Relationship

use of org.hisp.dhis.dxf2.events.trackedentity.Relationship in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method checkRelationships.

private List<ImportConflict> checkRelationships(TrackedEntityInstance trackedEntityInstance) {
    List<ImportConflict> importConflicts = new ArrayList<>();
    for (org.hisp.dhis.dxf2.events.trackedentity.Relationship relationship : trackedEntityInstance.getRelationships()) {
        RelationshipType relationshipType = manager.get(RelationshipType.class, relationship.getRelationship());
        if (relationshipType == null) {
            importConflicts.add(new ImportConflict("Relationship.type", "Invalid type " + relationship.getRelationship()));
        }
        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceA = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceA());
        if (entityInstanceA == null) {
            importConflicts.add(new ImportConflict("Relationship.trackedEntityInstance", "Invalid trackedEntityInstance " + relationship.getTrackedEntityInstanceA()));
        }
        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceB = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceB());
        if (entityInstanceB == null) {
            importConflicts.add(new ImportConflict("Relationship.trackedEntityInstance", "Invalid trackedEntityInstance " + relationship.getTrackedEntityInstanceB()));
        }
    }
    return importConflicts;
}
Also used : ArrayList(java.util.ArrayList) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 2 with Relationship

use of org.hisp.dhis.dxf2.events.trackedentity.Relationship in project dhis2-core by dhis2.

the class RelationshipRowCallbackHandler method processRow.

@Override
public void processRow(ResultSet rs) throws SQLException {
    final Relationship relationship = getRelationship(rs);
    this.items.put(extractUid(relationship.getFrom()), relationship);
    this.items.put(extractUid(relationship.getTo()), relationship);
}
Also used : Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship)

Example 3 with Relationship

use of org.hisp.dhis.dxf2.events.trackedentity.Relationship in project dhis2-core by dhis2.

the class JacksonRelationshipService method updateRelationshipXml.

@Override
public ImportSummary updateRelationshipXml(String id, InputStream inputStream, ImportOptions importOptions) throws IOException {
    Relationship relationship = fromXml(inputStream, Relationship.class);
    relationship.setRelationship(id);
    return updateRelationship(relationship, updateImportOptions(importOptions));
}
Also used : Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship)

Example 4 with Relationship

use of org.hisp.dhis.dxf2.events.trackedentity.Relationship in project dhis2-core by dhis2.

the class JacksonRelationshipService method addRelationshipsXml.

@Override
public ImportSummaries addRelationshipsXml(InputStream inputStream, ImportOptions importOptions) throws IOException {
    String input = StreamUtils.copyToString(inputStream, Charset.forName("UTF-8"));
    List<Relationship> relationships = new ArrayList<>();
    try {
        Relationships fromXml = fromXml(input, Relationships.class);
        relationships.addAll(fromXml.getRelationships());
    } catch (JsonMappingException ex) {
        Relationship fromXml = fromXml(input, Relationship.class);
        relationships.add(fromXml);
    }
    return processRelationshipList(relationships, updateImportOptions(importOptions));
}
Also used : Relationships(org.hisp.dhis.dxf2.events.trackedentity.Relationships) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ArrayList(java.util.ArrayList)

Example 5 with Relationship

use of org.hisp.dhis.dxf2.events.trackedentity.Relationship in project dhis2-core by dhis2.

the class JacksonRelationshipService method addRelationshipsJson.

@Override
public ImportSummaries addRelationshipsJson(InputStream inputStream, ImportOptions importOptions) throws IOException {
    String input = StreamUtils.copyToString(inputStream, Charset.forName("UTF-8"));
    List<Relationship> relationships = new ArrayList<>();
    JsonNode root = jsonMapper.readTree(input);
    if (root.get("relationships") != null) {
        Relationships fromJson = fromJson(input, Relationships.class);
        relationships.addAll(fromJson.getRelationships());
    } else {
        Relationship fromJson = fromJson(input, Relationship.class);
        relationships.add(fromJson);
    }
    return processRelationshipList(relationships, updateImportOptions(importOptions));
}
Also used : Relationships(org.hisp.dhis.dxf2.events.trackedentity.Relationships) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

Relationship (org.hisp.dhis.dxf2.events.trackedentity.Relationship)30 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)14 ArrayList (java.util.ArrayList)11 Transactional (org.springframework.transaction.annotation.Transactional)10 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)9 Test (org.junit.jupiter.api.Test)9 List (java.util.List)8 RelationshipType (org.hisp.dhis.relationship.RelationshipType)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)6 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)6 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)6 Optional (java.util.Optional)5 Set (java.util.Set)5 Event (org.hisp.dhis.dxf2.events.event.Event)5 Lists (com.google.common.collect.Lists)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 CurrentUserService (org.hisp.dhis.user.CurrentUserService)4