use of com.ibm.j9ddr.vm29.j9.DataType in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerDefinition method commonValidation.
private void commonValidation(ProcessResult response, SetPointEventHandlerVO vo) {
DataPointVO dp = DataPointDao.getInstance().get(vo.getTargetPointId());
DataType dataType = null;
if (dp == null)
response.addContextualMessage("targetPointId", "eventHandlers.noTargetPoint");
else {
dataType = dp.getPointLocator().getDataType();
if (!dp.getPointLocator().isSettable())
response.addContextualMessage("targetPointId", "event.setPoint.targetNotSettable");
}
if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_NONE && vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_NONE) {
response.addContextualMessage("activeAction", "eventHandlers.noSetPointAction");
response.addContextualMessage("inactiveAction", "eventHandlers.noSetPointAction");
}
MangoJavaScriptService javaScriptService = Common.getBean(MangoJavaScriptService.class);
// Active
if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE && dataType == DataType.MULTISTATE) {
try {
Integer.parseInt(vo.getActiveValueToSet());
} catch (NumberFormatException e) {
response.addContextualMessage("activeValueToSet", "eventHandlers.invalidActiveValue");
}
} else if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE && dataType == DataType.NUMERIC) {
try {
Double.parseDouble(vo.getActiveValueToSet());
} catch (NumberFormatException e) {
response.addContextualMessage("activeValueToSet", "eventHandlers.invalidActiveValue");
}
} else if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE) {
DataPointVO dpActive = DataPointDao.getInstance().get(vo.getActivePointId());
if (dpActive == null)
response.addContextualMessage("activePointId", "eventHandlers.invalidActiveSource");
else if (dataType != dpActive.getPointLocator().getDataType())
response.addContextualMessage("activeDataPointId", "eventHandlers.invalidActiveSourceType");
} else if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_SCRIPT_VALUE) {
if (StringUtils.isEmpty(vo.getActiveScript())) {
response.addContextualMessage("activeScript", "eventHandlers.invalidActiveScript");
} else {
try {
javaScriptService.compile(vo.getActiveScript(), true);
} catch (ScriptError e) {
response.addContextualMessage("activeScript", "eventHandlers.invalidActiveScriptError", e.getTranslatableMessage());
}
}
}
// Inactive
if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE && dataType == DataType.MULTISTATE) {
try {
Integer.parseInt(vo.getInactiveValueToSet());
} catch (NumberFormatException e) {
response.addContextualMessage("inactiveValueToSet", "eventHandlers.invalidInactiveValue");
}
} else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE && dataType == DataType.NUMERIC) {
try {
Double.parseDouble(vo.getInactiveValueToSet());
} catch (NumberFormatException e) {
response.addContextualMessage("inactiveValueToSet", "eventHandlers.invalidInactiveValue");
}
} else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE) {
DataPointVO dpInactive = DataPointDao.getInstance().get(vo.getInactivePointId());
if (dpInactive == null)
response.addContextualMessage("inactivePointId", "eventHandlers.invalidInactiveSource");
else if (dataType != dpInactive.getPointLocator().getDataType())
response.addContextualMessage("inactivePointId", "eventHandlers.invalidInactiveSourceType");
} else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_SCRIPT_VALUE) {
if (StringUtils.isEmpty(vo.getInactiveScript())) {
response.addContextualMessage("inactiveScript", "eventHandlers.invalidInactiveScript");
} else {
try {
javaScriptService.compile(vo.getInactiveScript(), true);
} catch (ScriptError e) {
response.addContextualMessage("inactiveScript", "eventHandlers.invalidActiveScriptError", e.getTranslatableMessage());
}
}
}
if (vo.getAdditionalContext() != null)
validateScriptContext(vo.getAdditionalContext(), response);
else
vo.setAdditionalContext(new ArrayList<>());
}
use of com.ibm.j9ddr.vm29.j9.DataType in project openj9 by eclipse-openj9.
the class StructurePointer method getStructureFields.
public StructureField[] getStructureFields() {
List<StructureField> fields = new LinkedList<StructureField>();
Class<?> working = this.getClass();
while (working != null) {
GeneratedPointerClass classAnnotation = working.getAnnotation(GeneratedPointerClass.class);
if (null == classAnnotation) {
break;
}
for (Method thisMethod : working.getMethods()) {
if (thisMethod.isAnnotationPresent(GeneratedFieldAccessor.class)) {
GeneratedFieldAccessor fieldAnnotation = thisMethod.getAnnotation(GeneratedFieldAccessor.class);
Field offsetField = null;
try {
offsetField = classAnnotation.structureClass().getField(fieldAnnotation.offsetFieldName());
} catch (SecurityException e) {
throw new Error("Unexpected security exception", e);
} catch (NoSuchFieldException e) {
// This will happen if we reach for a field that doesn't exist on this level
continue;
}
int offset = -1;
try {
offset = offsetField.getInt(null);
} catch (Exception e) {
throw new Error(e);
}
DataType result = null;
CorruptDataException cde = null;
try {
result = (DataType) thisMethod.invoke(this);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof CorruptDataException) {
cde = (CorruptDataException) cause;
} else {
throw new RuntimeException(e);
}
}
fields.add(new StructureField(thisMethod.getName(), fieldAnnotation.declaredType(), offset, result, cde));
}
}
working = working.getSuperclass();
}
Collections.sort(fields);
StructureField[] result = new StructureField[fields.size()];
fields.toArray(result);
return result;
}
use of com.ibm.j9ddr.vm29.j9.DataType in project openj9 by eclipse.
the class StructurePointer method getStructureFields.
public StructureField[] getStructureFields() {
List<StructureField> fields = new LinkedList<StructureField>();
Class<?> working = this.getClass();
while (working != null) {
GeneratedPointerClass classAnnotation = working.getAnnotation(GeneratedPointerClass.class);
if (null == classAnnotation) {
break;
}
for (Method thisMethod : working.getMethods()) {
if (thisMethod.isAnnotationPresent(GeneratedFieldAccessor.class)) {
GeneratedFieldAccessor fieldAnnotation = thisMethod.getAnnotation(GeneratedFieldAccessor.class);
Field offsetField = null;
try {
offsetField = classAnnotation.structureClass().getField(fieldAnnotation.offsetFieldName());
} catch (SecurityException e) {
throw new Error("Unexpected security exception", e);
} catch (NoSuchFieldException e) {
// This will happen if we reach for a field that doesn't exist on this level
continue;
}
int offset = -1;
try {
offset = offsetField.getInt(null);
} catch (Exception e) {
throw new Error(e);
}
DataType result = null;
CorruptDataException cde = null;
try {
result = (DataType) thisMethod.invoke(this);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof CorruptDataException) {
cde = (CorruptDataException) cause;
} else {
throw new RuntimeException(e);
}
}
fields.add(new StructureField(thisMethod.getName(), fieldAnnotation.declaredType(), offset, result, cde));
}
}
working = working.getSuperclass();
}
Collections.sort(fields);
StructureField[] result = new StructureField[fields.size()];
fields.toArray(result);
return result;
}
use of com.ibm.j9ddr.vm29.j9.DataType in project imageio-ext by geosolutions-it.
the class NetCDFUtilities method isVariableAccepted.
/**
* NetCDF files may contains a wide set of variables. Some of them are
* unuseful for our purposes. The method returns {@code true} if the
* specified variable is accepted.
*/
public static boolean isVariableAccepted(final Variable var, final CheckType checkType) {
if (var instanceof CoordinateAxis1D) {
return false;
} else if (checkType == CheckType.NOSCALARS) {
List<Dimension> dimensions = var.getDimensions();
if (dimensions.size() < 2) {
return false;
}
DataType dataType = var.getDataType();
if (dataType == DataType.CHAR) {
return false;
}
return isVariableAccepted(var.getName(), CheckType.NONE);
} else if (checkType == CheckType.ONLYGEOGRIDS) {
List<Dimension> dimensions = var.getDimensions();
if (dimensions.size() < 2) {
return false;
}
for (Dimension dimension : dimensions) {
String dimName = dimension.getName();
// check the dimension to be defined
Group group = dimension.getGroup();
Variable dimVariable = group.findVariable(dimName);
if (dimVariable == null) {
return false;
}
if (dimVariable instanceof CoordinateAxis1D) {
CoordinateAxis1D axis = (CoordinateAxis1D) dimVariable;
AxisType axisType = axis.getAxisType();
if (axisType == null) {
return false;
}
}
}
DataType dataType = var.getDataType();
if (dataType == DataType.CHAR) {
return false;
}
return isVariableAccepted(var.getName(), CheckType.NONE);
} else
return isVariableAccepted(var.getName(), checkType);
}
use of com.ibm.j9ddr.vm29.j9.DataType in project imageio-ext by geosolutions-it.
the class INGVConverter method run.
private void run(String fileNameIn, String fileNameOut) {
try {
final File fileIn = new File(fileNameIn);
final NetcdfFile ncFileIn = NetcdfFile.open(fileNameIn);
final File fileOut = new File(fileNameOut);
// keep original name
final File outputFile = File.createTempFile(fileIn.getName(), ".tmp");
final NetcdfFileWriteable ncFileOut = NetcdfFileWriteable.createNew(outputFile.getAbsolutePath());
boolean hasDepth = false;
// input dimensions
String timeName = "time_counter";
Dimension timeOriginalDim = ncFileIn.findDimension(timeName);
if (timeOriginalDim == null) {
timeOriginalDim = ncFileIn.findDimension("time");
timeName = "time";
}
final Dimension yDim = ncFileIn.findDimension("y");
final Dimension xDim = ncFileIn.findDimension("x");
// input VARIABLES
final Variable timeOriginalVar = ncFileIn.findVariable(timeName);
final Array timeOriginalData = timeOriginalVar.read();
final DataType timeDataType = timeOriginalVar.getDataType();
final Variable navLat = ncFileIn.findVariable(NAV_LAT);
final DataType navLatDataType = navLat.getDataType();
final Variable navLon = ncFileIn.findVariable(NAV_LON);
final DataType navLonDataType = navLon.getDataType();
final int nLat = yDim.getLength();
final int nLon = xDim.getLength();
final int nTimes = timeOriginalDim.getLength();
final Array latOriginalData = navLat.read("0:" + (nLat - 1) + ":1, 0:0:1").reduce();
final Array lonOriginalData = navLon.read("0:0:1, 0:" + (nLon - 1) + ":1").reduce();
// //
//
// Depth related vars
//
// //
Array depthOriginalData = null;
DataType depthDataType = null;
int nDepths = 0;
Array depthDestData = null;
Dimension depthDim = null;
String depthName = "depth";
Variable depthOriginalVar = null;
int dName = 0;
while (depthOriginalVar == null) {
if (dName == depthNames.length)
break;
String name = depthNames[dName++];
// Depth
depthOriginalVar = ncFileIn.findVariable(name);
}
if (depthOriginalVar != null) {
depthName = depthNames[dName - 1];
nDepths = depthOriginalVar.getDimension(0).getLength();
depthOriginalData = depthOriginalVar.read();
hasDepth = true;
}
Dimension timeDim = ncFileOut.addDimension("time", nTimes);
Dimension latDim = ncFileOut.addDimension(NetCDFUtilities.LAT, nLat);
Dimension lonDim = ncFileOut.addDimension(NetCDFUtilities.LON, nLon);
if (hasDepth)
depthDim = ncFileOut.addDimension(NetCDFUtilities.DEPTH, nDepths);
// writing file
NetCDFConverterUtilities.copyGlobalAttributes(ncFileOut, ncFileIn.getGlobalAttributes());
// //
//
// Time requires a special Management
//
// //
// time Variable
Variable timeVar = ncFileOut.addVariable(NetCDFUtilities.TIME, timeDataType, new Dimension[] { timeDim });
NetCDFConverterUtilities.setVariableAttributes(timeOriginalVar, ncFileOut, NetCDFUtilities.TIME);
// Dimensions
ncFileOut.addVariable(NetCDFUtilities.LAT, navLatDataType, new Dimension[] { latDim });
NetCDFConverterUtilities.setVariableAttributes(navLat, ncFileOut, NetCDFUtilities.LAT);
ncFileOut.addVariable(NetCDFUtilities.LON, navLonDataType, new Dimension[] { lonDim });
NetCDFConverterUtilities.setVariableAttributes(navLon, ncFileOut, NetCDFUtilities.LON);
Array lat1Data = NetCDFConverterUtilities.getArray(nLat, navLatDataType);
NetCDFConverterUtilities.setData1D(latOriginalData, lat1Data, navLatDataType, nLat, true);
// lon Variable
Array lon1Data = NetCDFConverterUtilities.getArray(nLon, navLonDataType);
NetCDFConverterUtilities.setData1D(lonOriginalData, lon1Data, navLonDataType, nLon, false);
if (hasDepth) {
depthDataType = depthOriginalVar.getDataType();
ncFileOut.addVariable(NetCDFUtilities.DEPTH, depthDataType, new Dimension[] { depthDim });
NetCDFConverterUtilities.setVariableAttributes(depthOriginalVar, ncFileOut, NetCDFUtilities.DEPTH);
}
if (hasDepth) {
// depth level Variable
depthDestData = NetCDFConverterUtilities.getArray(nDepths, depthDataType);
NetCDFConverterUtilities.setData1D(depthOriginalData, depthDestData, depthDataType, nDepths, false);
}
// {} Variables
final ArrayList<String> variables = new ArrayList<String>(5);
final HashMap<String, String> updatingValidRange = new HashMap<String, String>(5);
final HashMap<String, String> updatingFilLValue = new HashMap<String, String>(5);
int numVars = 0;
for (int i = 0; i < NUMVARS; i++) {
String varName = (String) VARIABLES.get(i);
Variable var = ncFileIn.findVariable(varName);
if (var != null) {
variables.add(varName);
boolean hasLocalDepth = NetCDFConverterUtilities.hasThisDimension(var, depthName);
if (hasDepth && hasLocalDepth)
ncFileOut.addVariable(varName, var.getDataType(), new Dimension[] { timeDim, depthDim, latDim, lonDim });
else
ncFileOut.addVariable(varName, var.getDataType(), new Dimension[] { timeDim, latDim, lonDim });
// //
//
// Check for updating valid range
//
// //
boolean hasMinMax = false;
Attribute validMax = var.findAttribute(NetCDFUtilities.DatasetAttribs.VALID_MAX);
Attribute validMin = var.findAttribute(NetCDFUtilities.DatasetAttribs.VALID_MIN);
Attribute fillValue = var.findAttribute(NetCDFUtilities.DatasetAttribs.FILL_VALUE);
boolean hasMissingValue = false;
boolean hasFillValue = true;
if (fillValue == null) {
hasFillValue = false;
fillValue = var.findAttribute(NetCDFUtilities.DatasetAttribs.MISSING_VALUE);
if (fillValue != null)
hasMissingValue = true;
}
Attribute validRange = var.findAttribute(NetCDFUtilities.DatasetAttribs.VALID_RANGE);
boolean hasValidRange = false;
boolean rewriteAttribute = false;
if (validMin != null && validMax != null && fillValue != null) {
rewriteAttribute = !NetCDFConverterUtilities.isFillValueOutsideValidRange(validMax, validMin, fillValue, var.getDataType());
hasMinMax = true;
} else if (validRange != null && fillValue != null) {
rewriteAttribute = !NetCDFConverterUtilities.isFillValueOutsideValidRange(validRange, fillValue, var.getDataType());
hasValidRange = true;
} else {
rewriteAttribute = true;
}
if (rewriteAttribute) {
updatingValidRange.put(varName, "");
DataType varDatatype = var.getDataType();
Array range = NetCDFConverterUtilities.getRangeArray(varDatatype);
ncFileOut.addVariableAttribute(varName, NetCDFUtilities.DatasetAttribs.VALID_RANGE, range);
if (hasMissingValue && !hasFillValue) {
updatingFilLValue.put(varName, "");
Number fillVal = NetCDFConverterUtilities.getNumber(varDatatype);
ncFileOut.addVariableAttribute(varName, NetCDFUtilities.DatasetAttribs.FILL_VALUE, fillVal);
}
}
String[] exceptions = null;
if (hasMinMax) {
if (hasMissingValue)
exceptions = new String[] { NetCDFUtilities.DatasetAttribs.VALID_MAX, NetCDFUtilities.DatasetAttribs.VALID_MIN, NetCDFUtilities.DatasetAttribs.MISSING_VALUE };
else
exceptions = new String[] { NetCDFUtilities.DatasetAttribs.VALID_MAX, NetCDFUtilities.DatasetAttribs.VALID_MIN };
} else if (hasValidRange) {
if (hasMissingValue)
exceptions = new String[] { NetCDFUtilities.DatasetAttribs.VALID_RANGE, NetCDFUtilities.DatasetAttribs.MISSING_VALUE };
else
exceptions = new String[] { NetCDFUtilities.DatasetAttribs.VALID_RANGE };
} else if (hasMissingValue)
exceptions = new String[] { NetCDFUtilities.DatasetAttribs.MISSING_VALUE };
NetCDFConverterUtilities.setVariableAttributes(var, ncFileOut, exceptions);
numVars++;
}
}
// writing bin data ...
ncFileOut.create();
Array timeData = NetCDFConverterUtilities.getArray(nTimes, timeDataType);
NetCDFConverterUtilities.setData1D(timeOriginalData, timeData, timeDataType, nTimes, false);
ncFileOut.write("time", timeData);
timeVar = ncFileOut.findVariable("time");
timeDim.addCoordinateVariable(timeVar);
ncFileOut.write(NetCDFUtilities.LAT, lat1Data);
ncFileOut.write(NetCDFUtilities.LON, lon1Data);
if (hasDepth) {
Variable depthVar = ncFileOut.findVariable("depth");
depthDim.addCoordinateVariable(depthVar);
ncFileOut.write(NetCDFUtilities.DEPTH, depthDestData);
}
for (int i = 0; i < numVars; i++) {
String varName = (String) variables.get(i);
Variable var = ncFileIn.findVariable(varName);
final boolean hasLocalDepth = NetCDFConverterUtilities.hasThisDimension(var, depthName);
Array originalVarArray = var.read();
DataType varDataType = var.getDataType();
Array destArray = null;
int[] dimensions = null;
final boolean setDepth = hasDepth && hasLocalDepth;
if (setDepth) {
dimensions = new int[] { timeDim.getLength(), depthDim.getLength(), latDim.getLength(), lonDim.getLength() };
} else {
dimensions = new int[] { timeDim.getLength(), latDim.getLength(), lonDim.getLength() };
}
destArray = NetCDFConverterUtilities.getArray(dimensions, varDataType);
boolean findNewRange = updatingValidRange.containsKey(varName);
boolean updateFillValue = updatingFilLValue.containsKey(varName);
final int[] loopLengths;
if (setDepth)
loopLengths = new int[] { nTimes, nDepths, nLat, nLon };
else
loopLengths = new int[] { nTimes, nLat, nLon };
NetCDFConverterUtilities.writeData(ncFileOut, varName, var, originalVarArray, destArray, findNewRange, updateFillValue, loopLengths, true);
}
ncFileOut.close();
outputFile.renameTo(fileOut);
} catch (Exception e) {
// something bad happened
if (NetCDFConverterUtilities.LOGGER.isLoggable(Level.INFO))
NetCDFConverterUtilities.LOGGER.log(Level.INFO, e.getLocalizedMessage(), e);
}
}
Aggregations