use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class RegistryService method updateGeoObjectType.
/**
* Updates the given {@link GeoObjectType} represented as JSON.
*
* @pre given {@link GeoObjectType} must already exist.
*
* @param sessionId
* @param gtJSON
* JSON of the {@link GeoObjectType} to be updated.
* @return updated {@link GeoObjectType}
*/
@Request(RequestType.SESSION)
public GeoObjectType updateGeoObjectType(String sessionId, String gtJSON) {
GeoObjectType geoObjectType = GeoObjectType.fromJSON(gtJSON, adapter);
ServerGeoObjectType serverGeoObjectType = ServerGeoObjectType.get(geoObjectType.getCode());
ServiceFactory.getGeoObjectTypePermissionService().enforceCanWrite(geoObjectType.getOrganizationCode(), serverGeoObjectType, geoObjectType.getIsPrivate());
serverGeoObjectType.update(geoObjectType);
NotificationFacade.queue(new GlobalNotificationMessage(MessageType.TYPE_CACHE_CHANGE, null));
return serverGeoObjectType.getType();
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class SynchronizationConfigService method getConfigForExternalSystem.
@Request(RequestType.SESSION)
public JsonObject getConfigForExternalSystem(String sessionId, String externalSystemId, String hierarchyTypeCode) {
JsonObject ret = new JsonObject();
// Add GeoObjectTypes
GeoObjectType[] gots = ServiceFactory.getRegistryService().getGeoObjectTypes(sessionId, null, new String[] { hierarchyTypeCode }, PermissionContext.WRITE);
CustomSerializer serializer = ServiceFactory.getRegistryService().serializer(sessionId);
JsonArray jarray = new JsonArray();
for (int i = 0; i < gots.length; ++i) {
jarray.add(gots[i].toJSON(serializer));
}
ret.add("types", jarray);
// Add DHIS2 OrgUnitGroups
DHIS2ExternalSystem system = DHIS2ExternalSystem.get(externalSystemId);
try {
DHIS2TransportServiceIF dhis2 = DHIS2ServiceFactory.buildDhis2TransportService(system);
JsonArray jaGroups = new JsonArray();
MetadataGetResponse<OrganisationUnitGroup> resp = dhis2.<OrganisationUnitGroup>metadataGet(OrganisationUnitGroup.class);
List<OrganisationUnitGroup> groups = resp.getObjects();
for (OrganisationUnitGroup group : groups) {
JsonObject joGroup = new JsonObject();
joGroup.addProperty("id", group.getId());
joGroup.addProperty("name", group.getName());
jaGroups.add(joGroup);
}
ret.add("orgUnitGroups", jaGroups);
} catch (InvalidLoginException e) {
LoginException cgrlogin = new LoginException(e);
throw cgrlogin;
} catch (HTTPException | UnexpectedResponseException | IllegalArgumentException | BadServerUriException e) {
HttpError cgrhttp = new HttpError(e);
throw cgrhttp;
}
return ret;
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class ServerParentTreeNodeOverTime method toJSON.
public JsonArray toJSON() {
SimpleDateFormat format = getDateFormat();
final JsonArray response = new JsonArray();
final Set<Entry<String, Hierarchy>> entrySet = this.hierarchies.entrySet();
for (Entry<String, Hierarchy> entry : entrySet) {
final Hierarchy hierarchy = entry.getValue();
final ServerHierarchyType ht = hierarchy.getType();
List<GeoObjectType> parentTypes = this.type.getTypeAncestors(ht, false);
// Populate a "types" array with all ancestors of the GOT they passed us
JsonArray types = new JsonArray();
for (GeoObjectType parent : parentTypes) {
ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
if (!pType.getCode().equals(this.type.getCode())) {
JsonObject pObject = new JsonObject();
pObject.addProperty(JSON_TYPE_CODE, pType.getCode());
pObject.addProperty(JSON_TYPE_LABEL, pType.getLabel().getValue());
types.add(pObject);
}
}
// Populate an "entries" array with all the parents per time period
final JsonArray entries = new JsonArray();
final List<ServerParentTreeNode> nodes = hierarchy.getNodes();
for (ServerParentTreeNode node : nodes) {
JsonObject pArray = new JsonObject();
for (GeoObjectType parent : parentTypes) {
ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
if (!pType.getCode().equals(this.type.getCode())) {
final List<ServerParentTreeNode> ptns = node.findParentOfType(pType.getCode());
if (ptns.size() > 0) {
ServerParentTreeNode sptn = ptns.get(0);
final VertexServerGeoObject sGeoObject = (VertexServerGeoObject) sptn.getGeoObject();
final GeoObject geoObject = sGeoObject.toGeoObject(node.getStartDate());
geoObject.setGeometry(null);
JsonObject pObject = new JsonObject();
pObject.add(JSON_ENTRY_PARENT_GEOOBJECT, geoObject.toJSON());
LocalizedValue label = sGeoObject.getDisplayLabel();
if (label != null) {
pObject.addProperty(JSON_ENTRY_PARENT_TEXT, label.getValue() + " : " + sGeoObject.getCode());
} else {
pObject.addProperty(JSON_ENTRY_PARENT_TEXT, "null" + " : " + sGeoObject.getCode());
}
pArray.add(pType.getCode(), pObject);
}
}
}
JsonObject object = new JsonObject();
object.addProperty(JSON_ENTRY_STARTDATE, format.format(node.getStartDate()));
if (node.getEndDate() != null) {
object.addProperty(JSON_ENTRY_ENDDATE, format.format(node.getEndDate()));
}
object.add(JSON_ENTRY_PARENTS, pArray);
object.addProperty("oid", node.getOid());
entries.add(object);
}
JsonObject object = new JsonObject();
object.addProperty(JSON_HIERARCHY_CODE, ht.getCode());
object.addProperty(JSON_HIERARCHY_LABEL, ht.getDisplayLabel().getValue());
object.add(JSON_HIERARCHY_TYPES, types);
object.add(JSON_HIERARCHY_ENTRIES, entries);
response.add(object);
}
return response;
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class XMLImporter method addGroupItems.
private List<ServerElement> addGroupItems(Element root, ServerGeoObjectType superType) {
List<ServerElement> list = new LinkedList<ServerElement>();
NodeList nList = root.getElementsByTagName("group-item");
for (int i = 0; i < nList.getLength(); i++) {
Node nNode = nList.item(i);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element) nNode;
String code = elem.getAttribute("code");
LocalizedValue label = this.getLabel(elem);
LocalizedValue description = this.getDescription(elem);
GeoObjectType type = new GeoObjectType(code, superType.getGeometryType(), label, description, superType.isGeometryEditable(), superType.getOrganization().getCode(), adapter);
type.setSuperTypeCode(superType.getCode());
type.setIsPrivate(superType.getIsPrivate());
ServerGeoObjectType result = new ServerGeoObjectTypeConverter().create(type);
list.add(result);
this.cache.put(code, result);
}
}
return list;
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class TestRegistryAdapterClient method refreshMetadataCache.
/**
* Clears the metadata cache and populates it with the metadata from the
* common geo-registry.
*/
public void refreshMetadataCache() {
refreshRequestMetadataCache();
this.getMetadataCache().rebuild();
GeoObjectType[] gots = this.getGeoObjectTypes(new String[] {}, new String[] {}, PermissionContext.READ);
for (GeoObjectType got : gots) {
this.getMetadataCache().addGeoObjectType(got);
}
HierarchyType[] hts = this.getHierarchyTypes(new String[] {});
for (HierarchyType ht : hts) {
this.getMetadataCache().addHierarchyType(ht);
}
}
Aggregations