Search in sources :

Example 41 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class GeoObjectUtilTest method testGetAncestorMapForTreeType.

@Test
@Request
public void testGetAncestorMapForTreeType() {
    ServerGeoObjectType type = USATestData.AREA.getServerObject();
    ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
    ServerGeoObjectIF object = new ServerGeoObjectService().getGeoObjectByCode(USATestData.CO_A_ONE.getCode(), type);
    List<GeoObjectType> dtoAncestors = type.getTypeAncestors(hierarchyType, true);
    List<ServerGeoObjectType> ancestors = new LinkedList<ServerGeoObjectType>();
    for (GeoObjectType ancestor : dtoAncestors) {
        ancestors.add(ServerGeoObjectType.get(ancestor));
    }
    Map<String, LocationInfo> map = object.getAncestorMap(hierarchyType, ancestors);
    Assert.assertEquals(3, map.size());
    // Validate the county values
    Assert.assertTrue(map.containsKey(USATestData.COUNTY.getCode()));
    LocationInfo vObject = map.get(USATestData.COUNTY.getCode());
    Assert.assertEquals(USATestData.CO_C_ONE.getCode(), vObject.getCode());
    Assert.assertEquals(USATestData.CO_C_ONE.getDisplayLabel(), vObject.getLabel());
    // Validate the state values
    Assert.assertTrue(map.containsKey(USATestData.STATE.getCode()));
    vObject = map.get(USATestData.STATE.getCode());
    Assert.assertEquals(USATestData.COLORADO.getCode(), vObject.getCode());
    Assert.assertEquals(USATestData.COLORADO.getDisplayLabel(), vObject.getLabel());
    // Validate the country values
    Assert.assertTrue(map.containsKey(USATestData.COUNTRY.getCode()));
    vObject = map.get(USATestData.COUNTRY.getCode());
    Assert.assertEquals(USATestData.USA.getCode(), vObject.getCode());
    Assert.assertEquals(USATestData.USA.getDisplayLabel(), vObject.getLabel());
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) LinkedList(java.util.LinkedList) LocationInfo(net.geoprism.registry.model.LocationInfo) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 42 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class ListType method markAsInvalid.

public void markAsInvalid(ServerGeoObjectType type) {
    boolean isValid = true;
    JsonArray hierarchies = this.getHierarchiesAsJson();
    ServerGeoObjectType masterlistType = this.getGeoObjectType();
    for (int i = 0; i < hierarchies.size(); i++) {
        JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
        String hCode = hierarchy.get("code").getAsString();
        Optional<ServerHierarchyType> ht = ServiceFactory.getMetadataCache().getHierachyType(hCode);
        if (ht.isPresent()) {
            List<String> pCodes = this.getParentCodes(hierarchy);
            if (pCodes.contains(type.getCode()) || type.getCode().equals(masterlistType.getCode())) {
                isValid = false;
            }
        } else {
            isValid = false;
        }
    }
    if (!isValid) {
        this.appLock();
        this.setValid(false);
        this.apply();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject)

Example 43 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class ListType method getAncestorMap.

public Map<ServerHierarchyType, List<ServerGeoObjectType>> getAncestorMap(ServerGeoObjectType type) {
    Map<ServerHierarchyType, List<ServerGeoObjectType>> map = new HashMap<>();
    JsonArray hierarchies = this.getHierarchiesAsJson();
    for (int i = 0; i < hierarchies.size(); i++) {
        JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
        List<String> pCodes = this.getParentCodes(hierarchy);
        if (pCodes.size() > 0) {
            String hCode = hierarchy.get("code").getAsString();
            ServerHierarchyType hierarchyType = ServerHierarchyType.get(hCode);
            List<GeoObjectType> dtoAncestors = type.getTypeAncestors(hierarchyType, true);
            List<ServerGeoObjectType> ancestors = new LinkedList<ServerGeoObjectType>();
            for (GeoObjectType ancestor : dtoAncestors) {
                ancestors.add(ServerGeoObjectType.get(ancestor));
            }
            map.put(hierarchyType, ancestors);
        }
    }
    return map;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HashMap(java.util.HashMap) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) LinkedList(java.util.LinkedList) JsonArray(com.google.gson.JsonArray) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) List(java.util.List) LinkedList(java.util.LinkedList)

Example 44 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class ListTypeVersion method publishNoAuth.

@Transaction
public String publishNoAuth() {
    this.lock();
    try {
        ListType masterlist = this.getListType();
        if (!masterlist.isValid()) {
            throw new InvalidMasterListException();
        }
        // Delete tile cache
        ListTileCache.deleteTiles(this);
        ListCurationHistory.deleteAll(this);
        MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
        mdBusiness.deleteAllRecords();
        MdAttributeConcreteDAO status = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("status");
        if (status != null) {
            ListTypeAttributeGroup.remove(status);
            status.delete();
        }
        MdAttributeConcreteDAO statusDefaultLocale = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("statusDefaultLocale");
        if (statusDefaultLocale != null) {
            ListTypeAttributeGroup.remove(statusDefaultLocale);
            statusDefaultLocale.delete();
        }
        ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
        Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
        // Add the type ancestor fields
        Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap = masterlist.getAncestorMap(type);
        Collection<AttributeType> attributes = type.getAttributeMap().values();
        Set<ServerHierarchyType> hierarchiesOfSubTypes = type.getHierarchiesOfSubTypes();
        // ServerGeoObjectService service = new ServerGeoObjectService();
        // ServerGeoObjectQuery query = service.createQuery(type,
        // this.getPeriod());
        Date forDate = this.getForDate();
        BasicVertexRestriction restriction = masterlist.getRestriction(type, forDate);
        BasicVertexQuery query = new BasicVertexQuery(type, forDate);
        query.setRestriction(restriction);
        Long count = query.getCount();
        if (count == null) {
            count = 0L;
        }
        long current = 0;
        try {
            ProgressService.put(this.getOid(), new Progress(0L, count, ""));
            int pageSize = 1000;
            long skip = 0;
            while (skip < count) {
                query = new BasicVertexQuery(type, forDate);
                query.setRestriction(restriction);
                query.setLimit(pageSize);
                query.setSkip(skip);
                // List<GeoObjectStatus> validStats = new
                // ArrayList<GeoObjectStatus>();
                // validStats.add(GeoObjectStatus.ACTIVE);
                // validStats.add(GeoObjectStatus.INACTIVE);
                // validStats.add(GeoObjectStatus.PENDING);
                // validStats.add(GeoObjectStatus.NEW);
                // query.setRestriction(new ServerStatusRestriction(validStats,
                // this.getForDate(), JoinOp.OR));
                List<ServerGeoObjectIF> results = query.getResults();
                for (ServerGeoObjectIF result : results) {
                    Business business = new Business(mdBusiness.definesType());
                    publish(masterlist, type, result, business, attributes, ancestorMap, hierarchiesOfSubTypes, locales);
                    Thread.yield();
                    ProgressService.put(this.getOid(), new Progress(current++, count, ""));
                }
                skip += pageSize;
            }
            this.setPublishDate(new Date());
            this.apply();
            return this.toJSON(true).toString();
        } finally {
            ProgressService.remove(this.getOid());
        }
    } finally {
        this.unlock();
    }
}
Also used : Locale(java.util.Locale) MdAttributeConcreteDAO(com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Progress(net.geoprism.registry.progress.Progress) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Date(java.util.Date) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) Point(com.vividsolutions.jts.geom.Point) BasicVertexRestriction(net.geoprism.registry.query.graph.BasicVertexRestriction) BasicVertexQuery(net.geoprism.registry.query.graph.BasicVertexQuery) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdAttributeLong(com.runwaysdk.system.metadata.MdAttributeLong) List(java.util.List) LinkedList(java.util.LinkedList) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Business(com.runwaysdk.business.Business) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 45 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class MasterList method markAsInvalid.

public void markAsInvalid(ServerGeoObjectType type) {
    boolean isValid = true;
    JsonArray hierarchies = this.getHierarchiesAsJson();
    ServerGeoObjectType masterlistType = this.getGeoObjectType();
    for (int i = 0; i < hierarchies.size(); i++) {
        JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
        String hCode = hierarchy.get("code").getAsString();
        Optional<ServerHierarchyType> ht = ServiceFactory.getMetadataCache().getHierachyType(hCode);
        if (ht.isPresent()) {
            List<String> pCodes = this.getParentCodes(hierarchy);
            if (pCodes.contains(type.getCode()) || type.getCode().equals(masterlistType.getCode())) {
                isValid = false;
            }
        } else {
            isValid = false;
        }
    }
    if (!isValid) {
        this.appLock();
        this.setValid(false);
        this.apply();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject)

Aggregations

ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)86 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)55 Request (com.runwaysdk.session.Request)38 JsonObject (com.google.gson.JsonObject)20 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)17 JsonArray (com.google.gson.JsonArray)16 LinkedList (java.util.LinkedList)14 List (java.util.List)14 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)12 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 Locale (java.util.Locale)10 Point (com.vividsolutions.jts.geom.Point)9 ServerParentTreeNode (net.geoprism.registry.model.ServerParentTreeNode)9 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)8 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)8 Organization (net.geoprism.registry.Organization)8