Exemplo n.º 1
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.º 2
0
  public void parse(NativeElement rootTag) {

    NativeNodeList orgs = rootTag.getElementsByTagName("organization");

    for (int i = 0; i < orgs.getLength(); i++) {
      NativeElement curTag = orgs.elementAt(i);
      Organization organization =
          new Organization(
              curTag.getAttribute("title"), curTag.getAttribute("shortTitle"), curTag, true);

      organizations.add(organization);
    }
  }
Exemplo n.º 3
0
  public void fillTable() {
    table.removeAll();
    String fetchList = "";
    for (int i = start; i < start + NUMBER_OF_RESULTS && i < currentResults.getLength(); i++)
      fetchList += ((NativeElement) currentResults.item(i)).getAttribute("id") + ",";

    if (fetchList.length() > 0)
      TaxonomyCache.impl.fetchList(
          fetchList,
          new GenericCallback<String>() {
            public void onFailure(Throwable arg0) {
              WindowUtils.hideLoadingAlert();
              WindowUtils.errorAlert("Error loading results. Inconsistency in index table.");
            }

            public void onSuccess(String arg0) {
              List<String> assessmentList = new ArrayList<String>();
              final String[][] x = new String[20][7];
              for (int i = start;
                  i < start + NUMBER_OF_RESULTS && i < currentResults.getLength();
                  i++) {
                TaxonNode currentNode =
                    TaxonomyCache.impl.getNode(
                        ((NativeElement) currentResults.item(i)).getAttribute("id"));

                x[i - start][0] = currentNode.getFullName();
                if (currentNode.getCommonNames().size() > 0)
                  x[i - start][1] = (currentNode.getCommonNames().get(0)).getName().toLowerCase();
                else x[i - start][1] = "";
                x[i - start][2] = TaxonNode.getDisplayableLevel(currentNode.getLevel());
                x[i - start][4] = String.valueOf(currentNode.getId());
                if (currentNode.getAssessments().size() > 0) {
                  x[i - start][3] = String.valueOf(currentNode.getAssessments().get(0));
                  assessmentList.add(
                      currentNode.getAssessments().get(0)
                          + "_"
                          + BaseAssessment.PUBLISHED_ASSESSMENT_STATUS);
                } else x[i - start][3] = "N/A";
                if (currentNode.getFootprint().length >= 5)
                  x[i - start][5] = currentNode.getFootprint()[4];
                else x[i - start][5] = "N/A";
                if (currentNode.getFootprint().length >= 6)
                  x[i - start][6] = currentNode.getFootprint()[5];
                else x[i - start][5] = "N/A";
              }

              AssessmentCache.impl.fetchAssessments(
                  new AssessmentFetchRequest(assessmentList, null),
                  new GenericCallback<String>() {
                    public void onFailure(Throwable caught) {
                      for (int i = start;
                          i < start + NUMBER_OF_RESULTS && i < currentResults.getLength();
                          i++) {
                        x[i - start][3] = "N/A";
                        TableItem tItem = new TableItem(x[i - start]);
                        table.add(tItem);
                      }
                      // x[i-start][3] = "N/A";
                      // SysDebugger.getInstance().println("FAILURES!");
                      SysDebugger.getInstance().println(caught.getMessage());

                      layout();
                    }

                    public void onSuccess(String result) {
                      for (int i = start;
                          i < start + NUMBER_OF_RESULTS && i < currentResults.getLength();
                          i++) {
                        AssessmentData aData =
                            AssessmentCache.impl.getPublishedAssessment(x[i - start][3], false);
                        if (aData == null) x[i - start][3] = "N/A";
                        else x[i - start][3] = aData.getProperCategoryAbbreviation();
                        TableItem tItem = new TableItem(x[i - start]);
                        table.add(tItem);
                      }

                      layout();
                    }
                  });
            }
          });
  }
  private String batchCreate(Request request, String username) {
    NativeDocument doc = NativeDocumentFactory.newNativeDocument();
    StringBuffer successfulIDs = new StringBuffer();
    StringBuffer extantIDs = new StringBuffer();
    StringBuffer unsuccessfulIDs = new StringBuffer();

    try {
      String text = request.getEntity().getText();
      doc.parse(text);

      AssessmentFilter filter =
          AssessmentFilter.parseXML(
              doc.getDocumentElement()
                  .getElementsByTagName(AssessmentFilter.HEAD_TAG)
                  .elementAt(0));

      NativeNodeList nodes = doc.getDocumentElement().getElementsByTagName("taxon");
      boolean useTemplate =
          Boolean.parseBoolean(
              doc.getDocumentElement()
                  .getElementsByTagName("useTemplate")
                  .elementAt(0)
                  .getTextContent());
      System.out.println("Using template? " + useTemplate);

      for (int i = 0; i < nodes.getLength(); i++) {
        TaxonNode taxon = TaxaIO.readNode(nodes.elementAt(i).getTextContent(), vfs);
        AssessmentData curAss = null;

        curAss =
            doCreateAssessmentForBatch(
                request.getChallengeResponse().getIdentifier(), filter, useTemplate, taxon);

        try {
          AssessmentIOWriteResult result = assignIDAndSave(curAss, username);
          if (result.status.isSuccess())
            successfulIDs.append(
                curAss.getSpeciesName() + (i == nodes.getLength() - 1 ? "" : ", "));
          else
            unsuccessfulIDs.append(
                curAss.getSpeciesName() + (i == nodes.getLength() - 1 ? "" : ", "));
        } catch (RegionConflictException e) {
          extantIDs.append(curAss.getSpeciesName() + (i == nodes.getLength() - 1 ? "" : ", "));
        }
      }

      StringBuilder ret = new StringBuilder();
      if (unsuccessfulIDs.length() > 0)
        ret.append(
            "<div>Unable to create an assessment for the following species: "
                + unsuccessfulIDs
                + "</div>\r\n");
      if (extantIDs.length() > 0)
        ret.append(
            "<div>The following species already have draft assessments with the specific locality: "
                + extantIDs
                + "</div>\r\n");
      if (successfulIDs.length() > 0)
        ret.append(
            "<div>Successfully created an assessment for the following species: "
                + successfulIDs
                + "</div>\r\n");

      return ret.toString();
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    } catch (NullPointerException e) {
      e.printStackTrace();
      return null;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
  /**
   * Assumes that: - Users have already been converted - Working Sets have already been converted -
   * Working Set IDs have remained the same.
   */
  protected void run() throws Exception {
    userIO = new UserIO(session);
    relationshipIO = new RelationshipIO(session);
    taxonIO = new TaxonIO(session);

    if (isTestMode()) print("### RUNNING IN TEST MODE ###");

    final WorkingSetIO wsIO = new WorkingSetIO(session);

    for (VFSPathToken token : data.getOldVFS().list(new VFSPath("/users"))) {
      final User user = userIO.getUserFromUsername(token.toString());
      if (user == null) printf("## No user exists for data directory %s ==", token);
      else {
        Hibernate.initialize(user.getSubscribedWorkingSets());

        final VFSPath workingSetPath =
            new VFSPath("/users/" + user.getUsername() + "/workingSet.xml");
        final NativeDocument document = new JavaNativeDocument();
        try {
          document.parse(data.getOldVFS().getString(workingSetPath));
        } catch (Exception e) {
          continue;
        }

        printf("== Finding working sets for %s (%s) ==", user.getUsername(), user.getId());

        final NativeNodeList nodes = document.getDocumentElement().getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
          NativeNode node = nodes.item(i);
          if ("public".equals(node.getNodeName())) {
            NativeNodeList children = node.getChildNodes();
            for (int k = 0; k < children.getLength(); k++) {
              NativeNode child = children.item(k);
              if ("workingSet".equals(child.getNodeName())) {
                NativeElement el = (NativeElement) child;
                String id = el.getAttribute("id");
                String creator = el.getAttribute("creator");

                if (!user.getUsername().equals(creator)) {
                  boolean success = wsIO.subscribeToWorkingSet(Integer.valueOf(id), user);
                  if (!success) printf("# Failed to subscribe to ws %s", id);
                  else {
                    printf("Subscribed to ws %s", id);
                    /*if (count.incrementAndGet() % 50 == 0) {
                    	printf("Converted %s working set subscriptions...", count.get());
                    	commitAndStartTransaction();
                    }*/
                  }
                }
              }
            }
          } else if ("private".equals(node.getNodeName())) {
            NativeNodeList children = node.getChildNodes();
            for (int k = 0; k < children.getLength(); k++) {
              NativeNode child = children.item(k);
              if ("workingSet".equals(child.getNodeName())) {
                WorkingSetData data =
                    new WorkingSetParser().parseSingleWorkingSet((NativeElement) node);
                if ("".equals(data.getId())) {
                  continue;
                }
                WorkingSet privateWS =
                    WorkingSetConverter.convertWorkingSetData(
                        data, session, relationshipIO, userIO, taxonIO, user);
                if (privateWS != null) {
                  printf("Created private working set %s", privateWS.getName());
                  session.save(privateWS);
                }
              }
            }
          }
        }
      }
      commitAndStartTransaction();
    }

    // commitAndStartTransaction();
  }