use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.
the class UserDao method update.
@Override
public void update(User existing, User vo) {
// ensure passwords prefixed with {PLAINTEXT} are always hashed before database insertion/update
// we hash plain text passwords after validation has taken place so we can check complexity etc
vo.hashPlainText();
try {
User old = getTransactionTemplate().execute(status -> {
User old1 = get(vo.getId());
if (old1 == null) {
return null;
}
boolean passwordChanged = !old1.getPassword().equals(vo.getPassword());
if (passwordChanged) {
vo.setPasswordChangeTimestamp(Common.timer.currentTimeMillis());
vo.setPasswordVersion(old1.getPasswordVersion() + 1);
} else {
vo.setPasswordChangeTimestamp(old1.getPasswordChangeTimestamp());
vo.setPasswordVersion(old1.getPasswordVersion());
}
UserDao.super.update(old1, vo);
// Set the last login time so it is available on the saved user
vo.setLastLogin(old1.getLastLogin());
if (passwordChanged || vo.isDisabled()) {
expireSessionsForUser(old1);
}
return old1;
});
if (old == null) {
throw new NotFoundException();
}
} catch (DataIntegrityViolationException e) {
// Log some information about the user object.
LOG.error("Error updating user: " + vo, e);
throw e;
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class PublisherImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
PublisherVO vo = null;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
if (vo == null) {
String typeStr = json.getString("type");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.publisher.missingType", xid, ModuleRegistry.getPublisherDefinitionTypes());
else {
PublisherDefinition<?> def = ModuleRegistry.getPublisherDefinition(typeStr);
if (def == null)
addFailureMessage("emport.publisher.invalidType", xid, typeStr, ModuleRegistry.getPublisherDefinitionTypes());
else {
vo = def.baseCreatePublisherVO();
vo.setXid(xid);
}
}
}
if (vo != null) {
try {
// The VO was found or successfully created. Finish reading it in.
ctx.getReader().readInto(vo, json);
boolean isnew = vo.isNew();
if (Common.runtimeManager.getLifecycleState() == ILifecycleState.RUNNING) {
if (isnew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
addSuccessMessage(isnew, "emport.publisher.prefix", xid);
// Handle embedded points (pre Mango 4.3 this was the case)
JsonArray arr = json.getJsonArray("points");
if (arr != null) {
for (JsonValue jv : arr) {
String dataPointXid = jv.getJsonValue("dataPointId").toString();
try {
DataPointVO dataPointVO = dataPointService.get(dataPointXid);
PublishedPointVO point = vo.getDefinition().createPublishedPointVO(vo, dataPointVO);
point.setName(dataPointVO.getName());
ctx.getReader().readInto(point, jv.toJsonObject());
point.setXid(publishedPointService.generateUniqueXid());
publishedPointService.insert(point);
addSuccessMessage(isnew, "emport.publishedPoint.prefix", point.getXid());
} catch (NotFoundException e) {
addFailureMessage("emport.publisher.prefix", xid, new TranslatableMessage("emport.error.missingPoint", dataPointXid));
} catch (ValidationException e) {
for (ProcessMessage m : e.getValidationResult().getMessages()) {
addFailureMessage(new ProcessMessage("emport.publisher.prefix", new TranslatableMessage("literal", xid), m));
}
}
}
}
} else {
addFailureMessage("emport.publisher.runtimeManagerNotRunning", xid);
}
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.publisher.prefix", xid);
} catch (TranslatableJsonException e) {
addFailureMessage("emport.publisher.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.publisher.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class RoleImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
String name = json.getString("name");
RoleVO vo = null;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
if (vo == null) {
vo = new RoleVO(Common.NEW_ID, xid, name);
}
try {
// Read into the VO to get all properties
ctx.getReader().readInto(vo, json);
boolean isnew = vo.getId() == Common.NEW_ID;
if (isnew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
addSuccessMessage(isnew, "emport.role.prefix", xid);
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.role.prefix", xid);
} catch (JsonException e) {
addFailureMessage("emport.role.prefix", xid, getJsonExceptionMessage(e));
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class EventHandlerImporter method importImpl.
@Override
protected void importImpl() {
AbstractEventHandlerVO handler = null;
String xid = json.getString("xid");
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
handler = service.get(xid);
} catch (NotFoundException e) {
// Nothing, done below
}
}
if (handler == null) {
String typeStr = json.getString("handlerType");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.eventHandler.missingType", xid, ModuleRegistry.getEventHandlerDefinitionTypes());
else {
EventHandlerDefinition<?> def = ModuleRegistry.getEventHandlerDefinition(typeStr);
if (def == null)
addFailureMessage("emport.eventHandler.invalidType", xid, typeStr, ModuleRegistry.getEventHandlerDefinitionTypes());
else {
handler = def.baseCreateEventHandlerVO();
handler.setXid(xid);
}
}
}
JsonObject et = json.getJsonObject("eventType");
JsonArray ets = json.getJsonArray("eventTypes");
if (handler != null) {
try {
ctx.getReader().readInto(handler, json);
Set<EventTypeMatcher> eventTypes = new HashSet<>(handler.getEventTypes());
// Find the event type.
if (et != null) {
eventTypes.add(new EventTypeMatcher(ctx.getReader().read(EventType.class, et)));
} else if (ets != null) {
for (JsonValue jsonValue : ets) {
eventTypes.add(new EventTypeMatcher(ctx.getReader().read(EventType.class, jsonValue)));
}
}
handler.setEventTypes(new ArrayList<>(eventTypes));
boolean isnew = handler.getId() == Common.NEW_ID;
if (isnew) {
service.insert(handler);
addSuccessMessage(true, "emport.eventHandler.prefix", xid);
} else {
service.update(handler.getId(), handler);
addSuccessMessage(false, "emport.eventHandler.prefix", xid);
}
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.eventHandler.prefix", xid);
} catch (TranslatableJsonException e) {
addFailureMessage("emport.eventHandler.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.eventHandler.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by MangoAutomation.
the class JsonDataImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
JsonDataVO vo = null;
boolean isNew = false;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
if (vo == null) {
isNew = true;
vo = new JsonDataVO();
vo.setXid(xid);
}
if (vo != null) {
try {
// The VO was found or successfully created. Finish reading it in.
ctx.getReader().readInto(vo, json);
// Ensure we have a default permission since null is valid in Mango 3.x
if (vo.getReadPermission() == null) {
vo.setReadPermission(new MangoPermission());
}
if (vo.getEditPermission() == null) {
vo.setEditPermission(new MangoPermission());
}
if (isNew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
addSuccessMessage(isNew, "emport.jsondata.prefix", xid);
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.jsondata.prefix", xid);
} catch (TranslatableJsonException e) {
addFailureMessage("emport.jsondata.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.jsondata.prefix", xid, getJsonExceptionMessage(e));
}
}
}
Aggregations