use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-modules-public by infiniteautomation.
the class AsciiFileEditDwr method testString.
@DwrPermission(user = true)
public ProcessResult testString(int dsId, String raw) {
final ProcessResult pr = new ProcessResult();
// Message we will work with
String msg;
if (dsId == -1) {
pr.addContextualMessage("testString", "dsEdit.file.test.needsSave");
return pr;
}
msg = StringEscapeUtils.unescapeJava(raw);
// Map to store the values vs the points they are for
final List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
pr.addData("results", results);
DataPointDao dpd = DataPointDao.instance;
List<DataPointVO> points = dpd.getDataPoints(dsId, null);
for (final DataPointVO vo : points) {
final Map<String, Object> result = new HashMap<String, Object>();
MatchCallback callback = new MatchCallback() {
@Override
public void onMatch(String pointIdentifier, PointValueTime value) {
result.put("success", "true");
result.put("name", vo.getName());
result.put("identifier", pointIdentifier);
result.put("value", value != null ? value.toString() : "null");
}
@Override
public void pointPatternMismatch(String message, String pointValueRegex) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("dsEdit.file.test.noPointRegexMatch").translate(Common.getTranslations()));
}
@Override
public void messagePatternMismatch(String message, String messageRegex) {
}
@Override
public void pointNotIdentified(String message, String messageRegex, int pointIdentifierIndex) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("dsEdit.file.test.noIdentifierFound").translate(Common.getTranslations()));
}
@Override
public void matchGeneralFailure(Exception e) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("common.default", e.getMessage()).translate(Common.getTranslations()));
}
};
AsciiFilePointLocatorVO locator = vo.getPointLocator();
AsciiFileDataSourceRT.matchPointValueTime(msg, Pattern.compile(locator.getValueRegex()), locator.getPointIdentifier(), locator.getPointIdentifierIndex(), locator.getDataTypeId(), locator.getValueIndex(), locator.getHasTimestamp(), locator.getTimestampIndex(), locator.getTimestampFormat(), callback);
if (result.size() > 0) {
results.add(result);
}
}
return pr;
}
use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class ChartExportServlet method exportExcel.
/**
* Do the export as Excel XLSX File
* @param response
* @param from
* @param to
* @param def
* @param user
* @throws IOException
*/
private void exportExcel(HttpServletResponse response, long from, long to, DataExportDefinition def, User user) throws IOException {
DataPointDao dataPointDao = DataPointDao.instance;
PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
// Stream the content.
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
final List<PointValueEmporter> sheetEmporters = new ArrayList<PointValueEmporter>();
final AtomicInteger sheetIndex = new AtomicInteger();
sheetEmporters.add(new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get()));
final SpreadsheetEmporter emporter = new SpreadsheetEmporter(FileType.XLSX);
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
emporter.prepareExport(bos);
emporter.prepareSheetExport(sheetEmporters.get(0));
final ExportDataValue edv = new ExportDataValue();
MappedRowCallback<PointValueTime> callback = new MappedRowCallback<PointValueTime>() {
@Override
public void row(PointValueTime pvt, int rowIndex) {
edv.setValue(pvt.getValue());
edv.setTime(pvt.getTime());
if (pvt instanceof AnnotatedPointValueTime)
edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
else
edv.setAnnotation(null);
sheetEmporters.get(sheetIndex.get()).exportRow(edv);
if (sheetEmporters.get(sheetIndex.get()).getRowsAdded() >= emporter.getMaxRowsPerSheet()) {
ExportPointInfo info = sheetEmporters.get(sheetIndex.get()).getPointInfo();
sheetIndex.incrementAndGet();
PointValueEmporter sheetEmporter = new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get());
sheetEmporter.setPointInfo(info);
sheetEmporters.add(sheetEmporter);
emporter.prepareSheetExport(sheetEmporters.get(sheetIndex.get()));
}
}
};
for (int pointId : def.getPointIds()) {
DataPointVO dp = dataPointDao.getDataPoint(pointId, false);
if (Permissions.hasDataPointReadPermission(user, dp)) {
ExportPointInfo pointInfo = new ExportPointInfo();
pointInfo.setXid(dp.getXid());
pointInfo.setPointName(dp.getName());
pointInfo.setDeviceName(dp.getDeviceName());
pointInfo.setTextRenderer(dp.getTextRenderer());
sheetEmporters.get(sheetIndex.get()).setPointInfo(pointInfo);
pointValueDao.getPointValuesBetween(pointId, from, to, callback);
}
}
emporter.finishExport();
}
use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class EventHandlerVO method jsonWrite.
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
DataPointDao dataPointDao = DataPointDao.instance;
writer.writeEntry("xid", xid);
writer.writeEntry("handlerType", TYPE_CODES.getCode(handlerType));
if (handlerType == TYPE_SET_POINT) {
String dpXid = dataPointDao.getXidById(targetPointId);
writer.writeEntry("targetPointId", dpXid);
// Active
writer.writeEntry("activeAction", SET_ACTION_CODES.getCode(activeAction));
if (activeAction == SET_ACTION_POINT_VALUE) {
dpXid = dataPointDao.getXidById(activePointId);
writer.writeEntry("activePointId", dpXid);
} else if (activeAction == SET_ACTION_STATIC_VALUE)
writer.writeEntry("activeValueToSet", activeValueToSet);
// Inactive
writer.writeEntry("inactiveAction", SET_ACTION_CODES.getCode(inactiveAction));
if (inactiveAction == SET_ACTION_POINT_VALUE) {
dpXid = dataPointDao.getXidById(inactivePointId);
writer.writeEntry("inactivePointId", dpXid);
} else if (inactiveAction == SET_ACTION_STATIC_VALUE)
writer.writeEntry("inactiveValueToSet", inactiveValueToSet);
} else if (handlerType == TYPE_EMAIL) {
writer.writeEntry("activeRecipients", activeRecipients);
writer.writeEntry("sendEscalation", sendEscalation);
if (sendEscalation) {
writer.writeEntry("escalationDelayType", Common.TIME_PERIOD_CODES.getCode(escalationDelayType));
writer.writeEntry("escalationDelay", escalationDelay);
writer.writeEntry("escalationRecipients", escalationRecipients);
}
writer.writeEntry("sendInactive", sendInactive);
if (sendInactive) {
writer.writeEntry("inactiveOverride", inactiveOverride);
if (inactiveOverride)
writer.writeEntry("inactiveRecipients", inactiveRecipients);
}
writer.writeEntry("includeSystemInformation", includeSystemInfo);
writer.writeEntry("includePointValueCount", includePointValueCount);
writer.writeEntry("includeLogfile", includeLogfile);
} else if (handlerType == TYPE_PROCESS) {
writer.writeEntry("activeProcessCommand", activeProcessCommand);
writer.writeEntry("activeProcessTimeout", activeProcessTimeout);
writer.writeEntry("inactiveProcessCommand", inactiveProcessCommand);
writer.writeEntry("inactiveProcessTimeout", inactiveProcessTimeout);
}
}
use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class PointFolder method jsonWrite.
//
//
// Serialization
//
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
DataPointDao dataPointDao = DataPointDao.instance;
List<String> pointList = new ArrayList<String>();
for (DataPointSummary p : points) {
String dpXid = dataPointDao.getXidById(p.getId());
if (dpXid != null)
pointList.add(dpXid);
}
writer.writeEntry("points", pointList);
}
use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.
the class DataPointDetailsController method handleRequest.
@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
User user = Common.getHttpUser();
int id = -1;
if (user.getEditPoint() != null)
id = user.getEditPoint().getId();
DataPointDao dataPointDao = DataPointDao.instance;
String idStr = request.getParameter("dpid");
DataPointVO point = null;
if (StringUtils.equals(idStr, "exception"))
throw new IOException("testing");
else if (StringUtils.equals(idStr, "permission-exception"))
throw new PermissionException(new TranslatableMessage("common.default", "Testing"), user);
if (StringUtils.isBlank(idStr)) {
// Check for pedid (point event detector id)
String pedStr = request.getParameter("pedid");
if (StringUtils.isBlank(pedStr)) {
// Check if an XID was provided.
String xid = request.getParameter("dpxid");
if (!StringUtils.isBlank(xid)) {
model.put("currentXid", xid);
point = dataPointDao.getDataPoint(xid);
id = point == null ? -2 : point.getId();
}
} else {
int pedid = Integer.parseInt(pedStr);
id = EventDetectorDao.instance.getSourceId(pedid, EventType.EventTypeNames.DATA_POINT);
}
} else
id = Integer.parseInt(idStr);
// Find accessible points for the goto list
List<DataPointSummary> userPoints = ControllerUtils.addPointListDataToModel(user, id, model);
// Get the point.
if (point == null && id != -1)
point = dataPointDao.getDataPoint(id);
if (point == null && id != -2 && /* -2 means an explicit XID was provided but not found */
!userPoints.isEmpty()) {
// Load at least 1 point, there may be many points but some might not actually load if thier data source DNE anymore
for (DataPointSummary userPoint : userPoints) {
point = dataPointDao.getDataPoint(userPoint.getId());
if (point != null)
break;
}
}
if (point != null) {
// Check permissions
Permissions.ensureDataPointReadPermission(user, point);
// Put the point in the model.
model.put("point", point);
// Get the users that have access to this point.
List<User> allUsers = UserDao.instance.getUsers();
List<Map<String, Object>> users = new LinkedList<>();
Map<String, Object> userData;
int accessType;
for (User mangoUser : allUsers) {
accessType = Permissions.getDataPointAccessType(mangoUser, point);
if (accessType != Permissions.DataPointAccessTypes.NONE) {
userData = new HashMap<>();
userData.put("user", mangoUser);
userData.put("accessType", accessType);
users.add(userData);
}
}
model.put("users", users);
// Determine whether the link to edit the point should be displayed
model.put("pointEditor", Permissions.hasDataSourcePermission(user, point.getDataSourceId()));
// Put the events in the model.
model.put("events", EventDao.instance.getEventsForDataPoint(id, user.getId()));
// Put the default history table count into the model. Default to 10.
int historyLimit = 10;
if (point.getChartRenderer() instanceof TableChartRenderer)
historyLimit = ((TableChartRenderer) point.getChartRenderer()).getLimit();
else if (point.getChartRenderer() instanceof ImageFlipbookRenderer)
historyLimit = ((ImageFlipbookRenderer) point.getChartRenderer()).getLimit();
model.put("historyLimit", historyLimit);
// Determine our image chart rendering capabilities.
if (ImageChartRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId())) {
// This point can render an image chart. Carry on...
int periodType = Common.TimePeriods.DAYS;
int periodCount = 1;
if (point.getChartRenderer() instanceof ImageChartRenderer) {
ImageChartRenderer r = (ImageChartRenderer) point.getChartRenderer();
periodType = r.getTimePeriod();
periodCount = r.getNumberOfPeriods();
}
model.put("periodType", periodType);
model.put("periodCount", periodCount);
}
// Determine out flipbook rendering capabilities
if (ImageFlipbookRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId()))
model.put("flipbookLimit", 10);
// Set the point in the session for the dwr.
user.setEditPoint(point);
model.put("currentXid", point.getXid());
model.put("hierPath", CollectionUtils.implode(dataPointDao.getPointHierarchy(true).getPath(id), " » "));
}
return null;
}
Aggregations