Search in sources :

Example 1 with ServerGeoObjectTypeConverter

use of net.geoprism.registry.conversion.ServerGeoObjectTypeConverter in project geoprism-registry by terraframe.

the class PatchExistsAndInvalid method addAttributes.

@Transaction
private void addAttributes() {
    List<Universal> unis = getUniversals();
    for (Universal uni : unis) {
        MdBusinessDAO bizDAO = (MdBusinessDAO) BusinessFacade.getEntityDAO(uni.getMdBusiness());
        MdAttributeConcreteDAO postgresStatusAttr = (MdAttributeConcreteDAO) bizDAO.definesAttribute(STATUS_ATTRIBUTE_NAME);
        if (postgresStatusAttr != null) {
            postgresStatusAttr.delete();
        }
        MdGeoVertexDAO mdVertex = GeoVertexType.getMdGeoVertex(uni.getUniversalId());
        MdAttributeEnumerationDAO statusMdAttr = (MdAttributeEnumerationDAO) mdVertex.definesAttribute(STATUS_ATTRIBUTE_NAME);
        if (statusMdAttr != null) {
            statusMdAttr.delete();
        }
    }
    for (Universal uni : unis) {
        ServerGeoObjectType type = new ServerGeoObjectTypeConverter().build(uni);
        MdGraphClassDAOIF mdClass = type.getMdVertex();
        MdAttributeDAOIF existing = mdClass.definesAttribute(DefaultAttribute.EXISTS.getName());
        if (existing == null) {
            logger.info("Adding new attributes to [" + mdClass.getKey() + "].");
            MdAttributeBooleanDAO existsMdAttr = MdAttributeBooleanDAO.newInstance();
            existsMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.EXISTS.getName());
            existsMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.EXISTS.getDefaultLocalizedName());
            existsMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.EXISTS.getDefaultDescription());
            existsMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdClass.getOid());
            existsMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.FALSE);
            existsMdAttr.setValue(MdAttributeConcreteInfo.DEFAULT_VALUE, MdAttributeBooleanInfo.FALSE);
            existsMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
            existsMdAttr.apply();
            MdAttributeBooleanDAO invalidMdAttr = MdAttributeBooleanDAO.newInstance();
            invalidMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.INVALID.getName());
            invalidMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.INVALID.getDefaultLocalizedName());
            invalidMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.INVALID.getDefaultDescription());
            invalidMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdClass.getOid());
            invalidMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.FALSE);
            invalidMdAttr.setValue(MdAttributeConcreteInfo.DEFAULT_VALUE, MdAttributeBooleanInfo.FALSE);
            invalidMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
            invalidMdAttr.apply();
        }
    }
    patchMasterlistVersions();
// TODO : We can't actually set this field to required unfortunately because of many different graph bugs.
// If we set it to required immediately when it's created, orientdb throws an error saying that objects
// don't have a required field. If we try to update the field to set it as required after the instance
// data has been patched, Runway tries to create the attribute twice because the MdAttribute in the cache
// still has the 'isNew' flag set to true. We can't do this in a separate transaction because the patching
// transaction is controlled at a higher level than we have access to here.
// enforceInvalidRequired();
}
Also used : MdAttributeConcreteDAO(com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO) Universal(com.runwaysdk.system.gis.geo.Universal) MdAttributeEnumerationDAO(com.runwaysdk.dataaccess.metadata.MdAttributeEnumerationDAO) ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdAttributeBooleanDAO(com.runwaysdk.dataaccess.metadata.MdAttributeBooleanDAO) MdGraphClassDAOIF(com.runwaysdk.dataaccess.MdGraphClassDAOIF) MdGeoVertexDAO(com.runwaysdk.gis.dataaccess.metadata.graph.MdGeoVertexDAO) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with ServerGeoObjectTypeConverter

use of net.geoprism.registry.conversion.ServerGeoObjectTypeConverter in project geoprism-registry by terraframe.

the class PatchExistsAndInvalid method enforceInvalidRequired.

private void enforceInvalidRequired() {
    List<Universal> unis = PatchExistsAndInvalid.getUniversals();
    for (Universal uni : unis) {
        ServerGeoObjectType type = new ServerGeoObjectTypeConverter().build(uni);
        MdGraphClassDAOIF mdClass = type.getMdVertex();
        logger.info("Setting invalid mdAttr to required for class [" + mdClass.getKey() + "].");
        MdAttributeDAO invalidMdAttr = (MdAttributeDAO) mdClass.definesAttribute(DefaultAttribute.INVALID.getName());
        invalidMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
        invalidMdAttr.apply();
    }
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdGraphClassDAOIF(com.runwaysdk.dataaccess.MdGraphClassDAOIF) MdAttributeDAO(com.runwaysdk.dataaccess.metadata.MdAttributeDAO)

Example 3 with ServerGeoObjectTypeConverter

use of net.geoprism.registry.conversion.ServerGeoObjectTypeConverter in project geoprism-registry by terraframe.

the class PatchExistsAndInvalidInstanceData method patchInstanceData.

private void patchInstanceData() {
    List<Universal> unis = PatchExistsAndInvalid.getUniversals();
    int applied = 0;
    for (Universal uni : unis) {
        ServerGeoObjectType type = new ServerGeoObjectTypeConverter().build(uni);
        MdGraphClassDAOIF mdClass = type.getMdVertex();
        List<VertexServerGeoObject> data = getInstanceData(type, mdClass);
        int current = 0;
        final int size = data.size();
        logger.info("Starting to patch instance data for type [" + mdClass.getDBClassName() + "] with count [" + size + "] ");
        for (VertexServerGeoObject go : data) {
            ValueOverTime defaultExists = go.buildDefaultExists();
            if (defaultExists != null) {
                go.setValue(DefaultAttribute.EXISTS.getName(), Boolean.TRUE, defaultExists.getStartDate(), defaultExists.getEndDate());
                go.setValue(DefaultAttribute.INVALID.getName(), false);
                // This apply method is mega slow due to the SearchService so we're going to just bypass it
                // go.apply(false);
                go.getVertex().setValue(GeoVertex.LASTUPDATEDATE, new Date());
                go.getVertex().apply();
                applied++;
            }
            if (current % 100 == 0) {
                logger.info("Finished record " + current + " of " + size);
            }
            current++;
        }
    }
    logger.info("Applied " + applied + " records across " + unis.size() + " types.");
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) Universal(com.runwaysdk.system.gis.geo.Universal) ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdGraphClassDAOIF(com.runwaysdk.dataaccess.MdGraphClassDAOIF) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Date(java.util.Date)

Example 4 with ServerGeoObjectTypeConverter

use of net.geoprism.registry.conversion.ServerGeoObjectTypeConverter in project geoprism-registry by terraframe.

the class RegistryService method refreshMetadataCache.

public void refreshMetadataCache() {
    ServiceFactory.getMetadataCache().rebuild();
    QueryFactory qf = new QueryFactory();
    UniversalQuery uq = new UniversalQuery(qf);
    OIterator<? extends Universal> it = uq.getIterator();
    try {
        while (it.hasNext()) {
            Universal uni = it.next();
            if (uni.getKey().equals(Universal.ROOT_KEY)) {
                continue;
            }
            ServerGeoObjectType type = new ServerGeoObjectTypeConverter().build(uni);
            ServiceFactory.getMetadataCache().addGeoObjectType(type);
        }
    } finally {
        it.close();
    }
    // We must build the hierarchy types which are inherited first
    // Otherwise you will end up with a NPE when building the hierarchies
    // which inherit the inherited hierarchy if it hasn't been built
    HierarchicalRelationshipType.getInheritedTypes().forEach(relationship -> {
        ServerHierarchyType ht = new ServerHierarchyTypeBuilder().get(relationship, false);
        ServiceFactory.getMetadataCache().addHierarchyType(ht);
    });
    HierarchicalRelationshipType.getAll().forEach(relationship -> {
        ServerHierarchyType ht = new ServerHierarchyTypeBuilder().get(relationship, false);
        if (!ServiceFactory.getMetadataCache().getHierachyType(ht.getCode()).isPresent()) {
            ServiceFactory.getMetadataCache().addHierarchyType(ht);
        }
    });
    try {
        // This is, unfortunately, a big hack. Some patch items need to occur
        // before the organizaiton class is defined
        MdClassDAO.getMdClassDAO(Organization.CLASS);
        OrganizationQuery oQ = new OrganizationQuery(qf);
        OIterator<? extends Organization> it3 = oQ.getIterator();
        try {
            while (it3.hasNext()) {
                Organization organization = it3.next();
                ServiceFactory.getMetadataCache().addOrganization(organization);
            }
        } finally {
            it3.close();
        }
    } catch (com.runwaysdk.dataaccess.cache.DataNotFoundException e) {
    // skip for now
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) QueryFactory(com.runwaysdk.query.QueryFactory) Universal(com.runwaysdk.system.gis.geo.Universal) ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) Organization(net.geoprism.registry.Organization) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) OrganizationQuery(net.geoprism.registry.OrganizationQuery) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) UniversalQuery(com.runwaysdk.system.gis.geo.UniversalQuery)

Example 5 with ServerGeoObjectTypeConverter

use of net.geoprism.registry.conversion.ServerGeoObjectTypeConverter in project geoprism-registry by terraframe.

the class RegistryService method createGeoObjectType.

/**
 * Creates a {@link GeoObjectType} from the given JSON.
 *
 * @param sessionId
 * @param gtJSON
 *          JSON of the {@link GeoObjectType} to be created.
 * @return newly created {@link GeoObjectType}
 */
@Request(RequestType.SESSION)
public GeoObjectType createGeoObjectType(String sessionId, String gtJSON) {
    ServerGeoObjectType type = null;
    type = new ServerGeoObjectTypeConverter().create(gtJSON);
    ((Session) Session.getCurrentSession()).reloadPermissions();
    // If this did not error out then add to the cache
    ServiceFactory.getMetadataCache().addGeoObjectType(type);
    NotificationFacade.queue(new GlobalNotificationMessage(MessageType.TYPE_CACHE_CHANGE, null));
    return type.getType();
}
Also used : ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) Session(com.runwaysdk.session.Session) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Aggregations

ServerGeoObjectTypeConverter (net.geoprism.registry.conversion.ServerGeoObjectTypeConverter)11 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)9 Universal (com.runwaysdk.system.gis.geo.Universal)6 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)4 MdGraphClassDAOIF (com.runwaysdk.dataaccess.MdGraphClassDAOIF)3 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 RootGeoObjectType (net.geoprism.registry.model.RootGeoObjectType)2 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)2 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)1 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)1 MdAttributeBooleanDAO (com.runwaysdk.dataaccess.metadata.MdAttributeBooleanDAO)1 MdAttributeConcreteDAO (com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO)1 MdAttributeDAO (com.runwaysdk.dataaccess.metadata.MdAttributeDAO)1 MdAttributeEnumerationDAO (com.runwaysdk.dataaccess.metadata.MdAttributeEnumerationDAO)1 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)1 MdGeoVertexDAO (com.runwaysdk.gis.dataaccess.metadata.graph.MdGeoVertexDAO)1 QueryFactory (com.runwaysdk.query.QueryFactory)1 Request (com.runwaysdk.session.Request)1 Session (com.runwaysdk.session.Session)1 UniversalQuery (com.runwaysdk.system.gis.geo.UniversalQuery)1