Search in sources :

Example 26 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class AddChildAction method execute.

@Override
public void execute() {
    ServerGeoObjectIF parent = new ServerGeoObjectService(new AllowAllGeoObjectPermissionService()).getGeoObject(this.getParentId(), this.getParentTypeCode());
    ServerGeoObjectIF child = new ServerGeoObjectService().getGeoObject(this.getChildId(), this.getChildTypeCode());
    ServerHierarchyType ht = ServerHierarchyType.get(this.getHierarchyTypeCode());
    ServiceFactory.getGeoObjectRelationshipPermissionService().enforceCanAddChild(ht.getOrganization().getCode(), parent.getType(), child.getType());
    parent.addChild(child, ht);
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) AllowAllGeoObjectPermissionService(net.geoprism.registry.permission.AllowAllGeoObjectPermissionService)

Example 27 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class CurationService method submitProblemResolution.

@Transaction
private void submitProblemResolution(String json) {
    JsonObject config = JsonParser.parseString(json).getAsJsonObject();
    ListCurationHistory hist = ListCurationHistory.get(config.get("historyId").getAsString());
    ListTypeVersion version = hist.getVersion();
    // this.checkPermissions(hist.getOrganization().getCode(),
    // hist.getServerGeoObjectType());
    // CurationProblem err =
    // CurationProblem.get(config.get("problemId").getAsString());
    String resolution = config.get("resolution").getAsString();
    if (resolution.equals(ErrorResolution.APPLY_GEO_OBJECT.name())) {
        String geoObjectCode = config.get("code").getAsString();
        String geoObjectTypeCode = config.get("typeCode").getAsString();
        String actions = config.get("actions").getAsJsonArray().toString();
        ServerGeoObjectService service = new ServerGeoObjectService();
        service.updateGeoObjectInTrans(geoObjectCode, geoObjectTypeCode, actions, version.getOid(), null);
    // err.appLock();
    // err.setResolution(resolution);
    // err.apply();
    } else {
        throw new UnsupportedOperationException("Invalid import resolution [" + resolution + "].");
    }
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 28 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class ChangeRequestTestDataGenerator method genChangeRequest.

@Transaction
private static void genChangeRequest(String genKey, Instant when, boolean includeRemove, boolean includeAdd) {
    ServerGeoObjectService service = new ServerGeoObjectService(new AllowAllGeoObjectPermissionService());
    GeoObject goNewChild = ServiceFactory.getAdapter().newGeoObjectInstance("Cambodia_District");
    goNewChild.setCode(genKey + "_CODE");
    goNewChild.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, genKey + "_LABEL");
    goNewChild.setWKTGeometry("MULTIPOLYGON (((10000 10000, 12300 40000, 16800 50000, 12354 60000, 13354 60000, 17800 50000, 13300 40000, 11000 10000, 10000 10000)))");
    ServerGeoObjectIF testAddChildParent = service.getGeoObjectByCode("855 01", "Cambodia_Province");
    ServerGeoObjectIF testAddChild = service.getGeoObjectByCode("855 0109", "Cambodia_District");
    List<AbstractActionDTO> actions = new ArrayList<AbstractActionDTO>();
    /*
     * Remove Child
     */
    if (includeRemove) {
        RemoveChildActionDTO removeChild = new RemoveChildActionDTO();
        removeChild.setChildCode(testAddChild.getUid());
        removeChild.setChildTypeCode(testAddChild.getType().getCode());
        removeChild.setParentCode(testAddChildParent.getUid());
        removeChild.setParentTypeCode(testAddChildParent.getType().getCode());
        removeChild.setHierarchyCode(LocatedIn.class.getSimpleName());
        removeChild.setCreateActionDate(Date.from(when.minus(9, ChronoUnit.HOURS)));
        removeChild.setContributorNotes("Removing the village from the district");
        actions.add(removeChild);
    }
    /*
     * Add Child
     */
    if (includeAdd) {
        AddChildActionDTO addChild = new AddChildActionDTO();
        addChild.setChildCode(testAddChild.getUid());
        addChild.setChildTypeCode(testAddChild.getType().getCode());
        addChild.setParentCode(testAddChildParent.getUid());
        addChild.setParentTypeCode(testAddChildParent.getType().getCode());
        addChild.setHierarchyCode(LocatedIn.class.getSimpleName());
        addChild.setCreateActionDate(Date.from(when.minus(10, ChronoUnit.HOURS)));
        addChild.setContributorNotes("Adding the village as a child of the district");
        actions.add(addChild);
    }
    /*
     * Create a new GeoObject
     */
    CreateGeoObjectActionDTO create = new CreateGeoObjectActionDTO();
    create.setGeoObject(goNewChild.toJSON());
    create.setCreateActionDate(Date.from(when.minus(8, ChronoUnit.HOURS)));
    create.setContributorNotes("Creating a new village");
    actions.add(create);
    /*
     * Update the previously created GeoObject
     */
    final String NEW_DISPLAY_LABEL = genKey + "_NEW_DISPLAY_LABEL";
    goNewChild.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, NEW_DISPLAY_LABEL);
    UpdateGeoObjectActionDTO update = new UpdateGeoObjectActionDTO();
    update.setGeoObject(goNewChild.toJSON());
    update.setCreateActionDate(Date.from(when.minus(7, ChronoUnit.HOURS)));
    update.setContributorNotes("Updating the village. Adding a better name and stuff");
    actions.add(update);
    // Serialize the actions
    String sActions = AbstractActionDTO.serializeActions(actions).toString();
    submitChangeRequest(sActions);
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) RemoveChildActionDTO(org.commongeoregistry.adapter.action.tree.RemoveChildActionDTO) UpdateGeoObjectActionDTO(org.commongeoregistry.adapter.action.geoobject.UpdateGeoObjectActionDTO) LocatedIn(com.runwaysdk.system.gis.geo.LocatedIn) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ArrayList(java.util.ArrayList) AbstractActionDTO(org.commongeoregistry.adapter.action.AbstractActionDTO) AddChildActionDTO(org.commongeoregistry.adapter.action.tree.AddChildActionDTO) CreateGeoObjectActionDTO(org.commongeoregistry.adapter.action.geoobject.CreateGeoObjectActionDTO) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) AllowAllGeoObjectPermissionService(net.geoprism.registry.permission.AllowAllGeoObjectPermissionService) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 29 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class ServerChildGraphNode method fromJSON.

public static ServerChildGraphNode fromJSON(JsonObject jo) {
    ServerGeoObjectIF goif = null;
    if (jo.has(TreeNode.JSON_GEO_OBJECT)) {
        GeoObject go = GeoObject.fromJSON(ServiceFactory.getAdapter(), jo.get(TreeNode.JSON_GEO_OBJECT).toString());
        ServerGeoObjectType type = ServerGeoObjectType.get(go.getType());
        ServerGeoObjectStrategyIF strategy = new ServerGeoObjectService().getStrategy(type);
        goif = strategy.constructFromGeoObject(go, false);
    }
    GraphType graphType = null;
    if (jo.has("graphType")) {
        String graphCode = jo.get("graphType").getAsString();
        String graphTypeClass = jo.get("graphTypeClass").getAsString();
        graphType = GraphType.getByCode(graphTypeClass, graphCode);
    }
    Date startDate = null;
    if (jo.has("startDate")) {
        startDate = GeoRegistryUtil.parseDate(jo.get("startDate").getAsString());
    }
    Date endDate = null;
    if (jo.has("endDate")) {
        endDate = GeoRegistryUtil.parseDate(jo.get("startDate").getAsString());
    }
    String oid = null;
    if (jo.has("oid")) {
        oid = jo.get("oid").getAsString();
    }
    ServerChildGraphNode node = new ServerChildGraphNode(goif, graphType, startDate, endDate, oid);
    if (jo.has(ChildTreeNode.JSON_CHILDREN)) {
        JsonArray jaChildren = jo.get(ChildTreeNode.JSON_CHILDREN).getAsJsonArray();
        for (int i = 0; i < jaChildren.size(); ++i) {
            node.addChild(ServerChildGraphNode.fromJSON(jaChildren.get(i).getAsJsonObject()));
        }
    }
    return node;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerGeoObjectStrategyIF(net.geoprism.registry.conversion.ServerGeoObjectStrategyIF) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Date(java.util.Date)

Example 30 with ServerGeoObjectService

use of net.geoprism.registry.geoobject.ServerGeoObjectService in project geoprism-registry by terraframe.

the class ServerHierarchyType method removeFromHierarchy.

@Transaction
private void removeFromHierarchy(ServerGeoObjectType parentType, ServerGeoObjectType childType, boolean migrateChildren) {
    ServerGeoObjectService service = new ServerGeoObjectService();
    List<? extends InheritedHierarchyAnnotation> annotations = InheritedHierarchyAnnotation.getByInheritedHierarchy(childType.getUniversal(), this.hierarchicalRelationship);
    if (annotations.size() > 0) {
        List<String> codes = new ArrayList<String>();
        for (InheritedHierarchyAnnotation annot : annotations) {
            String code = buildHierarchyKeyFromMdTermRelUniversal(annot.getForHierarchy().getKey());
            codes.add(code);
        }
        CantRemoveInheritedGOT ex = new CantRemoveInheritedGOT();
        ex.setGotCode(childType.getCode());
        ex.setHierCode(this.getCode());
        ex.setInheritedHierarchyList(StringUtils.join(codes, ", "));
        throw ex;
    }
    // hierarchy.
    if (parentType instanceof RootGeoObjectType) {
        List<ServerGeoObjectType> children = childType.getChildren(this);
        if (children.size() == 1) {
            ServerGeoObjectType nextRoot = children.get(0);
            List<? extends InheritedHierarchyAnnotation> results = InheritedHierarchyAnnotation.getByInheritedHierarchy(nextRoot.getUniversal(), this.hierarchicalRelationship);
            if (results.size() > 0) {
                throw new RootNodeCannotBeInheritedException("Cannot remove the root Geo-Object Type of a hierarchy if the new root Geo-Object Type is inherited by another hierarchy");
            }
        }
    }
    this.hierarchicalRelationship.removeFromHierarchy(parentType, childType, migrateChildren);
    service.removeAllEdges(this, childType);
    // MasterList.markAllAsInvalid(this, childType);
    ListType.markAllAsInvalid(this, childType);
    InheritedHierarchyAnnotation annotation = InheritedHierarchyAnnotation.get(childType.getUniversal(), this.hierarchicalRelationship);
    if (annotation != null) {
        annotation.delete();
    }
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) RootNodeCannotBeInheritedException(net.geoprism.registry.RootNodeCannotBeInheritedException) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) ArrayList(java.util.ArrayList) CantRemoveInheritedGOT(net.geoprism.registry.graph.CantRemoveInheritedGOT) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)33 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)23 Request (com.runwaysdk.session.Request)10 JsonObject (com.google.gson.JsonObject)8 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)7 AllowAllGeoObjectPermissionService (net.geoprism.registry.permission.AllowAllGeoObjectPermissionService)7 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)7 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)6 Date (java.util.Date)5 JsonArray (com.google.gson.JsonArray)4 Location (net.geoprism.registry.io.Location)4 GraphType (net.geoprism.registry.model.GraphType)4 ServerCodeRestriction (net.geoprism.registry.query.ServerCodeRestriction)4 ServerGeoObjectQuery (net.geoprism.registry.query.ServerGeoObjectQuery)4 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)4 ArrayList (java.util.ArrayList)3 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)3 ServerGraphNode (net.geoprism.registry.model.ServerGraphNode)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2