Search in sources :

Example 6 with Business

use of com.runwaysdk.business.Business in project geoprism-registry by terraframe.

the class AccountService method getRolesForUser.

/**
 * @param organizationCodes
 *          comma delimited list of registry codes. Returns all registry roles
 *          if empty.
 *
 * @return all of the roles are set to assigned equals false
 */
@Request(RequestType.SESSION)
public RegistryRole[] getRolesForUser(String sessionId, String userOID) {
    GeoprismUser geoPrismUser = GeoprismUser.get(userOID);
    List<RegistryRole> registryRoles = new LinkedList<RegistryRole>();
    Set<String> roleNameSet = new HashSet<String>();
    OIterator<? extends com.runwaysdk.system.Roles> roleIterator = geoPrismUser.getAllAssignedRole();
    for (Roles role : roleIterator) {
        RegistryRole registryRole = new RegistryRoleConverter().build(role);
        if (registryRole != null) {
            registryRole.setAssigned(true);
            LocalizedValueConverter.populateOrganizationDisplayLabel(registryRole);
            LocalizedValueConverter.populateGeoObjectTypeLabel(registryRole);
            registryRoles.add(registryRole);
            roleNameSet.add(registryRole.getName());
        }
    }
    // Add the registry roles that the user can be a member of based on their
    // organization affiliation
    OIterator<? extends Business> organizationIterators = geoPrismUser.getParents(OrganizationUser.CLASS);
    for (Business business : organizationIterators) {
        Organization organization = (Organization) business;
        List<RegistryRole> orgRoleIterator = this.getRolesForOrganization(organization.getCode());
        for (RegistryRole registryRole : orgRoleIterator) {
            if (!roleNameSet.contains(registryRole.getName())) {
                registryRoles.add(registryRole);
            }
        }
    }
    if (!roleNameSet.contains(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE)) {
        Roles sra = Roles.findRoleByName(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE);
        RegistryRole rrSRA = new RegistryRoleConverter().build(sra);
        rrSRA.setAssigned(false);
        registryRoles.add(rrSRA);
    }
    return registryRoles.stream().sorted(Comparator.comparing(RegistryRole::getOrganizationCode).thenComparing(RegistryRole::getGeoObjectTypeCode)).toArray(size -> new RegistryRole[size]);
}
Also used : RegistryRole(org.commongeoregistry.adapter.metadata.RegistryRole) Organization(net.geoprism.registry.Organization) Roles(com.runwaysdk.system.Roles) LinkedList(java.util.LinkedList) RegistryRoleConverter(net.geoprism.registry.conversion.RegistryRoleConverter) GeoprismUser(net.geoprism.GeoprismUser) HashSet(java.util.HashSet) Business(com.runwaysdk.business.Business) Request(com.runwaysdk.session.Request)

Example 7 with Business

use of com.runwaysdk.business.Business in project geoprism-registry by terraframe.

the class MasterListShapefileExporter method features.

public FeatureCollection<SimpleFeatureType, SimpleFeature> features(SimpleFeatureType featureType) {
    List<SimpleFeature> features = new ArrayList<SimpleFeature>();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    BusinessQuery query = this.version.buildQuery(this.filterJson);
    query.ORDER_BY_DESC(query.aCharacter(DefaultAttribute.CODE.getName()));
    OIterator<Business> objects = query.getIterator();
    try {
        while (objects.hasNext()) {
            Business row = objects.next();
            builder.set(GEOM, row.getObjectValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME));
            for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
                String attributeName = mdAttribute.definesAttribute();
                Object value = row.getObjectValue(attributeName);
                if (value != null) {
                    builder.set(this.getColumnName(attributeName), value);
                }
            }
            SimpleFeature feature = builder.buildFeature(row.getValue(DefaultAttribute.CODE.getName()));
            features.add(feature);
        }
    } finally {
        objects.close();
    }
    return new ListFeatureCollection(featureType, features);
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) ArrayList(java.util.ArrayList) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Business(com.runwaysdk.business.Business) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 8 with Business

use of com.runwaysdk.business.Business 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 9 with Business

use of com.runwaysdk.business.Business in project geoprism-registry by terraframe.

the class MasterListVersion method publishRecord.

@Transaction
public void publishRecord(ServerGeoObjectIF object) {
    object.setDate(this.getForDate());
    // Delete tile cache
    TileCache.deleteTiles(this);
    MasterList masterlist = this.getMasterlist();
    MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
    Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
    // Add the type ancestor fields
    ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
    Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap = masterlist.getAncestorMap(type);
    Set<ServerHierarchyType> hierarchiesOfSubTypes = type.getHierarchiesOfSubTypes();
    Collection<AttributeType> attributes = type.getAttributeMap().values();
    Business business = new Business(mdBusiness.definesType());
    this.publish(object, business, attributes, ancestorMap, hierarchiesOfSubTypes, locales);
}
Also used : Locale(java.util.Locale) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) 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 10 with Business

use of com.runwaysdk.business.Business in project geoprism-registry by terraframe.

the class MasterListVersion method data.

public JsonObject data(Integer pageNumber, Integer pageSize, String filterJson, String sort, Boolean includeGeometries) {
    if (includeGeometries == null) {
        includeGeometries = Boolean.FALSE;
    }
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    NumberFormat numberFormat = NumberFormat.getInstance(Session.getCurrentLocale());
    JsonArray results = new JsonArray();
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributes();
    BusinessQuery query = this.buildQuery(filterJson);
    if (sort != null && sort.length() > 0) {
        JsonObject jObject = JsonParser.parseString(sort).getAsJsonObject();
        String attribute = jObject.get("attribute").getAsString();
        String order = jObject.get("order").getAsString();
        if (order.equalsIgnoreCase("DESC")) {
            query.ORDER_BY_DESC(query.getS(attribute));
        } else {
            query.ORDER_BY_ASC(query.getS(attribute));
        }
        if (!attribute.equals(DefaultAttribute.CODE.getName())) {
            query.ORDER_BY_ASC(query.aCharacter(DefaultAttribute.CODE.getName()));
        }
    }
    try (OIterator<Business> iterator = query.getIterator(pageSize, pageNumber)) {
        while (iterator.hasNext()) {
            Business row = iterator.next();
            JsonObject object = new JsonObject();
            MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
            if (includeGeometries) {
                Geometry geom = (Geometry) row.getObjectValue(mdGeometry.definesAttribute());
                if (geom != null) {
                    GeoJSONWriter gw = new GeoJSONWriter();
                    org.wololo.geojson.Geometry gJSON = gw.write(geom);
                    JsonObject geojson = JsonParser.parseString(gJSON.toString()).getAsJsonObject();
                    object.add("geometry", geojson);
                }
            }
            object.addProperty(ORIGINAL_OID, row.getValue(ORIGINAL_OID));
            for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
                if (this.isValid(mdAttribute)) {
                    String attributeName = mdAttribute.definesAttribute();
                    Object value = row.getObjectValue(attributeName);
                    if (value != null) {
                        if (value instanceof Double) {
                            object.addProperty(mdAttribute.definesAttribute(), numberFormat.format((Double) value));
                        } else if (value instanceof Number) {
                            object.addProperty(mdAttribute.definesAttribute(), (Number) value);
                        } else if (value instanceof Boolean) {
                            object.addProperty(mdAttribute.definesAttribute(), (Boolean) value);
                        } else if (value instanceof String) {
                            object.addProperty(mdAttribute.definesAttribute(), (String) value);
                        } else if (value instanceof Character) {
                            object.addProperty(mdAttribute.definesAttribute(), (Character) value);
                        } else if (value instanceof Date) {
                            object.addProperty(mdAttribute.definesAttribute(), format.format((Date) value));
                        }
                    }
                }
            }
            results.add(object);
        }
    }
    JsonObject page = new JsonObject();
    page.addProperty("pageNumber", pageNumber);
    page.addProperty("pageSize", pageSize);
    page.addProperty("filter", filterJson);
    page.addProperty("count", query.getCount());
    page.add("results", results);
    return page;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeDouble(com.runwaysdk.system.metadata.MdAttributeDouble) Date(java.util.Date) JsonArray(com.google.gson.JsonArray) Geometry(com.vividsolutions.jts.geom.Geometry) MdAttributeGeometry(com.runwaysdk.system.gis.metadata.MdAttributeGeometry) VertexObject(com.runwaysdk.business.graph.VertexObject) JsonObject(com.google.gson.JsonObject) ValueObject(com.runwaysdk.dataaccess.ValueObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) SimpleDateFormat(java.text.SimpleDateFormat) GeoJSONWriter(org.wololo.jts2geojson.GeoJSONWriter) NumberFormat(java.text.NumberFormat) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Business(com.runwaysdk.business.Business) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Aggregations

Business (com.runwaysdk.business.Business)17 BusinessQuery (com.runwaysdk.business.BusinessQuery)12 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)8 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)7 LinkedList (java.util.LinkedList)7 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)6 List (java.util.List)6 Locale (java.util.Locale)6 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)6 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)6 JsonObject (com.google.gson.JsonObject)5 QueryFactory (com.runwaysdk.query.QueryFactory)5 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)4 Date (java.util.Date)4 Point (com.vividsolutions.jts.geom.Point)3 ArrayList (java.util.ArrayList)3 JsonArray (com.google.gson.JsonArray)2 VertexObject (com.runwaysdk.business.graph.VertexObject)2 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)2