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;
}
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();
}
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());
}
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);
}
}
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();
}
}
Aggregations