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;
}
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);
}
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));
}
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));
}
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));
}
Aggregations