Search in sources :

Example 11 with MdBusiness

use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.

the class ListTypeVersion method generateShapefile.

// public List<ExecutableJob> getJobs()
// {
// LinkedList<ExecutableJob> jobs = new LinkedList<ExecutableJob>();
// 
// PublishShapefileJobQuery psjq = new PublishShapefileJobQuery(new
// QueryFactory());
// psjq.WHERE(psjq.getVersion().EQ(this));
// 
// try (OIterator<? extends PublishShapefileJob> it = psjq.getIterator())
// {
// jobs.addAll(it.getAll());
// }
// 
// PublishListTypeVersionJobQuery pmlvj = new
// PublishListTypeVersionJobQuery(new QueryFactory());
// pmlvj.WHERE(pmlvj.getListTypeVersion().EQ(this));
// 
// try (OIterator<? extends PublishListTypeVersionJob> it =
// pmlvj.getIterator())
// {
// jobs.addAll(it.getAll());
// }
// 
// return jobs;
// }
public File generateShapefile() {
    String filename = this.getOid() + ".zip";
    final ListType list = this.getListType();
    final File directory = list.getShapefileDirectory();
    directory.mkdirs();
    final File file = new File(directory, filename);
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.isValid(mdAttribute)).collect(Collectors.toList());
    try {
        ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(this, mdBusiness, mdAttributes, null);
        try (final InputStream istream = exporter.export()) {
            try (final FileOutputStream fos = new FileOutputStream(file)) {
                IOUtils.copy(istream, fos);
            }
        }
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
    return file;
}
Also used : MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) Authenticate(com.runwaysdk.business.rbac.Authenticate) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) MdAttributeDateTimeUtil(com.runwaysdk.constants.MdAttributeDateTimeUtil) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) JSONException(org.json.JSONException) Condition(com.runwaysdk.query.Condition) IndexTypes(com.runwaysdk.constants.IndexTypes) TableMetadata(net.geoprism.registry.masterlist.TableMetadata) Map(java.util.Map) ServerGeoObjectRestriction(net.geoprism.registry.query.ServerGeoObjectRestriction) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) ComponentIF(com.runwaysdk.ComponentIF) ListTypeAttributeComparator(net.geoprism.registry.masterlist.ListTypeAttributeComparator) Set(java.util.Set) BusinessFacade(com.runwaysdk.business.BusinessFacade) IOUtils(org.apache.commons.io.IOUtils) JsonArray(com.google.gson.JsonArray) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) GeoserverRemoveWMSCommand(net.geoprism.registry.command.GeoserverRemoveWMSCommand) MdAttributeLong(com.runwaysdk.system.metadata.MdAttributeLong) SimpleDateFormat(java.text.SimpleDateFormat) JsonParser(com.google.gson.JsonParser) DefaultConfiguration(net.geoprism.DefaultConfiguration) NumberFormat(java.text.NumberFormat) MdAttributeDouble(com.runwaysdk.system.metadata.MdAttributeDouble) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) F(com.runwaysdk.query.F) Classification(net.geoprism.registry.model.Classification) BasicVertexQuery(net.geoprism.registry.query.graph.BasicVertexQuery) MdAttributeFloatInfo(com.runwaysdk.constants.MdAttributeFloatInfo) QueryFactory(com.runwaysdk.query.QueryFactory) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) VertexGeoObjectQuery(net.geoprism.registry.query.graph.VertexGeoObjectQuery) JsonSerializable(net.geoprism.registry.view.JsonSerializable) MdAttributeNumberDAOIF(com.runwaysdk.dataaccess.MdAttributeNumberDAOIF) ComponentQuery(com.runwaysdk.query.ComponentQuery) MdAttribute(com.runwaysdk.system.metadata.MdAttribute) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) Coordinate(com.vividsolutions.jts.geom.Coordinate) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ListCurationHistory(net.geoprism.registry.curation.ListCurationHistory) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Business(com.runwaysdk.business.Business) MdAttributeFloatDAO(com.runwaysdk.dataaccess.metadata.MdAttributeFloatDAO) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) BasicVertexRestriction(net.geoprism.registry.query.graph.BasicVertexRestriction) BusinessInfo(com.runwaysdk.constants.BusinessInfo) MdAttributePolygon(com.runwaysdk.system.gis.metadata.MdAttributePolygon) JsonObject(com.google.gson.JsonObject) Operation(com.runwaysdk.business.rbac.Operation) Date(java.util.Date) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) ValueObject(com.runwaysdk.dataaccess.ValueObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ClassificationType(net.geoprism.registry.model.ClassificationType) MdAttributeBooleanInfo(com.runwaysdk.constants.MdAttributeBooleanInfo) MdTableInfo(com.runwaysdk.constants.MdTableInfo) ValueQuery(com.runwaysdk.query.ValueQuery) MdAttributeShape(com.runwaysdk.system.gis.metadata.MdAttributeShape) Locale(java.util.Locale) Geometry(com.vividsolutions.jts.geom.Geometry) ParseException(java.text.ParseException) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) Database(com.runwaysdk.dataaccess.database.Database) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) DateFormat(java.text.DateFormat) GeoserverFacade(net.geoprism.gis.geoserver.GeoserverFacade) BusinessQuery(com.runwaysdk.business.BusinessQuery) MdAttributeCharacterDAO(com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO) UnsupportedOperationException(com.amazonaws.services.kms.model.UnsupportedOperationException) LocationInfo(net.geoprism.registry.model.LocationInfo) Collection(java.util.Collection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) MdAttributeConcreteInfo(com.runwaysdk.constants.MdAttributeConcreteInfo) Collectors(java.util.stream.Collectors) ProgressService(net.geoprism.registry.progress.ProgressService) FileNotFoundException(java.io.FileNotFoundException) Page(net.geoprism.registry.view.Page) List(java.util.List) MdAttributeDoubleInfo(com.runwaysdk.constants.MdAttributeDoubleInfo) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) MdAttributeMultiPolygon(com.runwaysdk.system.gis.metadata.MdAttributeMultiPolygon) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) Entry(java.util.Map.Entry) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) GeometryType(org.commongeoregistry.adapter.constants.GeometryType) MdAttributeIndices(com.runwaysdk.system.metadata.MdAttributeIndices) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) CurationService(net.geoprism.registry.curation.CurationService) HashMap(java.util.HashMap) ListTypeVersionPageQuery(net.geoprism.registry.query.ListTypeVersionPageQuery) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeLocalInfo(com.runwaysdk.constants.MdAttributeLocalInfo) Progress(net.geoprism.registry.progress.Progress) Constants(com.runwaysdk.constants.Constants) Point(com.vividsolutions.jts.geom.Point) ServiceFactory(net.geoprism.registry.service.ServiceFactory) Classifier(net.geoprism.ontology.Classifier) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) LocalizationFacade(com.runwaysdk.localization.LocalizationFacade) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeCharacterInfo(com.runwaysdk.constants.MdAttributeCharacterInfo) GeoserverCreateWMSCommand(net.geoprism.registry.command.GeoserverCreateWMSCommand) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) MdAttributeUUIDDAO(com.runwaysdk.dataaccess.metadata.MdAttributeUUIDDAO) LinkedList(java.util.LinkedList) LocalStruct(com.runwaysdk.business.LocalStruct) MdAttributeGeometry(com.runwaysdk.system.gis.metadata.MdAttributeGeometry) MdAttributeDateTime(com.runwaysdk.system.metadata.MdAttributeDateTime) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdAttributeConcreteDAO(com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO) Term(org.commongeoregistry.adapter.Term) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) FileInputStream(java.io.FileInputStream) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) OIterator(com.runwaysdk.query.OIterator) Session(com.runwaysdk.session.Session) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) Collections(java.util.Collections) InputStream(java.io.InputStream) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) IOException(java.io.IOException) File(java.io.File) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 12 with MdBusiness

use of com.runwaysdk.system.metadata.MdBusiness 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 13 with MdBusiness

use of com.runwaysdk.system.metadata.MdBusiness 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 14 with MdBusiness

use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.

the class MasterListVersion method createTable.

private TableMetadata createTable() {
    MasterList masterlist = this.getMasterlist();
    TableMetadata metadata = new TableMetadata();
    Locale currentLocale = Session.getCurrentLocale();
    String viewName = this.getTableName();
    // Create the MdTable
    MdBusinessDAO mdTableDAO = MdBusinessDAO.newInstance();
    mdTableDAO.setValue(MdTableInfo.NAME, viewName);
    mdTableDAO.setValue(MdTableInfo.PACKAGE, RegistryConstants.TABLE_PACKAGE);
    mdTableDAO.setStructValue(MdTableInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, masterlist.getDisplayLabel().getValue());
    mdTableDAO.setValue(MdTableInfo.TABLE_NAME, viewName);
    mdTableDAO.setValue(MdTableInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
    mdTableDAO.apply();
    MdBusiness mdBusiness = (MdBusiness) BusinessFacade.get(mdTableDAO);
    MdAttributeUUIDDAO mdAttributeOriginalId = MdAttributeUUIDDAO.newInstance();
    mdAttributeOriginalId.setValue(MdAttributeCharacterInfo.NAME, ORIGINAL_OID);
    mdAttributeOriginalId.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
    mdAttributeOriginalId.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Original oid");
    mdAttributeOriginalId.apply();
    metadata.setMdBusiness(mdBusiness);
    Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
    ServerGeoObjectType type = masterlist.getGeoObjectType();
    this.createMdAttributeFromAttributeType(mdBusiness, type.getGeometryType());
    Collection<AttributeType> attributeTypes = type.getAttributeMap().values();
    for (AttributeType attributeType : attributeTypes) {
        if (this.isValid(attributeType)) {
            createMdAttributeFromAttributeType(metadata, attributeType, type, locales);
        }
    }
    JsonArray hierarchies = masterlist.getHierarchiesAsJson();
    for (int i = 0; i < hierarchies.size(); i++) {
        JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
        List<String> pCodes = masterlist.getParentCodes(hierarchy);
        if (pCodes.size() > 0) {
            String hCode = hierarchy.get("code").getAsString();
            ServerHierarchyType hierarchyType = ServiceFactory.getMetadataCache().getHierachyType(hCode).get();
            String hierarchyLabel = hierarchyType.getDisplayLabel().getValue(currentLocale);
            for (String pCode : pCodes) {
                ServerGeoObjectType got = ServerGeoObjectType.get(pCode);
                String typeLabel = got.getLabel().getValue(currentLocale);
                String attributeName = hCode.toLowerCase() + pCode.toLowerCase();
                String label = typeLabel + " (" + hierarchyLabel + ")";
                String codeDescription = LocalizationFacade.localize("masterlist.code.description");
                codeDescription = codeDescription.replaceAll("\\{typeLabel\\}", typeLabel);
                codeDescription = codeDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
                String labelDescription = LocalizationFacade.localize("masterlist.label.description");
                labelDescription = labelDescription.replaceAll("\\{typeLabel\\}", typeLabel);
                labelDescription = labelDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
                MdAttributeCharacterDAO mdAttributeCode = MdAttributeCharacterDAO.newInstance();
                mdAttributeCode.setValue(MdAttributeCharacterInfo.NAME, attributeName);
                mdAttributeCode.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
                mdAttributeCode.setValue(MdAttributeCharacterInfo.SIZE, "255");
                mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label);
                mdAttributeCode.addItem(MdAttributeCharacterInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
                mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, codeDescription);
                mdAttributeCode.apply();
                MdAttributeCharacterDAO mdAttributeDefaultLocale = MdAttributeCharacterDAO.newInstance();
                mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + DEFAULT_LOCALE);
                mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
                mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
                mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label + " (defaultLocale)");
                mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", "default"));
                mdAttributeDefaultLocale.apply();
                for (Locale locale : locales) {
                    MdAttributeCharacterDAO mdAttributeLocale = MdAttributeCharacterDAO.newInstance();
                    mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + locale.toString());
                    mdAttributeLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
                    mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
                    mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label + " (" + locale + ")");
                    mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", locale.toString()));
                    mdAttributeLocale.apply();
                }
            }
        }
    }
    JsonArray subtypeHierarchies = masterlist.getSubtypeHierarchiesAsJson();
    for (int i = 0; i < subtypeHierarchies.size(); i++) {
        JsonObject hierarchy = subtypeHierarchies.get(i).getAsJsonObject();
        if (hierarchy.has("selected") && hierarchy.get("selected").getAsBoolean()) {
            String hCode = hierarchy.get("code").getAsString();
            HierarchyType hierarchyType = ServiceFactory.getAdapter().getMetadataCache().getHierachyType(hCode).get();
            String hierarchyLabel = hierarchyType.getLabel().getValue(currentLocale);
            String attributeName = hCode.toLowerCase();
            String codeDescription = LocalizationFacade.localize("masterlist.code.description");
            codeDescription = codeDescription.replaceAll("\\{typeLabel\\}", "");
            codeDescription = codeDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
            String labelDescription = LocalizationFacade.localize("masterlist.label.description");
            labelDescription = labelDescription.replaceAll("\\{typeLabel\\}", "");
            labelDescription = labelDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
            MdAttributeCharacterDAO mdAttributeCode = MdAttributeCharacterDAO.newInstance();
            mdAttributeCode.setValue(MdAttributeCharacterInfo.NAME, attributeName);
            mdAttributeCode.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
            mdAttributeCode.setValue(MdAttributeCharacterInfo.SIZE, "255");
            mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel);
            mdAttributeCode.addItem(MdAttributeCharacterInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
            mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, codeDescription);
            mdAttributeCode.apply();
            MdAttributeCharacterDAO mdAttributeDefaultLocale = MdAttributeCharacterDAO.newInstance();
            mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + DEFAULT_LOCALE);
            mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
            mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
            mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel + " (defaultLocale)");
            mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", "default"));
            mdAttributeDefaultLocale.apply();
            for (Locale locale : locales) {
                MdAttributeCharacterDAO mdAttributeLocale = MdAttributeCharacterDAO.newInstance();
                mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + locale.toString());
                mdAttributeLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
                mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
                mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel + " (" + locale + ")");
                mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", locale.toString()));
                mdAttributeLocale.apply();
            }
        }
    }
    return metadata;
}
Also used : TableMetadata(net.geoprism.registry.masterlist.TableMetadata) Locale(java.util.Locale) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeUUIDDAO(com.runwaysdk.dataaccess.metadata.MdAttributeUUIDDAO) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) JsonArray(com.google.gson.JsonArray) MdAttributeCharacterDAO(com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType)

Example 15 with MdBusiness

use of com.runwaysdk.system.metadata.MdBusiness 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

MdBusiness (com.runwaysdk.system.metadata.MdBusiness)28 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)13 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)13 Locale (java.util.Locale)12 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)12 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)11 Business (com.runwaysdk.business.Business)10 LinkedList (java.util.LinkedList)10 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)10 QueryFactory (com.runwaysdk.query.QueryFactory)9 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)8 MdAttributeMultiLineString (com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString)8 MdAttributeMultiPoint (com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint)8 MdAttributePoint (com.runwaysdk.system.gis.metadata.MdAttributePoint)8 MdAttributeCharacter (com.runwaysdk.system.metadata.MdAttributeCharacter)8 List (java.util.List)8 MdAttributeBoolean (com.runwaysdk.system.metadata.MdAttributeBoolean)7 MdAttributeDouble (com.runwaysdk.system.metadata.MdAttributeDouble)7 MdAttributeLong (com.runwaysdk.system.metadata.MdAttributeLong)7 JsonArray (com.google.gson.JsonArray)6