Search in sources :

Example 76 with DataType

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;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 77 with DataType

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;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) DataImplementationImpl(org.osate.aadl2.impl.DataImplementationImpl) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BooleanLiteral(org.osate.aadl2.BooleanLiteral) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort) EventPort(org.osate.aadl2.EventPort) DataPort(org.osate.aadl2.DataPort) Port(verdict.vdm.vdm_model.Port) EventDataPort(org.osate.aadl2.EventDataPort) DataImplementation(org.osate.aadl2.DataImplementation) Port(verdict.vdm.vdm_model.Port) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataType(org.osate.aadl2.DataType) DataType(org.osate.aadl2.DataType)

Example 78 with DataType

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);
    }
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) DataImplementation(org.osate.aadl2.DataImplementation) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) RecordType(verdict.vdm.vdm_data.RecordType) DataSubcomponent(org.osate.aadl2.DataSubcomponent) DataType(org.osate.aadl2.DataType) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration) DataType(org.osate.aadl2.DataType)

Example 79 with DataType

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);
            }
        }
    }
}
Also used : Input(fi.csc.chipster.sessiondb.model.Input) Dataset(fi.csc.chipster.sessiondb.model.Dataset) ArrayList(java.util.ArrayList) DataType(fi.csc.chipster.sessionworker.xml.schema2.DataType) UUID(java.util.UUID) Job(fi.csc.chipster.sessiondb.model.Job)

Example 80 with DataType

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;
}
Also used : HashMap(java.util.HashMap) DataType(fi.csc.chipster.sessionworker.xml.schema2.DataType) BadRequestException(jakarta.ws.rs.BadRequestException) LocationType(fi.csc.chipster.sessionworker.xml.schema2.LocationType)

Aggregations

ArrayList (java.util.ArrayList)26 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)23 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)17 DataType (com.serotonin.m2m2.DataType)14 HashMap (java.util.HashMap)14 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)13 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)11 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)10 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)10 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)10 DataType (org.osate.aadl2.DataType)10 DataType (ucar.ma2.DataType)10 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)9 IOException (java.io.IOException)9 DataImplementation (org.osate.aadl2.DataImplementation)9 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)8 File (java.io.File)7 ScriptError (com.serotonin.m2m2.rt.script.ScriptError)6 ScriptPermissionsException (com.serotonin.m2m2.rt.script.ScriptPermissionsException)6