Search in sources :

Example 1 with PrivateTypeIsReferencedInPublicMasterLists

use of net.geoprism.registry.geoobjecttype.PrivateTypeIsReferencedInPublicMasterLists in project geoprism-registry by terraframe.

the class GeoObjectTypeMetadata method apply.

@Override
public void apply() {
    if (!this.isNew() && this.isModified(GeoObjectTypeMetadata.ISPRIVATE)) {
        final ServerGeoObjectType type = this.getServerType();
        // They aren't allowed to set this to private in certain scenarios
        if (this.getIsPrivate()) {
            if (this.hasPublicChildren()) {
                PrivateTypeHasPublicChildren ex = new PrivateTypeHasPublicChildren();
                ex.setTypeLabel(this.getServerType().getLabel().getValue());
                throw ex;
            }
            if (this.isReferencedInPublicListTypes()) {
                PrivateTypeIsReferencedInPublicMasterLists ex = new PrivateTypeIsReferencedInPublicMasterLists();
                ex.setTypeLabel(this.getServerType().getLabel().getValue());
                throw ex;
            }
        } else {
            if (this.hasPrivateParents()) {
                TypeHasPrivateParents ex = new TypeHasPrivateParents();
                ex.setTypeLabel(this.getServerType().getLabel().getValue());
                throw ex;
            }
        }
        // Set the isPrivate field for all children
        if (this.isModified(GeoObjectTypeMetadata.ISPRIVATE) && type.getIsAbstract()) {
            List<ServerGeoObjectType> subtypes = type.getSubtypes();
            for (ServerGeoObjectType subtype : subtypes) {
                GeoObjectTypeMetadata submetadata = subtype.getMetadata();
                submetadata.appLock();
                submetadata.setIsPrivate(this.getIsPrivate());
                submetadata.apply();
            }
        }
    }
    super.apply();
}
Also used : PrivateTypeIsReferencedInPublicMasterLists(net.geoprism.registry.geoobjecttype.PrivateTypeIsReferencedInPublicMasterLists) PrivateTypeHasPublicChildren(net.geoprism.registry.geoobjecttype.PrivateTypeHasPublicChildren) TypeHasPrivateParents(net.geoprism.registry.geoobjecttype.TypeHasPrivateParents)

Example 2 with PrivateTypeIsReferencedInPublicMasterLists

use of net.geoprism.registry.geoobjecttype.PrivateTypeIsReferencedInPublicMasterLists 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)

Aggregations

PrivateTypeIsReferencedInPublicMasterLists (net.geoprism.registry.geoobjecttype.PrivateTypeIsReferencedInPublicMasterLists)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 QueryFactory (com.runwaysdk.query.QueryFactory)1 Universal (com.runwaysdk.system.gis.geo.Universal)1 ListType (net.geoprism.registry.ListType)1 ListTypeQuery (net.geoprism.registry.ListTypeQuery)1 ListTypeVersionQuery (net.geoprism.registry.ListTypeVersionQuery)1 PrivateTypeHasPublicChildren (net.geoprism.registry.geoobjecttype.PrivateTypeHasPublicChildren)1 TypeHasPrivateParents (net.geoprism.registry.geoobjecttype.TypeHasPrivateParents)1