public static List<GraphEntity> getEntities(Browser b, String typeName) { List<GraphEntity> result = new ArrayList<GraphEntity>(); for(GraphEntity ge: b.getAllEntities()) { if(ge.getType().equals(typeName)) { result.add(ge); } } return result; }
public static boolean hasAnyEntity(Browser b, String typeName) { boolean result = false; for(GraphEntity ge: b.getAllEntities()) { if(ge.getType().equals(typeName)) { result = true; break; } } return result; }
/** * It obtains the entities in the graph "g" whose type is the same as * "typeName". * * @param g The graph considered * @param typeName The type being searched * @return The list of entities * @throws NullEntity */ public static List<GraphEntity> getEntities(Graph g, String typeName) throws NullEntity { GraphEntity[] ge = g.getEntities(); List<GraphEntity> result = new ArrayList<>(); for (int k = 0; k < ge.length; k++) { if (ge[k].getType().equals(typeName)) { result.add(ge[k]); } } return result; }
public static void addPararms(Graph adlSpec, Repeat repFather) throws NullEntity { for (GraphEntity act : adlSpec.getEntities()) { if (act.getType().equals(ACTIVITY_TYPE)) { addPararms(act, repFather); } } }
public static Vector<GraphEntity> getProfilesTypeOf(String humanId, String profileType, Browser browser) { Vector<GraphEntity> result = new Vector<GraphEntity>(); try { GraphEntity[] entities = browser.getAllEntities(); for (GraphEntity adl : entities) { if (adl.getType().equalsIgnoreCase(profileType)) { GraphEntity human = Utils.getTargetEntity(adl, "ProfileOf"); if (human != null && human.getID().equals(humanId)) { result.add(adl); } } } } catch (Throwable ex) { ex.printStackTrace(); } return result; }
public static GraphEntity getProfileTypeOf(String humanId, String profileType, Browser browser) { GraphEntity result = null; try { GraphEntity[] entities = browser.getAllEntities(); for (GraphEntity adl : entities) { if (adl.getType().equalsIgnoreCase(profileType)) { GraphEntity human = Utils.getTargetEntity(adl, "ProfileOf"); if (human != null && human.getID().equals(humanId)) { return adl; } } } } catch (Throwable ex) { ex.printStackTrace(); } return result; }
private void generateTransitions(Graph adlSpec, Repeat repFather) throws NullEntity { for (GraphEntity activity : adlSpec.getEntities()) { if (activity.getType().equals(ACTIVITY_TYPE)) { generateDirectTransitions(activity, repFather); generateCondTransitions(activity, repFather); } } }
public static GraphEntity getFirstEntity(Graph graph, String type) { GraphEntity result = null; try { for (GraphEntity ge : graph.getEntities()) { if (!isTargetOfAnyRelationship(ge) && ge.getType().equals(type)) { return ge; } } } catch (NullEntity e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
/** * It obtains all entities in the specification whose type represented as * string is the same as the string passed as parameter * * @param type The type the application is looking for * @return * @throws NotInitialised */ public static GraphEntity[] generateEntitiesOfType(String type, Browser browser) throws NotInitialised { Graph[] gs = browser.getGraphs(); Sequences p = new Sequences(); GraphEntity[] ges = browser.getAllEntities(); HashSet actors = new HashSet(); for (int k = 0; k < ges.length; k++) { if (ges[k].getType().equals(type)) { actors.add(ges[k]); } } return toGEArray(actors.toArray()); }
public static GraphEntity getADL(String humanId, Browser browser) { GraphEntity result = null; try { GraphEntity[] entities = browser.getAllEntities(); for (GraphEntity adl : entities) { if (adl.getType().equalsIgnoreCase(ADLProfile_SPEC_DIAGRAM)) { Vector<GraphRelationship> rels = adl.getAllRelationships("ProfileOf"); for (GraphRelationship rel : rels) { GraphEntity connectedHuman = Utils.getTargetEntity(adl, rel); if (connectedHuman != null && connectedHuman.getID().equalsIgnoreCase(humanId)) { return adl; } } } } } catch (Throwable ex) { ex.printStackTrace(); } return result; } }
public static Vector<String> findAllDifferences(Browser bimp1, Browser bimp2){ GraphEntity[] entities = bimp1.getAllEntities(); boolean allIncluded=true; Vector<String> differences=new Vector<String>(); int k=0; while (k<entities.length){ GraphEntity ent1 = entities[k]; GraphEntity ent2 = bimp2.findEntity(ent1.getID()); allIncluded=allIncluded && ent2!=null; if (ent2==null){ differences.add("entity "+ent1.getID()+":"+ent1.getType()+" does not exist"); } else { differences.addAll(checkEntity(ent1, ent2, new Vector())); } k++; } return differences; }
private void generateCondTransitions(GraphEntity activity, Repeat repFather) { for (GraphEntity previousIf : Utils.getSourcesEntity(activity, TRUE_FLOW_REL)) { if (previousIf.getType().equals(IF_FLOW_CONTROL_TYPE)) { propagateCond(activity, previousIf, "new CompositeAndCondition(" + Utils.replaceBadChars(previousIf.getID()) + ")", repFather); } } for (GraphEntity previousIf : Utils.getSourcesEntity(activity, FALSE_FLOW_REL)) { if (previousIf.getType().equals(IF_FLOW_CONTROL_TYPE)) { propagateCond(activity, previousIf, "new NegateCondition(new CompositeAndCondition(" + Utils.replaceBadChars(previousIf.getID()) + "))", repFather); } } }
private Repeat createNewProgState(GraphEntity progState) { Repeat progStateRep = new Repeat("progStates"); System.out.println("\t\tProgState: " + progState.getID() + ":" + progState.getType()); progStateRep.add(new Var("psID", Utils.replaceBadChars(progState.getID()))); progStateRep.add(new Var("psType", Utils.replaceBadChars(progState.getType()))); progStateRep.add(new Var("psDesc", Utils.getAttributeByName(progState, "Description"))); return progStateRep; } }
public void generateActivities(Graph activitiesSpec, Sequences seq) throws NotFound, NullEntity { GraphEntity ge = Utils.getFirstEntity(activitiesSpec); if (ge.getType().equals("BActivity")) { GraphEntity nActivity = Utils.getTargetEntity(ge, "NextActivity"); if (nActivity == null) { return; } GraphAttribute ga = ge.getAttributeByName("SeqTaskDiagramField"); Graph taskSpecDiagram = Utils.getGraphByName(ga.getSimpleValue(), getBrowser()); /*if (taskSpecDiagram != null) { TaskGenerator taskGenerator = new TaskGenerator(getBrowser(), seq); taskGenerator.generate("", taskSpecDiagram); }*/ } }
private Vector<Graph> getPDDiagramsForActor(GraphEntity actor) { Vector<Graph> patientGraphs = new Vector<Graph>(); Vector<GraphRelationship> rels = actor.getAllRelationships("ProfileOf"); for (GraphRelationship rel : rels) { GraphEntity target; try { target = Utils.getSourceEntity(actor, rel); if (target.getType().equals("ParkinsonsProfile")) { GraphAttribute diagNameAtt = target.getAttributeByName("ParkinsonSpecDiag"); if (diagNameAtt != null && diagNameAtt.getSimpleValue() != null && browser.getGraph(diagNameAtt.getSimpleValue()) != null) { patientGraphs.add(browser.getGraph(diagNameAtt.getSimpleValue())); } } } catch (NotFound e) { // TODO Auto-generated catch block e.printStackTrace(); } } return patientGraphs; }
private void propagateCond(GraphEntity targetActivity, GraphEntity cIf, String condition, Repeat repFather) { Collection<GraphEntity> entities = Utils.getSourcesEntity(cIf, NEXT_ACTIVITY_REL); if (!entities.isEmpty()) { for (GraphEntity previousAct : entities) { regCondTrans(Utils.replaceBadChars(previousAct.getID()), Utils.replaceBadChars(targetActivity.getID()), condition, repFather, false); } } else { regCondTrans("Empty", Utils.replaceBadChars(targetActivity.getID()), condition, repFather, false); } for (GraphEntity previousIf : Utils.getSourcesEntity(cIf, TRUE_FLOW_REL)) { if (previousIf.getType().equals(IF_FLOW_CONTROL_TYPE)) { propagateCond(targetActivity, previousIf, condition + ".add(" + Utils.replaceBadChars(previousIf.getID()) + ")", repFather); } } for (GraphEntity previousIf : Utils.getSourcesEntity(cIf, FALSE_FLOW_REL)) { if (previousIf.getType().equals(IF_FLOW_CONTROL_TYPE)) { propagateCond(targetActivity, previousIf, condition + ".add(" + "new NegateCondition(" + Utils.replaceBadChars(previousIf.getID()) + "))", repFather); } } }
public void generateActivityClasses(Sequences seq) throws NullEntity, NotFound { for (GraphEntity ge : browser.getAllEntities()) { if (ge.getType().equals(ACTIVITY_TYPE)) { GraphAttribute ga = ge .getAttributeByName(SEQ_TASK_DIAGRAM_FIELD); if (ga != null) { String actDiagId = Utils.replaceBadChars(ga.getSimpleValue()); if (actDiagId != null && !actDiagId.equals("")) { Repeat rep = new Repeat("activities"); seq.addRepeat(rep); rep.add(new Var("aID", Utils.replaceBadChars(ge.getID()))); rep.add(new Var("aType", Utils.replaceBadChars(ge.getType()))); rep.add(new Var("aDesc", Utils.getAttributeByName(ge, "Description"))); rep.add(new Var("stID", Utils.replaceBadChars(actDiagId))); continue; } } logger.log(Level.SEVERE, "The {0} activity doesn't have sequential task diagram!", new Object[]{ge.getID()}); System.exit(0); } } }
private void generateDirectTransitions(GraphEntity activity, Repeat repFather) { for (GraphEntity previousAct : Utils.getSourcesEntity(activity, NEXT_ACTIVITY_REL)) { if (previousAct.getType().equals(ACTIVITY_TYPE)) { // registers a transition between activities without any // condition Repeat rep2 = new Repeat("regTrans"); repFather.add(rep2); rep2.add(new Var("actSource", Utils.replaceBadChars(previousAct.getID()))); rep2.add(new Var("actTarget", Utils.replaceBadChars(activity.getID()))); } } }
private void generateCondition(Graph adlSpec, Repeat repFather) throws NullEntity { for (GraphEntity condition : adlSpec.getEntities()) { if (condition.getType().equals(IF_FLOW_CONTROL_TYPE)) { Collection<GraphEntity> conds = Utils.getTargetsEntity(condition, IF_FLOW_COND_REL); String condSentence = ConditionGenerator.generateAndCondition(conds); String condId = Utils.replaceBadChars(condition.getID()); Repeat conditions = new Repeat("conditions"); repFather.add(conditions); conditions.add(new Var("condId", condId)); conditions.add(new Var("condInst", condSentence)); } } }
private void generateActivityInstances(Graph adlSpec, Repeat repFather) throws NullEntity { for (GraphEntity activity : adlSpec.getEntities()) { if (activity.getType().equals(ACTIVITY_TYPE)) { String activityName = activity.getID(); // Defines the activity Repeat rep = new Repeat("activities"); repFather.add(rep); rep.add(new Var("actName", Utils.replaceBadChars(activityName))); Collection<GraphEntity> nextEntities = Utils.getTargetsEntity(activity, NEXT_ACTIVITY_REL); if (nextEntities.isEmpty()) { // It is a last activity, the automaton should finish after the execution Repeat rep2 = new Repeat("regLastActivityRep"); repFather.add(rep2); rep2.add(new Var("finalActivity", Utils.replaceBadChars(activityName))); } } } }