Search in sources :

Example 11 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class FHAReport method reportHazardProperty.

protected void reportHazardProperty(InstanceObject ci, List<EMV2PropertyAssociation> PAList, List<EMV2PropertyAssociation> SevList, List<EMV2PropertyAssociation> LikeList, NamedElement target, TypeSet ts, Element localContext, WriteToFile report) {
    String targetName;
    if (PAList.isEmpty()) {
        return;
    }
    if (target == null) {
        targetName = "";
    } else {
        targetName = EMV2Util.getPrintName(target);
        if (target instanceof ErrorEvent) {
            targetName = "event " + targetName;
        }
        if (target instanceof ErrorBehaviorState) {
            targetName = "state " + targetName;
        }
    }
    for (EMV2PropertyAssociation PA : PAList) {
        for (ModalPropertyValue modalPropertyValue : PA.getOwnedValues()) {
            PropertyExpression peVal = modalPropertyValue.getOwnedValue();
            ListValue lv = (ListValue) peVal;
            for (PropertyExpression pe : lv.getOwnedListElements()) {
                EList<BasicPropertyAssociation> fields = ((RecordValue) pe).getOwnedFieldValues();
                if (ts != null) {
                    // do smaller of ts or hazard type set.
                    EList<EMV2Path> epathlist = PA.getEmv2Path();
                    for (EMV2Path ep : epathlist) {
                        ErrorTypes et = EMV2Util.getErrorType(ep);
                        ErrorTypes targettype = ts;
                        if (et != null && EMV2TypeSetUtil.contains(ts, et)) {
                            targettype = et;
                        }
                        List<EMV2PropertyAssociation> Sevs = EMV2Properties.getSeverityProperty(ci, target, et);
                        List<EMV2PropertyAssociation> Likes = EMV2Properties.getLikelihoodProperty(ci, target, et);
                        EMV2PropertyAssociation Sev = Sevs.isEmpty() ? null : Sevs.get(0);
                        EMV2PropertyAssociation Like = Likes.isEmpty() ? null : Likes.get(0);
                        PropertyExpression severityValue = EMV2Properties.getPropertyValue(Sev);
                        PropertyExpression likelihoodValue = EMV2Properties.getPropertyValue(Like);
                        if (targettype instanceof TypeSet) {
                            for (TypeToken token : ((TypeSet) targettype).getTypeTokens()) {
                                reportFHAEntry(report, fields, severityValue, likelihoodValue, ci, targetName, EMV2Util.getName(token));
                            }
                        } else {
                            reportFHAEntry(report, fields, severityValue, likelihoodValue, ci, targetName, EMV2Util.getName(targettype));
                        }
                    }
                } else {
                    // did not have a type set. Let's use fmr (state of type set as failure mode.
                    EMV2PropertyAssociation Sev = SevList.isEmpty() ? null : SevList.get(0);
                    EMV2PropertyAssociation Like = LikeList.isEmpty() ? null : LikeList.get(0);
                    PropertyExpression severityValue = EMV2Properties.getPropertyValue(Sev);
                    PropertyExpression likelihoodValue = EMV2Properties.getPropertyValue(Like);
                    if (localContext == null) {
                        reportFHAEntry(report, fields, severityValue, likelihoodValue, ci, targetName, "");
                    } else {
                        reportFHAEntry(report, fields, severityValue, likelihoodValue, ci, EMV2Util.getPrintName(localContext), EMV2Util.getPrintName(target));
                    }
                }
            }
        }
    }
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) ListValue(org.osate.aadl2.ListValue) EMV2PropertyAssociation(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation) RecordValue(org.osate.aadl2.RecordValue) ErrorTypes(org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes) EMV2Path(org.osate.xtext.aadl2.errormodel.errorModel.EMV2Path) TypeToken(org.osate.xtext.aadl2.errormodel.errorModel.TypeToken) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 12 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class ErrorModelValidator method checkBranches.

private void checkBranches(ErrorBehaviorTransition ebt) {
    EList<TransitionBranch> branches = ebt.getDestinationBranches();
    boolean foundsteady = false;
    boolean foundothers = false;
    BigDecimal prob = new BigDecimal(0.0, MathContext.UNLIMITED);
    if (branches.isEmpty()) {
        return;
    }
    for (TransitionBranch transitionBranch : branches) {
        if (transitionBranch.isSteadyState()) {
            if (foundsteady) {
                error(ebt, "More than one same state branch");
            } else {
                foundsteady = true;
            }
        }
        if (transitionBranch.getValue().isOthers()) {
            if (foundothers) {
                error(ebt, "More than one other branch");
            } else {
                foundothers = true;
            }
        }
        String bv = EMV2Util.stripUnderScore(transitionBranch.getValue().getRealvalue());
        Property sl = transitionBranch.getValue().getSymboliclabel();
        if (bv != null) {
            prob = prob.add(new BigDecimal(bv, MathContext.UNLIMITED));
        } else if (sl != null) {
            Classifier cl = EMV2Util.getAssociatedClassifier(ebt);
            List<EMV2PropertyAssociation> pa = EMV2Properties.getProperty(sl.getQualifiedName(), cl, ebt, null);
            for (EMV2PropertyAssociation emv2PropertyAssociation : pa) {
                prob = prob.add(new BigDecimal(EMV2Properties.getRealValue(emv2PropertyAssociation), MathContext.UNLIMITED));
            }
        }
    }
    if (!foundothers && prob.compareTo(new BigDecimal(1.0)) != 0) {
        error(ebt, "Sum of branch probabilities must be 1");
    }
    if (foundothers && prob.compareTo(new BigDecimal(1.0)) >= 0) {
        error(ebt, "Sum of branch probabilities must be less than 1 due to 'others'");
    }
}
Also used : TransitionBranch(org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch) EMV2PropertyAssociation(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation) List(java.util.List) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) Classifier(org.osate.aadl2.Classifier) Property(org.osate.aadl2.Property) BigDecimal(java.math.BigDecimal)

Example 13 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class EMV2Properties method getHazardDescription.

public static String getHazardDescription(NamedElement element, NamedElement relatedComponent, ErrorTypes ts) {
    List<EMV2PropertyAssociation> PA = EMV2Properties.getHazardsProperty(relatedComponent, element, ts);
    if (PA.isEmpty()) {
        return null;
    }
    // XXX TODO we may get more than one back, one each for different types
    PropertyExpression val = getPropertyValue(PA.get(0));
    if (val instanceof RecordValue) {
        RecordValue rv = (RecordValue) val;
        EList<BasicPropertyAssociation> fields = rv.getOwnedFieldValues();
        BasicPropertyAssociation xref = GetProperties.getRecordField(fields, "description");
        if (xref != null) {
            PropertyExpression peVal = getPropertyValue(xref);
            if (peVal instanceof StringLiteral) {
                return ((StringLiteral) peVal).getValue();
            }
        }
    }
    if (val instanceof ListValue) {
        ListValue lv = (ListValue) val;
        for (PropertyExpression pe : lv.getOwnedListElements()) {
            if (pe instanceof RecordValue) {
                RecordValue rv = (RecordValue) pe;
                EList<BasicPropertyAssociation> fields = rv.getOwnedFieldValues();
                BasicPropertyAssociation xref = GetProperties.getRecordField(fields, "description");
                if (xref != null) {
                    PropertyExpression peVal = getPropertyValue(xref);
                    if (peVal instanceof StringLiteral) {
                        return ((StringLiteral) peVal).getValue();
                    }
                }
            }
        }
    }
    return null;
}
Also used : StringLiteral(org.osate.aadl2.StringLiteral) ListValue(org.osate.aadl2.ListValue) EMV2PropertyAssociation(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation) RecordValue(org.osate.aadl2.RecordValue) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 14 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class EMV2Properties method getPropertyInClassifier.

/**
 * retrieve an error model property (such as Hazard) attached to an error model element based on contained property associations
 * in the annex subclause properties section of the classifier.
 * @param propertyName name of property we are looking for
 * @param ci component instance whose EM element has the property
 * @param target the error model element (which is optionally followed by a type that is contained in the typeset ts
 * @param ts the type set
 * @return Containmentpath of the PA that matches the parameters.
 * we return the path because the PA applies to more than element
 */
public static List<EMV2PropertyAssociation> getPropertyInClassifier(String propertyName, Classifier cl, NamedElement target, Stack<NamedElement> ciStack, ErrorTypes ts) {
    if (cl != null) {
        // deals with inherited properties by walking subclause inheritance
        EList<ErrorModelSubclause> emslist = EMV2Util.getAllContainingClassifierEMV2Subclauses(cl);
        for (ErrorModelSubclause ems : emslist) {
            List<EMV2PropertyAssociation> props = ems.getProperties();
            List<EMV2PropertyAssociation> result = getMatchingPropertiesInList(props, propertyName, target, ciStack, ts);
            if (!result.isEmpty()) {
                return result;
            }
        }
    }
    return Collections.emptyList();
}
Also used : ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) EMV2PropertyAssociation(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation)

Example 15 with EMV2PropertyAssociation

use of org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation in project osate2 by osate.

the class EMV2Properties method getProbability.

/**
 * retrieve the probability
 * @param ci component instance, subcomponent, or classifier
 * @param ne named element for which we retrieve the probability
 * @param ts type set
 * @return
 */
public static double getProbability(NamedElement ci, NamedElement ne, ErrorTypes ts) {
    List<EMV2PropertyAssociation> PA = EMV2Properties.getOccurrenceDistributionProperty(ci, ne, ts);
    double prob = 0;
    for (EMV2PropertyAssociation emv2PropertyAssociation : PA) {
        prob += EMV2Properties.getOccurrenceValue(emv2PropertyAssociation);
    }
    return prob;
}
Also used : EMV2PropertyAssociation(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation)

Aggregations

EMV2PropertyAssociation (org.osate.xtext.aadl2.errormodel.errorModel.EMV2PropertyAssociation)14 TypeSet (org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)7 NamedElement (org.osate.aadl2.NamedElement)6 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)5 EMV2Path (org.osate.xtext.aadl2.errormodel.errorModel.EMV2Path)5 ErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState)5 EList (org.eclipse.emf.common.util.EList)4 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)4 ListValue (org.osate.aadl2.ListValue)4 Property (org.osate.aadl2.Property)4 PropertyExpression (org.osate.aadl2.PropertyExpression)4 RecordValue (org.osate.aadl2.RecordValue)4 EMV2PathElement (org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement)4 ErrorModelSubclause (org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause)4 ErrorTypes (org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes)4 ArrayList (java.util.ArrayList)3 Classifier (org.osate.aadl2.Classifier)3 Element (org.osate.aadl2.Element)3 StringLiteral (org.osate.aadl2.StringLiteral)3 Subcomponent (org.osate.aadl2.Subcomponent)3