Exemplo n.º 1
0
  @Override
  public boolean hasChanged(Field field) {
    final Map<Integer, Field> savedFields = new HashMap<Integer, Field>();
    if (field != null)
      for (Field subfield : field.getFields()) savedFields.put(subfield.getId(), subfield);

    for (StructureHolder holder : oneToMany.getSelected()) {
      // Field has never been saved, if there are changes, let's save.
      if (holder.getField() == null || holder.getField().getId() == 0) {
        if (holder.hasChanged()) {
          Debug.println("NEW: {0} says it has changed", holder.getStructure().getClass().getName());
          return true;
        } else return false;
      } else {
        // We are working with previously saved data that could have changed.
        Field dataField = savedFields.remove(holder.getField().getId());
        if (dataField == null) { // How??
          Debug.println("OneToMany hasChanged badness, save to clean up.");
          return true;
        }

        if (holder.getStructure().hasChanged(dataField)) {
          Debug.println("OLD: {0} says it has changed", holder.getStructure().getClass().getName());
          return true;
        }
      }
    }

    return !savedFields.isEmpty();
  }
Exemplo n.º 2
0
  public static ClientUser buildUserFromProfile(NativeDocument profile, String username) {
    NativeElement root = profile.getDocumentElement();
    ClientUser currentUser = new ClientUser();
    currentUser.setUsername(username);

    // backwards compatibility for the moment...
    if (root.getElementsByTagName("creds").getLength() != 0) {
      Debug.println("Profile detected Old version...");
      currentUser.setFirstName(root.getElementByTagName("first").getTextContent());
      currentUser.setLastName(root.getElementByTagName("last").getTextContent());
      currentUser.setAffiliation(root.getElementByTagName("affiliation").getTextContent());
    } else {
      Debug.println("Profile detected New shiny version!");
      NativeNodeList nodes = root.getChildNodes();
      for (int i = 0; i < nodes.getLength(); i++) {
        NativeNode curNode = nodes.item(i);
        if (curNode.getNodeType() != NativeNode.ELEMENT_NODE) continue;
        String name = curNode.getNodeName();
        if (name.equals(NewAccountPanel.EMAIL_KEY)) currentUser.setEmail(curNode.getTextContent());
        else if (name.equals(NewAccountPanel.FIRSTNAME_KEY))
          currentUser.setFirstName(curNode.getTextContent());
        else if (name.equals(NewAccountPanel.LASTNAME_KEY))
          currentUser.setLastName(curNode.getTextContent());
        else if (name.equals(NewAccountPanel.AFFILIATION_KEY))
          currentUser.setAffiliation(curNode.getTextContent());
        else currentUser.setProperty(name, curNode.getTextContent());
      }
      if (root.getElementByTagName("quickGroup") == null)
        currentUser.setProperty("quickGroup", "rlu");
    }

    return currentUser;
  }
Exemplo n.º 3
0
  public static Document getField(String fieldName) {
    final VFSPathToken token = new VFSPathToken(fieldName + ".xml");
    if (SIS.get().getVFS().exists(FIELDS_DIR.child(token))) {
      try {
        return getInputStreamFile(SIS.get().getVFS().getInputStream(FIELDS_DIR.child(token)));
      } catch (IOException e) {
        Debug.println("Field {0} reported existence, but could not be loaded:\n{1}", fieldName, e);
      }
    }

    return getInputStreamFile(DocumentLoader.class.getResourceAsStream(fieldName + ".xml"));
  }
Exemplo n.º 4
0
  public static Document getView() {
    final VFSPathToken token = new VFSPathToken("views.xml");
    if (SIS.get().getVFS().exists(FIELDS_DIR.child(token))) {
      try {
        return SIS.get().getVFS().getMutableDocument(FIELDS_DIR.child(token));
      } catch (IOException e) {
        Debug.println("View reported existence, but could not be loaded:\n{0}", e);
      }
    }

    return BaseDocumentUtils.impl.getInputStreamFile(
        DocumentLoader.class.getResourceAsStream("views.xml"));
  }
Exemplo n.º 5
0
 public static java.util.Iterator iterateInfratypeByQuery(
     Session session, String condition, String orderBy) throws PersistentException {
   StringBuffer sb = new StringBuffer("From Infratype as Infratype");
   if (condition != null) sb.append(" Where ").append(condition);
   if (orderBy != null) sb.append(" Order By ").append(orderBy);
   try {
     Query query = session.createQuery(sb.toString());
     return query.iterate();
   } catch (Exception e) {
     Debug.println(e);
     throw new PersistentException(e);
   }
 }
Exemplo n.º 6
0
 public static Infratype[] listInfratypeByQuery(Session session, String condition, String orderBy)
     throws PersistentException {
   StringBuffer sb = new StringBuffer("From Infratype as Infratype");
   if (condition != null) sb.append(" Where ").append(condition);
   if (orderBy != null) sb.append(" Order By ").append(orderBy);
   try {
     Query query = session.createQuery(sb.toString());
     List list = query.list();
     return (Infratype[]) list.toArray(new Infratype[list.size()]);
   } catch (Exception e) {
     Debug.println(e);
     throw new PersistentException(e);
   }
 }
  public void ensureEvaluated(WorkingSet workingSet) throws WorkflowManagerException {
    final Collection<Assessment> assessments =
        WorkflowManager.getAllAssessments(session, workingSet);
    Debug.println("Ensuring evaluation on " + assessments.size() + " assessments...");

    final String table = "RedListEvaluated";
    final Collection<String> failedSpecies = new ArrayList<String>();
    for (Assessment data : assessments) {
      // final String uid = data.getAssessmentID() + "_" + AssessmentType.DRAFT_ASSESSMENT_TYPE;
      final String uid = "" + data.getId();

      final SelectQuery query = new SelectQuery();
      query.select(table, "asm_id");
      query.constrain(
          new CanonicalColumnName(table, "is_evaluated"), QConstraint.CT_EQUALS, "true");
      query.constrain(
          QConstraint.CG_AND,
          new CanonicalColumnName(table, "approval_status"),
          QConstraint.CT_EQUALS,
          Integer.valueOf(1));
      query.constrain(
          QConstraint.CG_AND, new CanonicalColumnName(table, "uid"), QConstraint.CT_EQUALS, uid);

      final Row.Loader rl = new Row.Loader();

      try {
        ec.doQuery(query, rl);
      } catch (DBException e) {
        failedSpecies.add(data.getSpeciesName());
        continue;
      }

      if (rl.getRow() == null) failedSpecies.add(data.getSpeciesName());
    }

    if (!failedSpecies.isEmpty()) {
      final StringBuilder builder = new StringBuilder();
      builder.append("The following species have not yet been marked as evaluted: ");
      for (Iterator<String> iter = failedSpecies.iterator(); iter.hasNext(); )
        builder.append(iter.next() + (iter.hasNext() ? ", " : ""));
      throw new WorkflowManagerException(builder.toString());
    }
  }