Search in sources :

Example 66 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.

the class IntervalListType method createEntries.

@Override
@Transaction
public void createEntries(JsonObject metadata) {
    if (!this.isValid()) {
        throw new InvalidMasterListException();
    }
    if (metadata == null) {
        List<ListTypeEntry> entries = this.getEntries();
        if (entries.size() > 0) {
            ListTypeEntry entry = entries.get(0);
            ListTypeVersion working = entry.getWorking();
            metadata = working.toJSON(false);
        }
    }
    final JsonObject object = metadata;
    this.getIntervals().forEach((pair) -> {
        Date startDate = pair.getFirst();
        this.getOrCreateEntry(startDate, object);
    });
}
Also used : JsonObject(com.google.gson.JsonObject) Date(java.util.Date) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 67 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.

the class ListType method getOrCreateEntry.

@Transaction
public ListTypeEntry getOrCreateEntry(Date forDate, JsonObject metadata) {
    if (!this.isValid()) {
        throw new InvalidMasterListException();
    }
    ListTypeEntryQuery query = new ListTypeEntryQuery(new QueryFactory());
    query.WHERE(query.getListType().EQ(this));
    query.AND(query.getForDate().EQ(forDate));
    try (OIterator<? extends ListTypeEntry> it = query.getIterator()) {
        if (it.hasNext()) {
            return it.next();
        }
    }
    return ListTypeEntry.create(this, forDate, metadata);
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 68 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.

the class ListType method delete.

@Override
@Transaction
public void delete() {
    // Validate there are no public versions
    ListTypeVersionQuery query = new ListTypeVersionQuery(new QueryFactory());
    query.WHERE(query.getListType().EQ(this));
    query.AND(query.getWorking().EQ(false));
    query.AND(OR.get(query.getListVisibility().EQ(ListType.PUBLIC), query.getGeospatialVisibility().EQ(ListType.PUBLIC)));
    long count = query.getCount();
    if (count > 0) {
        throw new CannotDeletePublicListTypeException();
    }
    // Delete all jobs
    this.getJobs().forEach(job -> {
        job.delete();
    });
    this.getEntries().forEach(entry -> {
        entry.delete();
    });
    super.delete();
    final File directory = this.getShapefileDirectory();
    if (directory.exists()) {
        try {
            FileUtils.deleteDirectory(directory);
        } catch (IOException e) {
            throw new ProgrammingErrorException(e);
        }
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) IOException(java.io.IOException) File(java.io.File) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 69 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction 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 70 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.

the class MasterList method create.

@Transaction
public static MasterList create(JsonObject object) {
    MasterList list = MasterList.fromJSON(object);
    if (Session.getCurrentSession() != null && Session.getCurrentSession().getUser() != null) {
        list.enforceActorHasPermission(Operation.CREATE);
    }
    if (list.getIsMaster() != null && list.getIsMaster()) {
        Universal universal = list.getUniversal();
        MasterListQuery query = new MasterListQuery(new QueryFactory());
        query.WHERE(query.getUniversal().EQ(universal));
        query.AND(query.getOrganization().EQ(list.getOrganization()));
        query.AND(query.getIsMaster().EQ(true));
        if (!list.isNew()) {
            query.AND(query.getOid().NE(list.getOid()));
        }
        if (query.getCount() > 0) {
            DuplicateMasterListException ex = new DuplicateMasterListException();
            ex.setGeoObjectType(universal.getDisplayLabel().getValue());
            throw ex;
        }
    }
    list.apply();
    return list;
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) QueryFactory(com.runwaysdk.query.QueryFactory) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

Transaction (com.runwaysdk.dataaccess.transaction.Transaction)131 QueryFactory (com.runwaysdk.query.QueryFactory)29 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)27 JsonObject (com.google.gson.JsonObject)17 Date (java.util.Date)15 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)15 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)14 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)13 LinkedList (java.util.LinkedList)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)10 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)10 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)10 List (java.util.List)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 VertexObject (com.runwaysdk.business.graph.VertexObject)8 IOException (java.io.IOException)8 GeoObjectImportConfiguration (net.geoprism.registry.io.GeoObjectImportConfiguration)8 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)8 JSONObject (org.json.JSONObject)8