use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventDao in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method getMaintenanceEvent.
@DwrPermission(admin = true)
public ProcessResult getMaintenanceEvent(int id) {
ProcessResult response = new ProcessResult();
MaintenanceEventVO me;
boolean activated = false;
if (id == Common.NEW_ID) {
DateTime dt = new DateTime();
me = new MaintenanceEventVO();
me.setXid(new MaintenanceEventDao().generateUniqueXid());
me.setActiveYear(dt.getYear());
me.setInactiveYear(dt.getYear());
me.setActiveMonth(dt.getMonthOfYear());
me.setInactiveMonth(dt.getMonthOfYear());
} else {
me = new MaintenanceEventDao().getMaintenanceEvent(id);
MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(me.getId());
if (rt != null)
activated = rt.isEventActive();
}
response.addData("me", me);
response.addData("activated", activated);
return response;
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventDao in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method getMaintenanceEvents.
@DwrPermission(admin = true)
public ProcessResult getMaintenanceEvents() {
ProcessResult response = new ProcessResult();
final Translations translations = getTranslations();
List<MaintenanceEventVO> events = new MaintenanceEventDao().getMaintenanceEvents();
Collections.sort(events, new Comparator<MaintenanceEventVO>() {
@Override
public int compare(MaintenanceEventVO m1, MaintenanceEventVO m2) {
return m1.getDescription().translate(translations).compareTo(m1.getDescription().translate(translations));
}
});
response.addData(MODEL_ATTR_EVENTS, events);
List<IntStringPair> dataSources = new ArrayList<IntStringPair>();
for (DataSourceVO<?> ds : DataSourceDao.instance.getDataSources()) dataSources.add(new IntStringPair(ds.getId(), ds.getName()));
response.addData("dataSources", dataSources);
return response;
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventDao in project ma-modules-public by infiniteautomation.
the class MaintenanceEventEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
MaintenanceEventDao maintenanceEventDao = new MaintenanceEventDao();
JsonObject maintenanceEvent = jsonValue.toJsonObject();
String xid = maintenanceEvent.getString("xid");
if (StringUtils.isBlank(xid))
xid = maintenanceEventDao.generateUniqueXid();
MaintenanceEventVO vo = maintenanceEventDao.getMaintenanceEvent(xid);
if (vo == null) {
vo = new MaintenanceEventVO();
vo.setXid(xid);
}
try {
importContext.getReader().readInto(vo, maintenanceEvent);
// Now validate it. Use a new response object so we can distinguish errors in this vo from other errors.
ProcessResult voResponse = new ProcessResult();
vo.validate(voResponse);
if (voResponse.getHasMessages())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(voResponse, "emport.maintenanceEvent.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.isNew();
RTMDefinition.instance.saveMaintenanceEvent(vo);
importContext.addSuccessMessage(isnew, "emport.maintenanceEvent.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventDao in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method saveMaintenanceEvent.
@DwrPermission(admin = true)
public ProcessResult saveMaintenanceEvent(int id, String xid, int dataSourceId, String alias, int alarmLevel, int scheduleType, boolean disabled, int activeYear, int activeMonth, int activeDay, int activeHour, int activeMinute, int activeSecond, String activeCron, int inactiveYear, int inactiveMonth, int inactiveDay, int inactiveHour, int inactiveMinute, int inactiveSecond, String inactiveCron) {
MaintenanceEventVO e = new MaintenanceEventVO();
e.setId(id);
e.setXid(xid);
e.setDataSourceId(dataSourceId);
e.setAlias(alias);
e.setAlarmLevel(alarmLevel);
e.setScheduleType(scheduleType);
e.setDisabled(disabled);
e.setActiveYear(activeYear);
e.setActiveMonth(activeMonth);
e.setActiveDay(activeDay);
e.setActiveHour(activeHour);
e.setActiveMinute(activeMinute);
e.setActiveSecond(activeSecond);
e.setActiveCron(activeCron);
e.setInactiveYear(inactiveYear);
e.setInactiveMonth(inactiveMonth);
e.setInactiveDay(inactiveDay);
e.setInactiveHour(inactiveHour);
e.setInactiveMinute(inactiveMinute);
e.setInactiveSecond(inactiveSecond);
e.setInactiveCron(inactiveCron);
ProcessResult response = new ProcessResult();
MaintenanceEventDao maintenanceEventDao = new MaintenanceEventDao();
if (StringUtils.isBlank(xid))
response.addContextualMessage("xid", "validate.required");
else if (!maintenanceEventDao.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");
e.validate(response);
// Save the maintenance event
if (!response.getHasMessages()) {
RTMDefinition.instance.saveMaintenanceEvent(e);
response.addData("meId", e.getId());
}
return response;
}
Aggregations