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);
}
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 + "].");
}
}
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);
}
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;
}
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();
}
}
Aggregations