Search in sources :

Example 31 with SystemType

use of org.geotoolkit.sml.xml.v100.SystemType in project arctic-sea by 52North.

the class SensorMLEncoderV101Test method should_merge_and_encode_two_same_contact_responsibleParty_only_once.

@Test
public void should_merge_and_encode_two_same_contact_responsibleParty_only_once() throws EncodingException {
    final SensorML sensorML = new SensorML();
    final System system = new System();
    sensorML.addMember(system);
    final SmlResponsibleParty p1 = createResponsibleParty("1");
    system.addContact(p1);
    final SensorMLDocument xbSensorML = SensorMLDocument.Factory.newInstance();
    final SystemType xbSystem = SystemType.Factory.newInstance();
    final ResponsibleParty xbP1 = xbSystem.addNewContact().addNewResponsibleParty();
    setResponsiblePartyValues(p1, xbP1);
    final XmlObject xbProcess = xbSensorML.addNewSensorML().addNewMember().addNewProcess().set(xbSystem);
    XmlHelper.substituteElement(xbProcess, xbSystem);
    xbSensorML.getSensorML().setVersion("1.0.1");
    sensorML.setXml(xbSensorML.xmlText());
    final SystemType xbEncodedSystem = encodeSystem(sensorML);
    assertThat(xbEncodedSystem.sizeOfContactArray(), is(1));
    assertThat(xbEncodedSystem.getContactArray(0).isSetResponsibleParty(), is(true));
    checkResponsibleParty(p1, xbEncodedSystem.getContactArray(0).getResponsibleParty());
}
Also used : SmlResponsibleParty(org.n52.shetland.ogc.sensorML.SmlResponsibleParty) SensorMLDocument(net.opengis.sensorML.x101.SensorMLDocument) SystemType(net.opengis.sensorML.x101.SystemType) XmlObject(org.apache.xmlbeans.XmlObject) SmlResponsibleParty(org.n52.shetland.ogc.sensorML.SmlResponsibleParty) ResponsibleParty(net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty) SensorML(org.n52.shetland.ogc.sensorML.SensorML) System(org.n52.shetland.ogc.sensorML.System) Test(org.junit.jupiter.api.Test)

Example 32 with SystemType

use of org.geotoolkit.sml.xml.v100.SystemType in project AMASE by loonwerks.

the class SafetyValidator method collectFaultsFromSubcomponents.

/**
 * Collect all subcomponents of this component implementation and
 * iterate through them finding the faults defined for each.
 * @param compImpl
 * @return Map<String, List<String>> mapping from component instance name
 * to a list of associated faults.
 */
private Map<String, List<String>> collectFaultsFromSubcomponents(ComponentImplementation compImpl) {
    Map<String, List<String>> mapCompNameToFaultNames = new HashMap<String, List<String>>();
    for (Subcomponent sub : compImpl.getAllSubcomponents()) {
        if (sub.getComponentType() instanceof SystemType) {
            List<AnnexSubclause> annexes = ((SystemType) sub.getComponentType()).getOwnedAnnexSubclauses();
            for (AnnexSubclause annex : annexes) {
                if (annex.getName().contains("safety")) {
                    for (Element child : annex.getChildren()) {
                        List<String> faultNames = new ArrayList<String>();
                        if (child instanceof SafetyContractSubclause) {
                            SafetyContractSubclause safetyChild = (SafetyContractSubclause) child;
                            SafetyContract cont = (SafetyContract) safetyChild.getContract();
                            faultNames.addAll(getFaultNamesFromSpecs(cont.getSpecs()));
                            mapCompNameToFaultNames.put(sub.getName(), faultNames);
                        }
                    }
                }
            }
        }
    }
    return mapCompNameToFaultNames;
}
Also used : HashMap(java.util.HashMap) Element(org.osate.aadl2.Element) NamedElement(org.osate.aadl2.NamedElement) ArrayList(java.util.ArrayList) SystemType(org.osate.aadl2.SystemType) SafetyContractSubclause(edu.umn.cs.crisys.safety.safety.SafetyContractSubclause) Subcomponent(org.osate.aadl2.Subcomponent) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) SafetyContract(edu.umn.cs.crisys.safety.safety.SafetyContract) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 33 with SystemType

use of org.geotoolkit.sml.xml.v100.SystemType in project AMASE by loonwerks.

the class SafetyValidator method collectFaultsFromPackages.

/**
 * Get packages defined in this component impl and collect all faults from
 * all included packages.
 * @param compImpl
 * @return Map<String, List<String>> mapping from component instance name
 * to a list of associated faults.
 */
private Map<String, List<String>> collectFaultsFromPackages(ComponentImplementation compImpl) {
    Map<String, List<String>> mapCompNameToFaultNames = new HashMap<String, List<String>>();
    List<AadlPackageImpl> packages = new ArrayList<AadlPackageImpl>();
    AadlPackageImpl aadlPackage = getAadlPackageImpl(compImpl);
    packages.add(aadlPackage);
    PublicPackageSection pps = aadlPackage.getOwnedPublicSection();
    // Collect all imported packages and iterate through
    // annexes to find safety annexes with faults.
    List<ModelUnit> imports = pps.getImportedUnits();
    for (ModelUnit imp : imports) {
        if (imp instanceof AadlPackageImpl) {
            packages.add((AadlPackageImpl) imp);
        }
    }
    for (AadlPackageImpl aadlPack : packages) {
        PublicPackageSection pub = aadlPack.getPublicSection();
        for (Classifier cl : pub.getOwnedClassifiers()) {
            if (cl instanceof SystemType) {
                for (AnnexSubclause sub : cl.getOwnedAnnexSubclauses()) {
                    if (sub.getName().contains("safety")) {
                        for (Element child : sub.getChildren()) {
                            List<String> faultNames = new ArrayList<String>();
                            if (child instanceof SafetyContractSubclause) {
                                SafetyContractSubclause safetyChild = (SafetyContractSubclause) child;
                                SafetyContract cont = (SafetyContract) safetyChild.getContract();
                                faultNames.addAll(getFaultNamesFromSpecs(cont.getSpecs()));
                                mapCompNameToFaultNames.put(cl.getName(), faultNames);
                            }
                        }
                    }
                }
            }
        }
    }
    return mapCompNameToFaultNames;
}
Also used : HashMap(java.util.HashMap) Element(org.osate.aadl2.Element) NamedElement(org.osate.aadl2.NamedElement) ArrayList(java.util.ArrayList) SystemType(org.osate.aadl2.SystemType) Classifier(org.osate.aadl2.Classifier) AadlPackageImpl(org.osate.aadl2.impl.AadlPackageImpl) SafetyContractSubclause(edu.umn.cs.crisys.safety.safety.SafetyContractSubclause) PublicPackageSection(org.osate.aadl2.PublicPackageSection) ModelUnit(org.osate.aadl2.ModelUnit) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) SafetyContract(edu.umn.cs.crisys.safety.safety.SafetyContract) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 34 with SystemType

use of org.geotoolkit.sml.xml.v100.SystemType in project VERDICT by ge-high-assurance.

the class Aadl2Vdm method translateSystemTypeObjects.

// End of populateVDMFromAadlObjects
/**
 * Analyzing each systemType:
 * 1. Determine if it is a lower-level system or higher-level system
 * 2. If lower-level, add to componentType list attribute of Model
 * 	2.1 Populate the port, contract, cyberRel, safetyRel, event, id, compCategory
 *      fields of componentType of the Model object
 * 3. If higher-level, assign to Model
 * 	3.1 Populate the safetyReq
 *      cyberReq, mission fields of Model object
 * @param systemTypes
 * @param m1
 * @return
 */
public Model translateSystemTypeObjects(List<SystemType> systemTypes, Model m1, HashSet<String> dataTypeDecl) {
    for (SystemType sysType : systemTypes) {
        // variables for unpacking sysType
        List<Event> events = new ArrayList<>();
        List<CyberMission> missionReqs = new ArrayList<>();
        List<CyberRel> cyberRels = new ArrayList<>();
        List<SafetyRel> safetyRels = new ArrayList<>();
        List<CyberReq> cyberReqs = new ArrayList<>();
        List<SafetyReq> safetyReqs = new ArrayList<>();
        // a flag to check if a higher -level component has already been found
        boolean higher_flag = false;
        // unpacking sysType
        for (AnnexSubclause annex : sysType.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("verdict")) {
                Verdict verdictAnnex = VerdictUtil.getVerdict(annex);
                for (Statement statement : verdictAnnex.getElements()) {
                    if (statement instanceof Event) {
                        events.add((Event) statement);
                    } else if (statement instanceof CyberMission) {
                        missionReqs.add((CyberMission) statement);
                    } else if (statement instanceof CyberReq) {
                        cyberReqs.add((CyberReq) statement);
                    } else if (statement instanceof CyberRel) {
                        cyberRels.add((CyberRel) statement);
                    } else if (statement instanceof SafetyReq) {
                        safetyReqs.add((SafetyReq) statement);
                    } else if (statement instanceof SafetyRel) {
                        safetyRels.add((SafetyRel) statement);
                    }
                }
            }
        }
        /**
         *  For every SystemType,
         *  populate the id, name, compCateg, port, event,
         *  cyberRel, and safetyRel fields of componentType
         *  and add it to the list of componentType
         *  of the Model object
         */
        if (true) {
            // No Filter-- do for all System Types
            // to pack the sysType as a VDM component
            verdict.vdm.vdm_model.ComponentType packComponent = new verdict.vdm.vdm_model.ComponentType();
            // Note: Not populating "contract" for now
            // ISSUE: There is no getId() function for systemType
            packComponent.setId(sysType.getQualifiedName());
            // populating "name"
            packComponent.setName(sysType.getName());
            // populating "compCateg"
            packComponent.setCompCateg(sysType.getCategory().getName());
            // get all bus accesses and store them as ports
            List<BusAccess> busAccesses = sysType.getOwnedBusAccesses();
            // checking each busAccess's details and adding it to the port list
            for (BusAccess busAccess : busAccesses) {
                String portName = busAccess.getName();
                String modeString = "in";
                if (busAccess.getKind() == AccessType.PROVIDES) {
                    modeString = "providesBusAccess";
                } else if (busAccess.getKind() == AccessType.REQUIRES) {
                    modeString = "requiresBusAccess";
                }
                // fetching data type information
                verdict.vdm.vdm_model.Port newPort = createVdmPort(portName, modeString, busAccess.getQualifiedName());
                // Note: Not populating "type" for now
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each busAccess
            // get all data accesses and store them as ports
            List<DataAccess> dataAccesses = sysType.getOwnedDataAccesses();
            // checking each dataAccess's details and adding it to the port list
            for (DataAccess dataAccess : dataAccesses) {
                String portName = dataAccess.getName();
                String modeString = "in";
                if (dataAccess.getKind() == AccessType.PROVIDES) {
                    modeString = "providesDataAccess";
                } else if (dataAccess.getKind() == AccessType.REQUIRES) {
                    modeString = "requiresDataAccess";
                }
                verdict.vdm.vdm_model.Port newPort = createVdmPort(portName, modeString, dataAccess.getQualifiedName());
                // Note: Not populating "type" for now
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each dataAccess
            // get all ports
            List<DataPort> dataPorts = sysType.getOwnedDataPorts();
            // checking each port's mode and name and adding it to the port list
            for (DataPort dataPort : dataPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmPort(dataPort, m1, dataTypeDecl);
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each port
            // get all event data ports
            List<EventDataPort> eventDataPorts = sysType.getOwnedEventDataPorts();
            for (EventDataPort eventDataPort : eventDataPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmPort(eventDataPort, m1, dataTypeDecl);
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // get all event ports
            List<EventPort> eventPorts = sysType.getOwnedEventPorts();
            for (EventPort eventPort : eventPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmEventPort(eventPort);
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // packing all events and adding to component
            for (Event anEvent : events) {
                // To pack the event as a VDM event
                verdict.vdm.vdm_model.Event packEvent = createVdmEvent(anEvent);
                // adding to the list of component's events
                packComponent.getEvent().add(packEvent);
            }
            // packing all cyberRels and adding to component
            for (CyberRel aCyberRel : cyberRels) {
                // To pack the cyberRel as a VDM event
                verdict.vdm.vdm_model.CyberRel packCyberRel = createVdmCyberRel(aCyberRel);
                // adding to the list of component's Cyber relations
                packComponent.getCyberRel().add(packCyberRel);
            }
            // packing all safetyRels and adding to component
            for (SafetyRel aSafetyRel : safetyRels) {
                // To pack the safetyRel as a VDM event
                verdict.vdm.vdm_model.SafetyRel packSafetyRel = createVdmSafetyRel(aSafetyRel);
                // adding to the list of component's Safety relations
                packComponent.getSafetyRel().add(packSafetyRel);
            }
            // End of packing all safetyRels
            // adding to the list of componentTypes of the Model object
            m1.getComponentType().add(packComponent);
        }
        /**
         * If a high-level system
         *  populate the name, safetyReq, cyberReq, and mission
         *  for the model object
         */
        if (!cyberReqs.isEmpty() || !safetyReqs.isEmpty() || !missionReqs.isEmpty()) {
            // checking if a high-level system has already been found
            if (higher_flag == false) {
                higher_flag = true;
            } else {
                System.out.println("Warning: Multiple high-level systems detected!");
            }
            // populating name
            m1.setName(sysType.getName());
            // packing all safetyReqs and adding to model
            for (SafetyReq aSafetyReq : safetyReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.SafetyReq packSafetyReq = createVdmSafetyReq(aSafetyReq, sysType.getFullName());
                // adding to the list of model's Safety requirements
                m1.getSafetyReq().add(packSafetyReq);
            }
            // packing all cyberReqs and adding to model
            for (CyberReq aCyberReq : cyberReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.CyberReq packCyberReq = createVdmCyberReq(aCyberReq, sysType.getFullName());
                // adding to the list of model's Cyber requirements
                m1.getCyberReq().add(packCyberReq);
            }
            // packing all missionReqs and adding to model
            for (CyberMission aMission : missionReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.Mission packMission = createVdmMission(aMission);
                // adding to the list of model's Mission
                m1.getMission().add(packMission);
            }
        // End of packing all missionReqs
        }
    // End of if a higher-level system
    }
    // returning the populated Model
    return m1;
}
Also used : ArrayList(java.util.ArrayList) SystemType(org.osate.aadl2.SystemType) Port(verdict.vdm.vdm_model.Port) DataAccess(org.osate.aadl2.DataAccess) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EventPort(org.osate.aadl2.EventPort) EventDataPort(org.osate.aadl2.EventDataPort) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) BusAccess(org.osate.aadl2.BusAccess) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) Event(com.ge.research.osate.verdict.dsl.verdict.Event) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 35 with SystemType

use of org.geotoolkit.sml.xml.v100.SystemType in project VERDICT by ge-high-assurance.

the class VerdictJavaValidator method checkStatement.

/**
 * Check that cyber relations/requirements have unique, non-empty IDs
 * and they are only located in subsystems/top-level systems, respectively.
 *
 * @param statement
 */
@Check(CheckType.FAST)
public void checkStatement(Statement statement) {
    String statementType;
    boolean shouldBeSubcomponent;
    if (statement instanceof CyberRel) {
        statementType = "Cyber relation";
        shouldBeSubcomponent = true;
    } else if (statement instanceof CyberReq) {
        statementType = "Cyber requirement";
        shouldBeSubcomponent = false;
    } else if (statement instanceof CyberMission) {
        statementType = "Mission";
        shouldBeSubcomponent = false;
    } else if (statement instanceof SafetyReq) {
        statementType = "Safety requirement";
        shouldBeSubcomponent = false;
    } else if (statement instanceof SafetyRel) {
        statementType = "Safety relation";
        shouldBeSubcomponent = true;
    } else if (statement instanceof Event) {
        statementType = "Event";
        shouldBeSubcomponent = true;
    } else {
        throw new RuntimeException("statement is not CyberRel, or CyberReq, or Mission, or SafetyReq, or SafetyRel, or Event!?");
    }
    if (statement.getId().length() == 0) {
        error(statementType + " must specify an ID", VerdictPackage.Literals.STATEMENT__ID);
        return;
    }
    // Find enclosing system
    EObject container = statement;
    while (container != null && !(container instanceof SystemType || container instanceof PublicPackageSection)) {
        container = container.eContainer();
    }
    /*
		 * Within the same component, we need to make sure that cyber relations, cyber requirements,
		 * safety relations, safety missions, events do not have naming conflicts respectively.
		 */
    Set<String> otherIds = new HashSet<>();
    if (container instanceof SystemType) {
        SystemType currentSystem = (SystemType) container;
        // Get enclosing file
        while (!(container instanceof PublicPackageSection)) {
            container = container.eContainer();
        }
        // Get all verdict annexes for this system
        for (AnnexSubclause annex : currentSystem.getOwnedAnnexSubclauses()) {
            if ("verdict".equals(annex.getName())) {
                Verdict subclause = VerdictUtil.getVerdict(annex);
                // We only check that within the same statement category, there should not be naming conflicts.
                for (Statement other : subclause.getElements()) {
                    // Don't double-count self
                    if (!statement.equals(other)) {
                        if ((statement instanceof CyberRel) && (other instanceof CyberRel)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof CyberReq) && (other instanceof CyberReq)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof CyberMission) && (other instanceof CyberMission)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof SafetyReq) && (other instanceof SafetyReq)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof SafetyRel) && (other instanceof SafetyRel)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof Event) && (other instanceof Event)) {
                            otherIds.add(other.getId());
                        }
                    }
                }
            }
        }
        /*
			 * A system is a top-level system if it is not a subcomponent
			 * of any other system (cyber/safety requirements are valid).
			 *
			 * If it is a subcomponent of another system, then it is a
			 * subcomponent (cyber/safety relations are valid).
			 */
        PublicPackageSection pack = (PublicPackageSection) container;
        // Find all system impls
        for (Classifier cls : pack.getOwnedClassifiers()) {
            if (cls instanceof SystemImplementation) {
                // Grab the dependency/subcomponent tree
                SystemImplementation systemImpl = (SystemImplementation) cls;
                for (Subcomponent sub : systemImpl.getAllSubcomponents()) {
                    if (sub.getComponentImplementation() != null) {
                        subcomponents.add(sub.getComponentImplementation().getType());
                    }
                    subcomponents.add(sub.getSubcomponentType());
                }
            }
        }
        boolean isSubcomponent = subcomponents.contains(currentSystem);
        if (isSubcomponent && !shouldBeSubcomponent) {
            warning(statementType + " not allowed in subcomponent system");
        } else if (!isSubcomponent && shouldBeSubcomponent) {
            warning(statementType + " not allowed in top-level system");
        }
        if (otherIds.contains(statement.getId())) {
            error("Duplicate ID " + statement.getId(), VerdictPackage.Literals.STATEMENT__ID);
        }
    }
    // Perform extra checks for missions
    if (statement instanceof CyberMission) {
        checkMission((CyberMission) statement);
    }
    // And cyber reqs
    if (statement instanceof CyberReq) {
        checkCyberReq((CyberReq) statement);
    }
}
Also used : CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) ThreatStatement(com.ge.research.osate.verdict.dsl.verdict.ThreatStatement) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SystemType(org.osate.aadl2.SystemType) Classifier(org.osate.aadl2.Classifier) PublicPackageSection(org.osate.aadl2.PublicPackageSection) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) SystemImplementation(org.osate.aadl2.SystemImplementation) EObject(org.eclipse.emf.ecore.EObject) Subcomponent(org.osate.aadl2.Subcomponent) Event(com.ge.research.osate.verdict.dsl.verdict.Event) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) AnnexSubclause(org.osate.aadl2.AnnexSubclause) HashSet(java.util.HashSet) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) Check(org.eclipse.xtext.validation.Check)

Aggregations

SystemType (net.opengis.sensorML.x101.SystemType)24 Test (org.junit.jupiter.api.Test)18 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)15 SystemType (org.osate.aadl2.SystemType)14 AbstractProcess (org.n52.shetland.ogc.sensorML.AbstractProcess)13 ArrayList (java.util.ArrayList)12 System (org.n52.shetland.ogc.sensorML.System)11 EObject (org.eclipse.emf.ecore.EObject)9 SensorML (org.n52.shetland.ogc.sensorML.SensorML)9 AnnexSubclause (org.osate.aadl2.AnnexSubclause)8 IdentifierList (net.opengis.sensorML.x101.IdentificationDocument.Identification.IdentifierList)6 PublicPackageSection (org.osate.aadl2.PublicPackageSection)6 CyberReq (com.ge.research.osate.verdict.dsl.verdict.CyberReq)5 HashSet (java.util.HashSet)5 SystemImplementation (org.osate.aadl2.SystemImplementation)5 SafetyReq (com.ge.research.osate.verdict.dsl.verdict.SafetyReq)4 Statement (com.ge.research.osate.verdict.dsl.verdict.Statement)4 Verdict (com.ge.research.osate.verdict.dsl.verdict.Verdict)4 Component (net.opengis.sensorML.x101.ComponentsDocument.Components.ComponentList.Component)4 SmlPerson (org.n52.shetland.ogc.sensorML.SmlPerson)4