Search in sources :

Example 1 with GeoObject

use of org.commongeoregistry.adapter.dataaccess.GeoObject in project geoprism-registry by terraframe.

the class GeoObjectEditorControllerNoOverTime method applyInTransaction.

@Transaction
private GeoObject applyInTransaction(String sessionId, String sPtn, String sGo, Boolean isNew, String masterListId) {
    final Date startDate = new Date();
    final Date endDate = ValueOverTime.INFINITY_END_DATE;
    GeoObject go;
    Map<String, String> roles = Session.getCurrentSession().getUserRoles();
    if (roles.keySet().contains(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE)) {
        Instant base = Instant.now();
        int sequence = 0;
        ChangeRequest request = new ChangeRequest();
        request.addApprovalStatus(AllGovernanceStatus.PENDING);
        request.apply();
        if (!isNew) {
            UpdateGeoObjectAction action = new UpdateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setGeoObjectJson(sGo);
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        } else {
            CreateGeoObjectAction action = new CreateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setGeoObjectJson(sGo);
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        }
        ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
        applyChangeRequest(sessionId, request, ptn, isNew, base, sequence, startDate, endDate);
    } else {
        if (!isNew) {
            go = RegistryService.getInstance().updateGeoObject(sessionId, sGo.toString(), startDate, endDate);
        } else {
            go = RegistryService.getInstance().createGeoObject(sessionId, sGo.toString(), startDate, endDate);
        }
        ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
        applyPtn(sessionId, ptn, startDate, endDate);
        // Update the master list record
        if (masterListId != null) {
            ServerGeoObjectService service = new ServerGeoObjectService();
            ServerGeoObjectIF geoObject = service.getGeoObject(go);
            if (!isNew) {
                ListTypeVersion.get(masterListId).updateRecord(geoObject);
            } else {
                ListTypeVersion.get(masterListId).publishRecord(geoObject);
            }
        }
        return go;
    }
    return null;
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) UpdateGeoObjectAction(net.geoprism.registry.action.geoobject.UpdateGeoObjectAction) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) Instant(java.time.Instant) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with GeoObject

use of org.commongeoregistry.adapter.dataaccess.GeoObject in project geoprism-registry by terraframe.

the class GeoObjectEditorControllerNoOverTime method applyChangeRequest.

public void applyChangeRequest(String sessionId, ChangeRequest request, ParentTreeNode ptn, boolean isNew, Instant base, int sequence, Date startDate, Date endDate) {
    GeoObject child = ptn.getGeoObject();
    List<ParentTreeNode> childDbParents = new LinkedList<ParentTreeNode>();
    if (!isNew) {
        childDbParents = RegistryService.getInstance().getParentGeoObjects(sessionId, child.getUid(), child.getType().getCode(), null, false, startDate).getParents();
        // create
        for (ParentTreeNode ptnDbParent : childDbParents) {
            boolean shouldRemove = true;
            for (ParentTreeNode ptnParent : ptn.getParents()) {
                if (ptnParent.getGeoObject().equals(ptnDbParent.getGeoObject()) && ptnParent.getHierachyType().getCode().equals(ptnDbParent.getHierachyType().getCode())) {
                    shouldRemove = false;
                }
            }
            if (shouldRemove) {
                GeoObject parent = ptnDbParent.getGeoObject();
                RemoveChildAction action = new RemoveChildAction();
                action.addApprovalStatus(AllGovernanceStatus.PENDING);
                action.setChildId(child.getUid());
                action.setChildTypeCode(child.getType().getCode());
                action.setParentId(parent.getUid());
                action.setParentTypeCode(parent.getType().getCode());
                action.setHierarchyTypeCode(ptnDbParent.getHierachyType().getCode());
                action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
                action.setApiVersion(CGRAdapterProperties.getApiVersion());
                action.apply();
                request.addAction(action).apply();
            }
        }
    }
    // Create new relationships that don't already exist
    for (ParentTreeNode ptnParent : ptn.getParents()) {
        boolean alreadyExists = false;
        if (!isNew) {
            for (ParentTreeNode ptnDbParent : childDbParents) {
                if (ptnParent.getGeoObject().equals(ptnDbParent.getGeoObject()) && ptnParent.getHierachyType().getCode().equals(ptnDbParent.getHierachyType().getCode())) {
                    alreadyExists = true;
                }
            }
        }
        if (!alreadyExists) {
            GeoObject parent = ptnParent.getGeoObject();
            AddChildAction action = new AddChildAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setChildId(child.getUid());
            action.setChildTypeCode(child.getType().getCode());
            action.setParentId(parent.getUid());
            action.setParentTypeCode(parent.getType().getCode());
            action.setHierarchyTypeCode(ptnParent.getHierachyType().getCode());
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        }
    }
}
Also used : RemoveChildAction(net.geoprism.registry.action.tree.RemoveChildAction) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) AddChildAction(net.geoprism.registry.action.tree.AddChildAction) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) LinkedList(java.util.LinkedList)

Example 3 with GeoObject

use of org.commongeoregistry.adapter.dataaccess.GeoObject in project geoprism-registry by terraframe.

the class RegistryController method updateGeoObject.

/**
 * Update a new GeoObject in the Common Geo-Registry
 *
 * @pre
 * @post
 *
 * @param geoObject
 *          in GeoJSON format to be updated.
 * @throws ParseException
 *
 * @returns
 * @throws //TODO
 */
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_UPDATE)
public ResponseIF updateGeoObject(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_UPDATE_PARAM_GEOOBJECT) String jGeoObj, @RequestParamter(name = "startDate") String startDateString, @RequestParamter(name = "endDate") String endDateString) throws ParseException {
    Date startDate = (startDateString != null && startDateString.length() > 0) ? GeoRegistryUtil.parseDate(startDateString, true) : null;
    Date endDate = (endDateString != null && endDateString.length() > 0) ? GeoRegistryUtil.parseDate(endDateString, true) : null;
    GeoObject geoObject = this.registryService.updateGeoObject(request.getSessionId(), jGeoObj, startDate, endDate);
    CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
    return new RestBodyResponse(geoObject.toJSON(serializer));
}
Also used : GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 4 with GeoObject

use of org.commongeoregistry.adapter.dataaccess.GeoObject in project geoprism-registry by terraframe.

the class RegistryController method createGeoObject.

/**
 * Creates a new GeoObject in the Common Geo-Registry
 *
 * @pre
 * @post
 *
 * @param geoObject
 *          in GeoJSON format to be created.
 * @throws ParseException
 *
 * @returns
 * @throws //TODO
 */
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_CREATE)
public ResponseIF createGeoObject(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_CREATE_PARAM_GEOOBJECT) String jGeoObj, @RequestParamter(name = "startDate") String startDateString, @RequestParamter(name = "endDate") String endDateString) throws ParseException {
    Date startDate = (startDateString != null && startDateString.length() > 0) ? GeoRegistryUtil.parseDate(startDateString, true) : null;
    Date endDate = (endDateString != null && endDateString.length() > 0) ? GeoRegistryUtil.parseDate(endDateString, true) : null;
    GeoObject geoObject = this.registryService.createGeoObject(request.getSessionId(), jGeoObj, startDate, endDate);
    CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
    return new RestBodyResponse(geoObject.toJSON(serializer));
}
Also used : GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 5 with GeoObject

use of org.commongeoregistry.adapter.dataaccess.GeoObject in project geoprism-registry by terraframe.

the class RegistryController method getGeoObject.

/**
 * Returns a GeoObject with the given uid.
 *
 * @pre @post
 *
 * @param uid
 *          The UID of the GeoObject.
 *
 * @returns a GeoObject in GeoJSON format with the given uid. @throws
 */
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_GET)
public ResponseIF getGeoObject(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_GET_PARAM_ID) String id, @RequestParamter(name = RegistryUrls.GEO_OBJECT_GET_PARAM_TYPE_CODE) String typeCode, @RequestParamter(name = "date") String date) throws JSONException {
    GeoObject geoObject = this.registryService.getGeoObject(request.getSessionId(), id, typeCode, GeoRegistryUtil.parseDate(date, true));
    CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
    return new RestBodyResponse(geoObject.toJSON(serializer));
}
Also used : GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint)

Aggregations

GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)52 Test (org.junit.Test)22 Request (com.runwaysdk.session.Request)12 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)11 Endpoint (com.runwaysdk.mvc.Endpoint)9 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)8 Date (java.util.Date)8 JsonArray (com.google.gson.JsonArray)7 TestUserInfo (net.geoprism.registry.test.TestUserInfo)7 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)7 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)7 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)6 SmartExceptionDTO (com.runwaysdk.business.SmartExceptionDTO)5 InputStream (java.io.InputStream)5 GeoObjectImportConfiguration (net.geoprism.registry.io.GeoObjectImportConfiguration)5 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)5 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)5 CustomSerializer (org.commongeoregistry.adapter.metadata.CustomSerializer)5 JSONObject (org.json.JSONObject)5 JsonObject (com.google.gson.JsonObject)4