Search in sources :

Example 26 with GeoObjectType

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();
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 27 with GeoObjectType

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;
}
Also used : DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) JsonObject(com.google.gson.JsonObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) JsonArray(com.google.gson.JsonArray) OrganisationUnitGroup(net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) UnexpectedResponseException(net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException) HttpError(net.geoprism.registry.etl.export.HttpError) Request(com.runwaysdk.session.Request)

Example 28 with GeoObjectType

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;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) Entry(java.util.Map.Entry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 29 with GeoObjectType

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;
}
Also used : ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) RootGeoObjectType(net.geoprism.registry.model.RootGeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ServerElement(net.geoprism.registry.model.ServerElement) Element(org.w3c.dom.Element) ServerElement(net.geoprism.registry.model.ServerElement) LinkedList(java.util.LinkedList)

Example 30 with GeoObjectType

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);
    }
}
Also used : HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType)

Aggregations

GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)33 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)23 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)13 JsonArray (com.google.gson.JsonArray)10 JsonObject (com.google.gson.JsonObject)10 Request (com.runwaysdk.session.Request)10 LinkedList (java.util.LinkedList)7 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)6 Test (org.junit.Test)6 ServerGeoObjectTypeConverter (net.geoprism.registry.conversion.ServerGeoObjectTypeConverter)4 HierarchyNode (org.commongeoregistry.adapter.metadata.HierarchyNode)4 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)4 Endpoint (com.runwaysdk.mvc.Endpoint)3 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)3 List (java.util.List)3 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)3 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)2 Universal (com.runwaysdk.system.gis.geo.Universal)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2