Search in sources :

Example 1 with ListTypeVersionQuery

use of net.geoprism.registry.ListTypeVersionQuery in project geoprism-registry by terraframe.

the class GeoObjectTypeMetadata method isReferencedInPublicListTypes.

private boolean isReferencedInPublicListTypes() {
    Universal uni = this.getUniversal();
    ServerGeoObjectType type = this.getServerType();
    QueryFactory qf = new QueryFactory();
    ListTypeVersionQuery versionQuery = new ListTypeVersionQuery(qf);
    versionQuery.WHERE(versionQuery.getListVisibility().EQ(ListType.PUBLIC));
    versionQuery.OR(versionQuery.getGeospatialVisibility().EQ(ListType.PUBLIC));
    ListTypeQuery mlq = new ListTypeQuery(qf);
    mlq.WHERE(mlq.EQ(versionQuery.getListType()));
    OIterator<? extends ListType> it = mlq.getIterator();
    while (it.hasNext()) {
        ListType list = it.next();
        if (list.getUniversal().getOid().equals(uni.getOid())) {
            PrivateTypeIsReferencedInPublicMasterLists ex = new PrivateTypeIsReferencedInPublicMasterLists();
            ex.setTypeLabel(this.getServerType().getLabel().getValue());
            throw ex;
        } else {
            JsonArray hierarchies = list.getHierarchiesAsJson();
            for (int i = 0; i < hierarchies.size(); i++) {
                JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
                JsonArray parents = hierarchy.get("parents").getAsJsonArray();
                for (int j = 0; j < parents.size(); ++j) {
                    JsonObject parent = parents.get(j).getAsJsonObject();
                    if (parent.has("selected") && parent.get("selected").getAsBoolean()) {
                        if (parent.has("code") && parent.get("code").getAsString().equals(type.getCode())) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : JsonArray(com.google.gson.JsonArray) Universal(com.runwaysdk.system.gis.geo.Universal) QueryFactory(com.runwaysdk.query.QueryFactory) PrivateTypeIsReferencedInPublicMasterLists(net.geoprism.registry.geoobjecttype.PrivateTypeIsReferencedInPublicMasterLists) ListType(net.geoprism.registry.ListType) ListTypeQuery(net.geoprism.registry.ListTypeQuery) JsonObject(com.google.gson.JsonObject) ListTypeVersionQuery(net.geoprism.registry.ListTypeVersionQuery)

Example 2 with ListTypeVersionQuery

use of net.geoprism.registry.ListTypeVersionQuery in project geoprism-registry by terraframe.

the class ListTypeService method getGeospatialVersions.

@Request(RequestType.SESSION)
public JsonArray getGeospatialVersions(String sessionId, String startDate, String endDate) {
    ListTypeVersionQuery query = new ListTypeVersionQuery(new QueryFactory());
    if (startDate != null && startDate.length() > 0) {
        query.AND(query.getForDate().GE(GeoRegistryUtil.parseDate(startDate)));
    }
    if (endDate != null && endDate.length() > 0) {
        query.AND(query.getForDate().LE(GeoRegistryUtil.parseDate(endDate)));
    }
    query.ORDER_BY_DESC(query.getListType());
    query.ORDER_BY_DESC(query.getForDate());
    query.ORDER_BY_DESC(query.getVersionNumber());
    Map<String, Set<String>> orgMap = new LinkedHashMap<String, Set<String>>();
    Map<String, Set<String>> typeMap = new LinkedHashMap<String, Set<String>>();
    Map<String, JsonObject> listMap = new LinkedHashMap<String, JsonObject>();
    try (OIterator<? extends ListTypeVersion> it = query.getIterator()) {
        while (it.hasNext()) {
            ListTypeVersion version = it.next();
            ListType listType = version.getListType();
            final boolean isMember = Organization.isMember(listType.getOrganization());
            if ((version.getWorking() && listType.doesActorHaveExploratoryPermission()) || (isMember || version.getGeospatialVisibility().equals(ListType.PUBLIC))) {
                if (!listMap.containsKey(listType.getOid())) {
                    JsonObject object = new JsonObject();
                    object.addProperty("label", listType.getDisplayLabel().getValue());
                    object.addProperty("oid", listType.getOid());
                    object.add("versions", new JsonArray());
                    listMap.put(listType.getOid(), object);
                    String gotCode = listType.getGeoObjectType().getCode();
                    if (!typeMap.containsKey(gotCode)) {
                        typeMap.put(gotCode, new HashSet<String>());
                    }
                    typeMap.get(gotCode).add(listType.getOid());
                    String orgCode = listType.getOrganization().getCode();
                    if (!orgMap.containsKey(orgCode)) {
                        orgMap.put(orgCode, new HashSet<String>());
                    }
                    orgMap.get(orgCode).add(gotCode);
                }
                JsonObject object = new JsonObject();
                object.addProperty("oid", version.getOid());
                object.addProperty("forDate", GeoRegistryUtil.formatDate(version.getForDate(), false));
                object.addProperty("versionNumber", version.getVersionNumber());
                listMap.get(listType.getOid()).get("versions").getAsJsonArray().add(object);
            }
        }
    }
    JsonArray jaOrgs = new JsonArray();
    for (String orgCode : orgMap.keySet()) {
        Organization org = ServiceFactory.getMetadataCache().getOrganization(orgCode).get();
        JsonObject joOrg = new JsonObject();
        joOrg.addProperty("orgCode", orgCode);
        joOrg.add("orgLabel", LocalizedValueConverter.convertNoAutoCoalesce(org.getDisplayLabel()).toJSON());
        JsonArray jaTypes = new JsonArray();
        for (String gotCode : orgMap.get(orgCode)) {
            ServerGeoObjectType type = ServiceFactory.getMetadataCache().getGeoObjectType(gotCode).get();
            JsonObject joType = new JsonObject();
            joType.addProperty("typeCode", gotCode);
            joType.add("typeLabel", type.getLabel().toJSON());
            JsonArray jaLists = new JsonArray();
            for (String listOid : typeMap.get(gotCode)) {
                JsonObject joListType = listMap.get(listOid);
                JsonArray jaVersions = joListType.get("versions").getAsJsonArray();
                if (jaVersions.size() > 0) {
                    jaLists.add(joListType);
                }
            }
            joType.add("lists", jaLists);
            if (jaLists.size() > 0) {
                jaTypes.add(joType);
            }
        }
        joOrg.add("types", jaTypes);
        if (jaTypes.size() > 0) {
            jaOrgs.add(joOrg);
        }
    }
    return jaOrgs;
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) Set(java.util.Set) HashSet(java.util.HashSet) Organization(net.geoprism.registry.Organization) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) ListTypeVersionQuery(net.geoprism.registry.ListTypeVersionQuery) LinkedHashMap(java.util.LinkedHashMap) JsonArray(com.google.gson.JsonArray) ListType(net.geoprism.registry.ListType) Request(com.runwaysdk.session.Request)

Example 3 with ListTypeVersionQuery

use of net.geoprism.registry.ListTypeVersionQuery in project geoprism-registry by terraframe.

the class ListTypeService method getPublicVersions.

@Request(RequestType.SESSION)
public JsonArray getPublicVersions(String sessionId, String listOid) {
    JsonArray response = new JsonArray();
    ListType listType = ListType.get(listOid);
    final boolean isMember = Organization.isMember(listType.getOrganization());
    ListTypeVersionQuery query = new ListTypeVersionQuery(new QueryFactory());
    query.WHERE(query.getListType().EQ(listType));
    query.AND(query.getWorking().EQ(false));
    query.ORDER_BY_DESC(query.getListType());
    query.ORDER_BY_DESC(query.getForDate());
    query.ORDER_BY_DESC(query.getVersionNumber());
    try (OIterator<? extends ListTypeVersion> it = query.getIterator()) {
        while (it.hasNext()) {
            ListTypeVersion list = it.next();
            if (isMember || list.getListVisibility().equals(ListType.PUBLIC)) {
                response.add(list.toJSON(false));
            }
        }
    }
    return response;
}
Also used : JsonArray(com.google.gson.JsonArray) QueryFactory(com.runwaysdk.query.QueryFactory) ListType(net.geoprism.registry.ListType) ListTypeVersion(net.geoprism.registry.ListTypeVersion) ListTypeVersionQuery(net.geoprism.registry.ListTypeVersionQuery) Request(com.runwaysdk.session.Request)

Aggregations

JsonArray (com.google.gson.JsonArray)3 QueryFactory (com.runwaysdk.query.QueryFactory)3 ListType (net.geoprism.registry.ListType)3 ListTypeVersionQuery (net.geoprism.registry.ListTypeVersionQuery)3 JsonObject (com.google.gson.JsonObject)2 Request (com.runwaysdk.session.Request)2 ListTypeVersion (net.geoprism.registry.ListTypeVersion)2 Universal (com.runwaysdk.system.gis.geo.Universal)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 ListTypeQuery (net.geoprism.registry.ListTypeQuery)1 Organization (net.geoprism.registry.Organization)1 PrivateTypeIsReferencedInPublicMasterLists (net.geoprism.registry.geoobjecttype.PrivateTypeIsReferencedInPublicMasterLists)1 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)1