Exemplo n.º 1
0
 public List<ViolationsEntry> violationsChartData(long projectId) {
   List<ViolationsEntry> violationsEntryList = new ArrayList<ViolationsEntry>();
   for (Violation violation : violationRepository.findByProjectId(projectId)) {
     violationsEntryList.add(new ViolationsEntry(violation.getDateTime()));
   }
   return violationsEntryList;
 }
Exemplo n.º 2
0
 public List<ViolationsEntry> violationsChartData() {
   List<ViolationsEntry> violationsEntryList = new ArrayList<ViolationsEntry>();
   for (Violation violation : violationRepository.findAll()) {
     violationsEntryList.add(new ViolationsEntry(violation.getDateTime()));
   }
   return violationsEntryList;
 }
Exemplo n.º 3
0
  public static Violation getViolation(String description) {
    if (violationsList == null) return null;

    Violation matchViolation = new Violation();
    for (Violation violation : violationsList) {
      if (description.equals(violation.getDescription())) {
        matchViolation = violation;
      }
    }
    return matchViolation;
  }
Exemplo n.º 4
0
 /**
  * @param plan
  * @return a list of activities and other plan elements that have violations.
  */
 public static Set<EPlanElement> getPlanElementsWithViolations(EPlan plan) {
   Set<EPlanElement> result = new HashSet();
   if (noDomainFor(plan)) {
     return Collections.EMPTY_SET;
   }
   List<ViolationTracker> trackers = PlanAdvisorMember.get(plan).getViolationTrackers();
   for (ViolationTracker tracker : trackers) {
     Violation violation = tracker.getViolation();
     if (violation.isCurrentlyViolated()) {
       result.addAll(violation.getElements());
     }
   }
   return result;
 }
  @Override
  public void process(IPatternMatch match) {

    Map<String, Object> keyObjectMap = constraint.getSpecification().getKeyObjects(match);

    if (!keyObjectMap.isEmpty()) {

      ViolationKey key = constraint.getViolationKey(match);

      Violation violation = constraint.getViolation(key);

      if (violation == null) {
        violation = new Violation();
        violation.setConstraint(constraint);
        violation.setKeyObjects(constraint.getSpecification().getKeyObjects(match));
        violation.setMessage(
            IncQueryRuntimeHelper.getMessage(
                match, constraint.getSpecification().getMessageFormat()));
        constraint.addViolation(key, violation);

        constraint.notifyListenersViolationAppeared(violation);
      }

      if (violation.addMatch(match)) {
        violation.notifyListenersViolationEntryAppeared(match);
      }
    } else {
      logger.error("Error getting Violation key objects!");
    }
  }
Exemplo n.º 6
0
  boolean checkConst(Record rec, ThreadInfo ti, FieldInfo fi, Instruction insn) {
    if (checkConst) {
      AnnotationInfo ai = insn.getMethodInfo().getAnnotation("gov.nasa.jpf.Const");
      if (ai != null) {
        violation = new Violation(rec, ti, fi, insn);
        violation.setConstErrorMessage();

        ti.breakTransition();
        return false;
      }
    }

    return true;
  }
Exemplo n.º 7
0
  boolean checkShared(Record rec, ThreadInfo ti, InfoObject use, Instruction insn) {
    if (checkShared) {
      AnnotationInfo ai = rec.ei.getClassInfo().getAnnotation("gov.nasa.jpf.NonShared");
      if (ai != null && ti != rec.tiCreate) {
        violation = new Violation(rec, ti, use, insn);
        violation.setSharedErrorMessage();

        ti.breakTransition();
        return false;
      }
    }

    return true;
  }
 /**
  * Add a new Violation to the list of violations found by this visitor. Only add the violation if
  * the node lineNumber >= 0.
  *
  * @param node - the Groovy AST Node
  * @param message - the message for the violation; defaults to null
  */
 protected void addViolation(MethodCallExpression node, String message) {
   if (node.getLineNumber() >= 0) {
     int lineNumber = AstUtil.findFirstNonAnnotationLine(node, sourceCode);
     String sourceLine = sourceCode.line(AstUtil.findFirstNonAnnotationLine(node, sourceCode) - 1);
     Violation violation = new Violation();
     violation.setRule(rule);
     violation.setLineNumber(lineNumber);
     violation.setSourceLine(sourceLine);
     if (currentClassNode != null) {
       violation.setMessage(
           String.format("Violation in class %s. %s", currentClassNode.getName(), message));
     } else {
       violation.setMessage(message);
     }
     violations.add(violation);
   }
 }
Exemplo n.º 9
0
 @Override
 public Violation build() {
   try {
     Violation record = new Violation();
     record.businessId =
         fieldSetFlags()[0] ? this.businessId : (java.lang.Integer) defaultValue(fields()[0]);
     record.date =
         fieldSetFlags()[1] ? this.date : (java.lang.CharSequence) defaultValue(fields()[1]);
     record.violationTypeID =
         fieldSetFlags()[2] ? this.violationTypeID : (java.lang.Long) defaultValue(fields()[2]);
     record.riskCategory =
         fieldSetFlags()[3]
             ? this.riskCategory
             : (java.lang.CharSequence) defaultValue(fields()[3]);
     record.description =
         fieldSetFlags()[4]
             ? this.description
             : (java.lang.CharSequence) defaultValue(fields()[4]);
     return record;
   } catch (Exception e) {
     throw new org.apache.avro.AvroRuntimeException(e);
   }
 }
Exemplo n.º 10
0
 /**
  * reads the violations from the given xml file
  *
  * <p>xml file structure is as follows
  *
  * <p><violations> <violation priority="1"> <vtext>.document</vtext> </violation>
  * ............................ </violations>
  *
  * @param violationsFilePath
  * @return
  * @throws ParserConfigurationException
  * @throws SAXException
  * @throws IOException
  */
 public static List<Violation> getViolations(File violationsFilePath)
     throws ParserConfigurationException, SAXException, IOException {
   List<Violation> violations = new ArrayList<Violation>();
   DocumentBuilder docBuilder = dbf.newDocumentBuilder();
   Document doc = docBuilder.parse(violationsFilePath);
   NodeList violationsNodeList = doc.getElementsByTagName("violation");
   int noOfNodes = violationsNodeList.getLength();
   for (int i = 0; i < noOfNodes; i++) {
     Violation violation = new Violation();
     Node violationNode = violationsNodeList.item(i);
     String priority = ((Element) violationNode).getAttribute("priority");
     if (priority == null || priority.isEmpty()) priority = "1";
     violation.setPriority(priority);
     String type = ((Element) violationNode).getAttribute("type");
     if (type != null && !type.isEmpty()) violation.setViolationType(type);
     String filetypes = ((Element) violationNode).getAttribute("filetypes");
     if (filetypes != null && !filetypes.isEmpty()) {
       for (String filetype : filetypes.split(",")) {
         violation.addFileType(filetype);
       }
     }
     Node vTextNode = ((Element) violationNode).getElementsByTagName("vtext").item(0);
     if (vTextNode != null) {
       String vText = vTextNode.getFirstChild().getNodeValue();
       violation.setViolationText(vText);
     }
     Node vRegexpNode = ((Element) violationNode).getElementsByTagName("regexp").item(0);
     if (vRegexpNode != null) {
       Node rNode = vRegexpNode.getFirstChild();
       if (rNode != null) {
         String regexp = rNode.getNodeValue();
         violation.setRegularExpression(regexp);
       }
     }
     Node vdescriptionNode = ((Element) violationNode).getElementsByTagName("description").item(0);
     if (vdescriptionNode != null) {
       Node dNode = vdescriptionNode.getFirstChild();
       if (dNode != null) {
         String description = dNode.getNodeValue();
         violation.setDescription(description);
       }
     }
     Node vSuggestionNode = ((Element) violationNode).getElementsByTagName("suggestion").item(0);
     if (vSuggestionNode != null) {
       Node sNode = vSuggestionNode.getFirstChild();
       if (sNode != null) {
         String suggestion = sNode.getNodeValue();
         violation.setSuggestion(suggestion);
       }
     }
     Node vExceptionsNode = ((Element) violationNode).getElementsByTagName("exceptions").item(0);
     if (vExceptionsNode != null) {
       NodeList regexExceptions = ((Element) vExceptionsNode).getElementsByTagName("regexp");
       for (int j = 0; j < regexExceptions.getLength(); j++) {
         Node regexExceptionNode = regexExceptions.item(j).getFirstChild();
         if (regexExceptionNode != null) {
           String regexException = regexExceptionNode.getNodeValue();
           violation.addRegexException(regexException);
         }
       }
       NodeList textExceptions = ((Element) vExceptionsNode).getElementsByTagName("vtext");
       for (int j = 0; j < textExceptions.getLength(); j++) {
         Node textExceptionNode = textExceptions.item(j).getFirstChild();
         if (textExceptionNode != null) {
           String regexException = textExceptionNode.getNodeValue();
           violation.addTextException(regexException);
         }
       }
     }
     Node vExclusionlistNode =
         ((Element) violationNode).getElementsByTagName("exclusionlist").item(0);
     if (vExclusionlistNode != null) {
       NodeList excludeList = ((Element) vExclusionlistNode).getElementsByTagName("exclude");
       for (int j = 0; j < excludeList.getLength(); j++) {
         Node excludeListNode = excludeList.item(j).getFirstChild();
         if (excludeListNode != null) {
           String excludeListName = excludeListNode.getNodeValue();
           violation.addExclusionlist(excludeListName);
         }
       }
     }
     violations.add(violation);
   }
   violationsList = violations;
   return violations;
 }
Exemplo n.º 11
0
  private void materialiseMultiStage(
      MultiStageUpperProgram program,
      Treatment4Classification treatment,
      GapByStore4ID_registerInfoAboutInstantiationIndividualsOnly gap) {
    String programName = "multi-stage upper program";
    Logger_MORe.logInfo(name + " store is materialising " + programName + " ...");
    Timer t = new Timer();

    long tripleCountBeforeMat = 0;

    program.saveDatalogRules(Utility_PAGOdA.TempDirectory + "/multi_datalog.dlog");

    Collection<Violation> violations = null;
    int iteration = 0;
    Timer subTimer = new Timer();
    boolean incrementally = false;
    try {
      while (true) {
        long oldTripleCount = store.getTriplesCount();

        subTimer.reset();
        Logger_MORe.logInfo("Iteration " + ++iteration + ": ");

        incrementally = (iteration != 1);

        if (incrementally) gap.compileFromFile(null);
        else {
          tripleCountBeforeMat = oldTripleCount;
          gap.compileFromFile(new File(Utility_PAGOdA.TempDirectory + "/multi_datalog.dlog"));
        }
        //				Utility.printStoreToFile(store, "multistageMaterialisationIter"+iteration);
        //				Utility.printPredicatesSummaryOfStoreToFile(store,
        // "multistageMaterialisationIter"+iteration);
        Utility.printAllTriples(getDataStore());
        gap
            .registerGapTuples(); // PAGOdA does not add the gap when doing multistage because the
                                  // multistage store cannot be used for tracking, but we want to
                                  // register
        // which instantiation individuals have a gap and which don't to detect classes that may be
        // fully classified at this point.
        // this is an alternative to addGapBackTo that registers information about which
        // instantiation individuals have a gap but
        // doesn't add gap tuples to the store.

        long tripleCount = store.getTriplesCount();
        Logger_MORe.logDebug(
            name
                + " store after materialising datalog-rules: "
                + tripleCount
                + " ("
                + (tripleCount - oldTripleCount)
                + " new)");
        Logger_MORe.logDebug("Time to materialise datalog-rules: " + subTimer.duration());

        subTimer.reset();
        if ((violations = program.isIntegrated(this, incrementally)) == null
            || violations.size() == 0) {
          store.clearRulesAndMakeFactsExplicit();
          Logger_MORe.logDebug(
              name
                  + " store after materialising "
                  + programName
                  + ": "
                  + tripleCount
                  + " ("
                  + (tripleCount - tripleCountBeforeMat)
                  + " new)");
          Logger_MORe.logInfo(
              name
                  + " store is DONE for multi-stage materialising in "
                  + t.duration()
                  + " seconds.");
          return;
        }
        Logger_MORe.logDebug("Time to detect violations: " + subTimer.duration());

        store.makeFactsExplicit();

        subTimer.reset();
        oldTripleCount = store.getTriplesCount();
        for (Violation v : violations) {
          Timer localTimer = new Timer();
          int number = v.size();
          long vOldCounter = store.getTriplesCount();

          treatment.makeSatisfied(v, gap);

          Logger_MORe.logDebug(
              "Time to make the constraint being satisfied: "
                  + localTimer.duration()
                  + " "
                  + number
                  + " tuples for "
                  + v.getConstraint());
          Logger_MORe.logDebug(
              "tuple number: "
                  + v.size()
                  + " before: "
                  + vOldCounter
                  + " after: "
                  + store.getTriplesCount()
                  + " ("
                  + (store.getTriplesCount() - vOldCounter)
                  + " new) .");
        }
        Logger_MORe.logDebug(
            name
                + " store after adding facts for violations: "
                + (tripleCount = store.getTriplesCount())
                + " ("
                + (tripleCount - oldTripleCount)
                + " new)");
        Logger_MORe.logDebug("Time to add triples for violations: " + subTimer.duration());
      }
    } catch (JRDFStoreException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 12
0
  protected Set<?>[] materialise(
      MultiStageUpperProgram4Classification program,
      Treatment treatment,
      boolean registerPredicatesWithGap) {
    // based on materialise(MultiStageUpperProgram, Treatment, GapByStore4ID)

    Set<?>[] ret = new Set<?>[3];
    if (registerPredicatesWithGap) {
      ret[0] = new HashSet<OWLClass>(); // classes with candidate subsumers
      ret[1] = new HashSet<String>(); // potentiallyUnsatClasses
      ret[2] = new HashSet<String>(); // candidate subsumers // do I even need to store these?
    }

    String programName = "multi-stage upper program";
    Logger_MORe.logInfo(name + " store is materialising " + programName + " ...");
    Timer t = new Timer();

    long tripleCountBeforeMat = 0;

    Collection<Violation> violations = null;
    int iteration = 0;
    Timer subTimer = new Timer();
    boolean incrementally = false;
    TupleIterator iter = null;
    try {
      while (true) {
        long oldTripleCount = store.getTriplesCount();

        subTimer.reset();
        Logger_MORe.logInfo("Iteration " + ++iteration + ": ");

        incrementally = (iteration != 1);

        if (incrementally) store.setNumberOfThreads(1);
        else {
          tripleCountBeforeMat = oldTripleCount;
          store.importFiles(
              new File[] {new File(program.getOutputPath())}, new Prefixes(), UpdateType.Add, true);
        }
        store.applyReasoning(incrementally);
        store.setNumberOfThreads(matNoOfThreads);

        if (registerPredicatesWithGap) {
          // here we are basically imitating GapByStore4ID, can't we just add the relevant methods
          // to that class and use it class here?

          try {
            iter =
                internal_evaluateAgainstIDBs(
                    "select ?x ?z where { ?x "
                        + MyPrefixes.PAGOdAPrefixes.expandText("rdf:type")
                        + " ?z . }");
            for (long multi = iter.open(); multi != 0; multi = iter.getNext()) {
              OWLClass c =
                  indManager.getClass4Individual(
                      RDFoxTripleManager.getRawTerm(iter.getResource(0)));
              if (c != null) {
                String s = RDFoxTripleManager.getRawTerm(iter.getResource(1));
                if (s.equals(MyPrefixes.PAGOdAPrefixes.expandText("owl:Nothing"))) {
                  ((Set<String>) ret[1]).add(RDFoxTripleManager.getRawTerm(iter.getResource(0)));
                  ((Set<OWLClass>) ret[0]).add(c);
                } else {
                  ((Set<OWLClass>) ret[0]).add(c);
                  ((Set<String>) ret[2]).add(RDFoxTripleManager.getRawTerm(iter.getResource(1)));
                }
              }
            }
          } catch (JRDFStoreException e) {
            e.printStackTrace();
            if (iter != null) iter.dispose();
          } finally {
            if (iter != null) iter.dispose();
          }
        }

        long tripleCount = store.getTriplesCount();
        Logger_MORe.logDebug(
            name
                + " store after materialising datalog-rules: "
                + tripleCount
                + " ("
                + (tripleCount - oldTripleCount)
                + " new)");
        Logger_MORe.logDebug("Time to materialise datalog-rules: " + subTimer.duration());

        subTimer.reset();
        // TODO revise this chunk to make sure inconsistencies do not make us stop materialising
        // FIXME
        if ((violations = program.isIntegrated(this, incrementally)) == null
            || violations.size() == 0) {
          store.clearRulesAndMakeFactsExplicit();
          Logger_MORe.logDebug(
              name
                  + " store after materialising "
                  + programName
                  + ": "
                  + tripleCount
                  + " ("
                  + (tripleCount - tripleCountBeforeMat)
                  + " new)");
          Logger_MORe.logInfo(
              name
                  + " store is DONE for multi-stage materialising in "
                  + t.duration()
                  + " seconds.");
          return ret; // isValid() ? 1 : 0;
        }
        Logger_MORe.logDebug("Time to detect violations: " + subTimer.duration());

        store.makeFactsExplicit();

        //				first.printAllTriples(getDataStore());

        subTimer.reset();
        oldTripleCount = store.getTriplesCount();
        for (Violation v : violations) {
          Timer localTimer = new Timer();
          int number = v.size();
          long vOldCounter = store.getTriplesCount();

          if (registerPredicatesWithGap) {
            for (AnswerTuple tuple :
                ((Treatment4Classification) treatment).makeSatisfiedAndReturnAddedTuples(v)) {
              OWLClass c = indManager.getClass4Individual(tuple.getRawTerm(0));
              if (c != null) {
                String s = tuple.getRawTerm(1);
                if (s.equals(MyPrefixes.PAGOdAPrefixes.expandText("owl:Nothing"))) {
                  ((Set<String>) ret[1]).add(tuple.getRawTerm(0));
                  ((Set<OWLClass>) ret[0]).add(c);
                } else {
                  ((Set<OWLClass>) ret[0]).add(c);
                  ((Set<String>) ret[2]).add(tuple.getRawTerm(1));
                }
              }
            }
          } else {
            if (!treatment.makeSatisfied(v)) {
              //						validMaterialisation = false;
              //						Utility.logInfo(name + " store FAILED for multi-stage materialisation in " +
              // t.duration() + " seconds.");
              Logger_MORe.logInfo(
                  name
                      + " store could not make violation satisfied for multi-stage materialisation, but we'll keep going!.");
              //						return 0;
            }
          }

          Logger_MORe.logDebug(
              "Time to make the constraint being satisfied: "
                  + localTimer.duration()
                  + " "
                  + number
                  + " tuples for "
                  + v.getConstraint());
          Logger_MORe.logDebug(
              "tuple number: "
                  + v.size()
                  + " before: "
                  + vOldCounter
                  + " after: "
                  + store.getTriplesCount()
                  + " ("
                  + (store.getTriplesCount() - vOldCounter)
                  + " new) .");
        }
        Logger_MORe.logDebug(
            name
                + " store after adding facts for violations: "
                + (tripleCount = store.getTriplesCount())
                + " ("
                + (tripleCount - oldTripleCount)
                + " new)");
        Logger_MORe.logDebug("Time to add triples for violations: " + subTimer.duration());
      }
    } catch (JRDFStoreException e) {
      e.printStackTrace();
    }
    return ret;
  }
Exemplo n.º 13
0
 protected void exception(String path, String detail, Throwable t) {
   Violation violation = new Violation(Severity.ERROR, path, detail, t);
   violation.setVerifierInfo(this);
   violationListener.reportViolation(violation);
 }
Exemplo n.º 14
0
 protected void error(String path, String detail) {
   Violation violation = new Violation(Severity.ERROR, path, detail);
   violation.setVerifierInfo(this);
   violationListener.reportViolation(violation);
 }
Exemplo n.º 15
0
 protected void warning(String path, String detail) {
   Violation violation = new Violation(Severity.WARNING, path, detail);
   violation.setVerifierInfo(this);
   violationListener.reportViolation(violation);
 }