use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.
the class DataPointService method validate.
@Override
public ProcessResult validate(DataPointVO vo) {
ProcessResult result = commonValidation(vo);
DataSourceVO dsvo = dataSourceDao.get(vo.getDataSourceId());
if (dsvo == null) {
result.addContextualMessage("dataSourceId", "validate.invalidValue");
return result;
}
// Validate pl if there is one
if (vo.getPointLocator() != null) {
DataSourceDefinition<? extends DataSourceVO> def = ModuleRegistry.getDataSourceDefinition(vo.getPointLocator().getDataSourceType());
if (def == null) {
throw new ShouldNeverHappenException("No data source definition for type " + vo.getPointLocator().getDataSourceType());
} else {
// Validate the point locator
def.validate(result, vo, dsvo);
if (vo.getPointLocator().getDataType() == null && !result.hasContextualMessage("dataType")) {
result.addContextualMessage("dataType", "validate.invalidValueWithAcceptable", DataType.formatNames());
}
}
}
PermissionHolder user = Common.getUser();
permissionService.validatePermission(result, "readPermission", user, vo.getReadPermission());
permissionService.validatePermission(result, "editPermission", user, vo.getEditPermission());
permissionService.validatePermission(result, "setPermission", user, vo.getSetPermission(), false);
return result;
}
use of com.serotonin.m2m2.DataType in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method createVdmPort.
/**
* @author Vidhya Tekken Valapil
* Creates a new Vdm Port object and returns
* Populates "name", "mode" and "type"
* @param dataport
* @return vdm port
*/
private Port createVdmPort(DataPort dataPort, Model model, HashSet<String> dataTypeDecl) {
String modeString = "in";
if (dataPort.isIn()) {
modeString = "in";
} else if (dataPort.isOut()) {
modeString = "out";
}
// fetching data type information
DataSubcomponentType dSubCompType = dataPort.getDataFeatureClassifier();
verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
if (dSubCompType instanceof DataTypeImpl) {
org.osate.aadl2.DataType aadlDType = (org.osate.aadl2.DataType) dSubCompType;
dtype = resolveAADLDataType(aadlDType, model, dataTypeDecl);
} else if (dSubCompType instanceof DataImplementationImpl) {
org.osate.aadl2.DataImplementation aadlDImpl = (org.osate.aadl2.DataImplementation) dSubCompType;
dtype = resolveAADLDataImplementationType(aadlDImpl, model, dataTypeDecl);
} else {
System.out.println("Unresolved/unexpected Named Element.");
}
verdict.vdm.vdm_model.Port newPort = new verdict.vdm.vdm_model.Port();
newPort.setProbe(false);
if (dataPort.getOwnedPropertyAssociations().size() != 0) {
EList<PropertyAssociation> propertyAssocs = dataPort.getOwnedPropertyAssociations();
for (PropertyAssociation propertyAssoc : propertyAssocs) {
if (propertyAssoc.getProperty().getName().equalsIgnoreCase("probe")) {
EList<ModalPropertyValue> propVals = propertyAssoc.getOwnedValues();
if (propVals.size() == 0 || propVals.size() > 1) {
throw new RuntimeException("Unexpected number for values for probe property of port.");
}
if (propVals.get(0).getOwnedValue() instanceof BooleanLiteral) {
BooleanLiteral probeVal = (BooleanLiteral) propVals.get(0).getOwnedValue();
newPort.setProbe(probeVal.getValue());
} else {
throw new RuntimeException("Unexpected type of value for probe property of port.");
}
}
}
}
newPort.setId(dataPort.getQualifiedName());
newPort.setName(dataPort.getName());
newPort.setMode(convertToVdmPortMode(modeString));
newPort.setType(dtype);
return newPort;
}
use of com.serotonin.m2m2.DataType in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method defineDataImplementationType.
/**
* @author Vidhya Tekken Valapil
* populate information related to data implementation types in the vdm
*/
private void defineDataImplementationType(DataImplementation dataImplementation, Model model, HashSet<String> dataTypeDecl) {
// DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
String dataImplementationName = dataImplementation.getName();
if (!dataTypeDecl.contains(dataImplementationName)) {
dataTypeDecl.add(dataImplementationName);
// vdm data type declaration
TypeDeclaration dataTypeVdm = new TypeDeclaration();
dataTypeVdm.setName(dataImplementationName);
verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
// GET DETAILS OF THE DATA IMPLEMENTATION AND CREATE CORRESPONDING VDM DATATYPE
EList<DataSubcomponent> subcomponents = dataImplementation.getOwnedDataSubcomponents();
if (!(subcomponents.isEmpty())) {
// if the dataType definition has subcomponents
RecordType recType = new RecordType();
for (DataSubcomponent dataSubComp : subcomponents) {
RecordField recField = new RecordField();
recField.setName(dataSubComp.getName());
DataSubcomponentType dataSubCompType = dataSubComp.getDataSubcomponentType();
if (dataSubCompType instanceof org.osate.aadl2.DataType) {
org.osate.aadl2.DataType aadlDataType = (org.osate.aadl2.DataType) dataSubCompType;
Agree2Vdm agree2vdm = new Agree2Vdm();
verdict.vdm.vdm_data.DataType recFieldDtype = agree2vdm.getVdmTypeFromAADLType(aadlDataType);
recField.setType(recFieldDtype);
resolveAADLDataType(aadlDataType, model, dataTypeDecl);
recType.getRecordField().add(recField);
} else if (dataSubCompType instanceof DataImplementation) {
DataImplementation dataSubCompDataImplementation = (DataImplementation) dataSubCompType;
verdict.vdm.vdm_data.DataType recFieldDtype = new verdict.vdm.vdm_data.DataType();
recFieldDtype.setUserDefinedType(dataSubCompDataImplementation.getName());
recField.setType(recFieldDtype);
defineDataImplementationType(dataSubCompDataImplementation, model, dataTypeDecl);
recType.getRecordField().add(recField);
} else {
System.out.println("Unexpected Data Subcomponent that is not a DataTypeImpl or DataImplementatioImpl.");
}
}
if (recType.getRecordField().size() != 0) {
dtype.setRecordType(recType);
dataTypeVdm.setDefinition(dtype);
}
} else {
// if the dataType is base type boolean or integer or char or string
System.out.println("Data implementation type has no subcomponents");
}
// add the typeDeclaration to the model
model.getTypeDeclaration().add(dataTypeVdm);
}
}
use of com.serotonin.m2m2.DataType in project chipster-web-server by chipster.
the class XmlSession method fixModificationParents.
/**
* Fix dataset relations of the user modified datasets
*
* When user creates a new dataset from the selected rows of an old dataset, the
* Java client creates a MODIFICATION type of link between the datasets and
* creates a dummy Operation object, which will converted to a Job object for
* the web app. The new client doesn't use links, but gets dataset relations
* from the Job inputs. However, the Java client doesn't create the input
* definitions for the dummy job, so the web app wouldn't be able to show them.
* This method creates the Input objects for the Jobs to show these the dataset
* relationship correctly in the web app.
*
* @param sessionType
* @param session
* @param datasetMap
* @param jobMap
* @throws RestException
*/
private static void fixModificationParents(SessionType sessionType, Session session, Map<UUID, Dataset> datasetMap, Map<UUID, Job> jobMap) throws RestException {
for (DataType dataType : sessionType.getData()) {
UUID datasetId = UUID.fromString(dataType.getDataId());
Dataset dataset = datasetMap.get(datasetId);
Job job = jobMap.get(dataset.getSourceJob());
if (job != null && "operation-definition-id-user-modification".equals(job.getToolId())) {
List<DataType> parents = getLinked(sessionType, dataType, Link.MODIFICATION);
if (parents.size() == 1) {
Input input = new Input();
String dataId = parents.get(0).getDataId();
input.setDatasetId(dataId);
List<Input> inputs = new ArrayList<>();
inputs.add(input);
job.setInputs(inputs);
}
}
}
}
use of com.serotonin.m2m2.DataType in project chipster-web-server by chipster.
the class XmlSession method getEntryToDatasetIdMap.
/**
* There are two variants of version 2 xml sessions: the zip entries of the data
* files in the older variant are named as "file-0", "file-1" and so on while
* the newer uses the dataId for the entry name. Map entry names to dataIds to
* support the older variant. In the newer variant the key and value will be the
* same.
*
* @param sessionType
* @return
*/
private static HashMap<String, String> getEntryToDatasetIdMap(SessionType sessionType) {
HashMap<String, String> entryToDatasetIdMap = new HashMap<>();
for (DataType dataType : sessionType.getData()) {
boolean found = false;
for (LocationType locationType : dataType.getLocation()) {
if (StorageMethod.LOCAL_SESSION_ZIP.toString().equals(locationType.getMethod())) {
found = true;
String url = locationType.getUrl();
String entryName = url.substring(url.indexOf("#") + 1);
entryToDatasetIdMap.put(entryName, dataType.getDataId());
}
}
if (!found) {
throw new BadRequestException("file content of " + dataType.getName() + " not found");
}
}
return entryToDatasetIdMap;
}
Aggregations