Search in sources :

Example 86 with Transaction

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

the class DataExportJob method startInTrans.

@Transaction
private JobHistoryRecord startInTrans(SynchronizationConfig configuration) {
    ExportHistory history = (ExportHistory) this.createNewHistory();
    JobHistoryRecord record = new JobHistoryRecord(this, history);
    record.apply();
    return record;
}
Also used : JobHistoryRecord(com.runwaysdk.system.scheduler.JobHistoryRecord) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 87 with Transaction

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

the class ExternalSystem method apply.

@Override
@Transaction
public void apply() {
    Organization organization = this.getOrganization();
    if (organization != null) {
        SessionIF session = Session.getCurrentSession();
        if (session != null) {
            ServiceFactory.getRolePermissionService().enforceRA(organization.getCode());
        }
    }
    super.apply();
}
Also used : Organization(net.geoprism.registry.Organization) SessionIF(com.runwaysdk.session.SessionIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 88 with Transaction

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

the class Transition method removeAll.

@Transaction
public static void removeAll(ServerGeoObjectType type) {
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(Transition.CLASS);
    MdAttributeDAOIF sourceAttribute = mdVertex.definesAttribute(Transition.SOURCE);
    MdAttributeDAOIF targetAttribute = mdVertex.definesAttribute(Transition.TARGET);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    statement.append(" WHERE " + sourceAttribute.getColumnName() + ".@class = :vertexClass");
    statement.append(" OR " + targetAttribute.getColumnName() + ".@class = :vertexClass");
    GraphQuery<Transition> query = new GraphQuery<Transition>(statement.toString());
    query.setParameter("vertexClass", type.getMdVertex().getDBClassName());
    List<Transition> results = query.getResults();
    results.forEach(event -> event.delete());
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) GraphQuery(com.runwaysdk.business.graph.GraphQuery) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 89 with Transaction

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

the class TransitionEvent method apply.

@Transaction
public static JsonObject apply(JsonObject json) {
    try {
        String beforeTypeCode = json.get(TransitionEvent.BEFORETYPECODE).getAsString();
        String afterTypeCode = json.get(TransitionEvent.AFTERTYPECODE).getAsString();
        ServerGeoObjectType beforeType = ServerGeoObjectType.get(beforeTypeCode);
        ServerGeoObjectType afterType = ServerGeoObjectType.get(afterTypeCode);
        ServiceFactory.getGeoObjectPermissionService().enforceCanWrite(beforeType.getOrganization().getCode(), beforeType);
        // ServiceFactory.getGeoObjectPermissionService().enforceCanWrite(afterType.getOrganization().getCode(),
        // afterType);
        DateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
        format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
        LocalizedValue description = LocalizedValue.fromJSON(json.get(TransitionEvent.DESCRIPTION).getAsJsonObject());
        TransitionEvent event = json.has(OID) ? TransitionEvent.get(json.get(OID).getAsString()) : new TransitionEvent();
        LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, description);
        event.setEventDate(format.parse(json.get(TransitionEvent.EVENTDATE).getAsString()));
        event.setBeforeTypeCode(beforeTypeCode);
        event.setAfterTypeCode(afterTypeCode);
        event.setBeforeTypeOrgCode(beforeType.getOrganization().getCode());
        event.setAfterTypeOrgCode(afterType.getOrganization().getCode());
        event.apply();
        JsonArray transitions = json.get("transitions").getAsJsonArray();
        List<String> appliedTrans = new ArrayList<String>();
        for (int i = 0; i < transitions.size(); i++) {
            JsonObject object = transitions.get(i).getAsJsonObject();
            Transition trans = Transition.apply(event, i, object);
            appliedTrans.add(trans.getOid());
        }
        for (Transition trans : event.getTransitions()) {
            if (!appliedTrans.contains(trans.getOid())) {
                trans.delete();
            }
        }
        return event.toJSON(false);
    } catch (ParseException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 90 with Transaction

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

the class RegistrySessionService method getActor.

@Transaction
private static synchronized SingleActorDAOIF getActor(OauthServer server, String username) throws JSONException {
    UsersQuery query = new UsersQuery(new QueryFactory());
    query.WHERE(query.getUsername().EQ(username));
    OIterator<? extends Users> it = query.getIterator();
    try {
        if (it.hasNext()) {
            UserDAO user = (UserDAO) BusinessFacade.getEntityDAO(it.next());
            try {
                GeoprismUser geoprismUser = GeoprismUser.getByUsername(user.getUsername());
                UserInfo userInfo = UserInfo.getByUser(geoprismUser);
                ExternalSystem system = ExternalSystem.get(userInfo.getExternalSystemOid());
                if (system instanceof DHIS2ExternalSystem) {
                    DHIS2ExternalSystem dhis2System = (DHIS2ExternalSystem) system;
                    if (dhis2System.getOauthServerOid().equals(server.getOid())) {
                        return user;
                    }
                }
            } catch (Throwable t) {
                logger.error("Encountered an unexpected error while logging user in.", t);
            }
            UserNotOuathEnabledException ex = new UserNotOuathEnabledException();
            ex.setUsername(user.getUsername());
            ex.setOauthServer(server.getDisplayLabel().getValue());
            throw ex;
        } else {
            UserNotFoundException ex = new UserNotFoundException();
            ex.setUsername(username);
            throw ex;
        }
    } finally {
        it.close();
    }
}
Also used : UserNotFoundException(net.geoprism.registry.session.UserNotFoundException) UserNotOuathEnabledException(net.geoprism.registry.session.UserNotOuathEnabledException) QueryFactory(com.runwaysdk.query.QueryFactory) UserDAO(com.runwaysdk.business.rbac.UserDAO) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) UsersQuery(com.runwaysdk.system.UsersQuery) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) GeoprismUser(net.geoprism.GeoprismUser) UserInfo(net.geoprism.registry.UserInfo) 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