示例#1
0
  public static void removeApplication(String appPath) throws NotesException {

    Session session = null;
    Database dbUnplugged = null;

    String correctedPath = appPath.replace("\\", "/");

    Logger.debug("Remove Unplugged application for app at " + correctedPath);

    Configuration config = Configuration.get();

    // open unplugged db
    session = Utils.getCurrentSession();
    dbUnplugged = session.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

    // check if an app document for this app already exists and create it if not
    DocumentCollection dcApp =
        dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\"");

    if (dcApp.getCount() == 0) {
      Logger.warn("- Unplugged application document not found");

    } else if (dcApp.getCount() > 1) {
      Logger.error("- Multiple Unplugged application documents found: not removed");

    } else {

      Logger.info("- Unplugged add configuration found");

      dcApp.getFirstDocument().remove(true);
      Logger.info("- Unplugged app configuration removed");
    }
  }
示例#2
0
  public static void removeUsersAndDevices(String alias) throws NotesException {

    Session session = null;
    Database dbUnplugged = null;

    String alias1 = "/" + alias.toLowerCase();
    String alias2 = "/o=" + alias.toLowerCase();

    Logger.debug("Remove Unplugged users and devices for alias \"" + alias + "\"");

    Configuration config = Configuration.get();

    // open unplugged db
    session = Utils.getCurrentSession();
    dbUnplugged = session.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

    // check if an app document for this app already exists and create it if not
    String q =
        "Form=\"User\":\"Device\" & ( @Contains(@LowerCase(UserName); \""
            + alias1
            + "\") | @Contains(@LowerCase(UserName); \""
            + alias2
            + "\") )";
    DocumentCollection dcApp = dbUnplugged.search(q);

    Logger.info("- finding users and devices with query: " + q);

    if (dcApp.getCount() == 0) {
      Logger.info("- No Unplugged users/ devices found");

    } else {

      Logger.info("- found " + dcApp.getCount() + " users and/or devices");

      Document doc = dcApp.getFirstDocument();
      while (null != doc) {

        Document t = dcApp.getNextDocument(doc);

        Logger.info(
            "- removing "
                + doc.getItemValueString("form")
                + " for "
                + doc.getItemValueString("UserName"));

        doc.remove(true);

        try {
          doc.recycle();
        } catch (Exception e) {

        }
        doc = t;
      }
    }
  }
示例#3
0
  public static void createAppDefinition(String appPath, boolean hideFromWS, boolean autoLaunch) {

    Session sessionAsSigner = null;
    Database dbUnplugged = null;
    Document docApp = null;

    try {

      String correctedPath = appPath.replace("\\", "/");

      Logger.debug("create unplugged application " + correctedPath);

      Configuration config = Configuration.get();

      // open unplugged db
      sessionAsSigner = Utils.getCurrentSessionAsSigner();
      dbUnplugged =
          sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

      // check if an app document for this app already exists and create it if not
      DocumentCollection dcApp =
          dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\"");

      if (dcApp.getCount() == 0) {

        // create new app document
        Logger.debug("application not found: create new");

        docApp = dbUnplugged.createDocument();
        docApp.replaceItemValue("form", "UserDatabase");
        docApp.replaceItemValue("Path", correctedPath);

      } else {

        throw (new Exception("application for " + correctedPath + " already exists in Unplugged"));
      }

      docApp.replaceItemValue("Active", "1");
      docApp.replaceItemValue("ShowOnWS", (hideFromWS ? "no" : ""));
      docApp.replaceItemValue("AutoLaunchApp", (autoLaunch ? "yes" : ""));
      docApp.replaceItemValue("ReplAttachmentExts", ""); // send all attachments
      docApp.computeWithForm(true, true);
      docApp.save();

      Logger.debug("done");

    } catch (Exception e) {

      Logger.error(e);

    } finally {

      Utils.recycle(docApp, dbUnplugged);
    }
  }
示例#4
0
  /**
   * train the tagger using the DocumentCollection in file 'trainingCollection'.
   * 'trainingCollection' should consist of documents which have been explicitly tagged with
   * part-of-speech information.
   */
  void train(String trainingCollection) {

    for (int i = 0; i < posTable.length; i++)
      tagTable[i] = new String[] {"constit", "cat", posTable[i], posTable[i]};

    // build ergodic HMM with one state for each POS (plus start and end states)

    HMMstate startState = new HMMstate("start", "", WordFeatureHMMemitter.class);
    posh.addState(startState);
    for (int j = 0; j < posTable.length; j++) startState.addArc(new HMMarc(posTable[j], 0));
    HMMstate endState = new HMMstate("end", "", WordFeatureHMMemitter.class);
    posh.addState(endState);
    for (int i = 0; i < posTable.length; i++) {
      String pos = posTable[i];
      HMMstate state = new HMMstate(pos, pos, WordFeatureHMMemitter.class);
      posh.addState(state);
      for (int j = 0; j < posTable.length; j++) state.addArc(new HMMarc(posTable[j], 0));
      state.addArc(new HMMarc("end", 0));
    }
    posh.resolveNames();

    posh.resetForTraining();
    annotator = new HMMannotator(posh);
    annotator.setTagTable(tagTable);
    annotator.setBItag(false);

    DocumentCollection col = new DocumentCollection(trainingCollection);
    col.open();
    for (int i = 0; i < col.size(); i++) {
      ExternalDocument doc = col.get(i);
      doc.open();
      System.out.println("Training from " + doc.fileName());

      // divide at endmarks (constit cat="."), adding "S" marks

      int posn = 0;
      int start = posn;
      Vector anns;
      while ((anns = doc.annotationsAt(posn, "constit")) != null) {
        Annotation ann = (Annotation) anns.get(0);
        posn = ann.span().end();
        String pos = (String) ann.get("cat");
        if (pos.equals(".")) {
          doc.annotate("S", new Span(start, posn), new FeatureSet());
          start = posn;
        }
      }
      annotator.train(doc);
      //  free up space taken by annotations on document
      doc.clearAnnotations();
    }
    posh.computeProbabilities();
  }
示例#5
0
  public void run() {
    List<TestFailure> failures = dto.loadFailures();
    DocumentCollection documents = DocumentCollection.getInstance();
    TermCollection terms = TermCollection.getInstance();

    TestFailureUtil.buildDocumentCollection(failures, documents);
    TestFailureUtil.buildTermCollection(failures, terms);

    for (int i = 0; i < terms.size(); i++) {
      String term = terms.get(i);
      Integer count = documents.findTermFrequency(term);
      // Calculate idf weight against a term
      Float weight = (float) Math.log((double) documents.size() / (double) count);
      terms.setWeithg(term, weight);
      // System.out.println(String.valueOf(i) + "." + term + " : " + String.valueOf(weight)) ;
    }

    for (int i = 0; i < documents.size(); i++) {
      String document = documents.get(i);
      String[] words = document.split("\\s+");

      System.out.println(document);

      for (String word : words) {
        TermItem item = new TermItem();
        float tfidf = VectorSpaceModel.findTFIDF(documents.get(i), word);

        item.setTerm(word);
        item.setTfidf(tfidf);

        Integer pos = -1;
        while ((pos = document.indexOf(word, pos + 1)) >= 0) {
          item.addPos(pos);
        }

        if (tfidf > 0.0) System.out.println(item.toString());
      }
    }
  }
示例#6
0
  // removes the specified applications for the user from Unplugged
  @SuppressWarnings("unchecked")
  public static void deleteApplication(String userName, Vector<String> appPaths) {

    Session sessionAsSigner = null;
    Database dbUnplugged = null;
    Document docUser = null;
    View vwUsers = null;
    Name nmUser = null;
    Document docApp = null;

    try {

      Configuration config = Configuration.get();

      // open unplugged db
      sessionAsSigner = Utils.getCurrentSessionAsSigner();
      dbUnplugged =
          sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

      nmUser = sessionAsSigner.createName(userName);

      // get all application documents for this user
      DocumentCollection dcApp =
          dbUnplugged.search("Form=\"UserDatabase\" & @IsMember(\"" + userName + "\"; UserName)");

      Document docTemp = null;

      int numRemoved = 0;

      // update app documents
      docApp = dcApp.getFirstDocument();
      while (null != docApp) {

        String path = docApp.getItemValueString("Path");

        if (appPaths.contains(path)) {
          // remove application
          Vector<String> appUsers = docApp.getItemValue("UserName");

          Logger.debug(nmUser.getCanonical() + " is a user for " + path + " - removing");

          appUsers.remove(nmUser.getCanonical());
          docApp.replaceItemValue("UserName", appUsers);
          docApp.computeWithForm(true, true);
          docApp.save();

          numRemoved++;
        }

        docTemp = dcApp.getNextDocument(docApp);
        docApp.recycle();
        docApp = docTemp;
      }

      if (numRemoved == dcApp.getCount()) { // user removed from all apps - remove user config

        Logger.info(
            "Unplugged user "
                + nmUser.getCanonical()
                + " removed from all applications - remove user config");

        // check for user account
        vwUsers = dbUnplugged.getView(USERS_VIEW);
        docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true);

        if (docUser != null) {
          docUser.remove(true);
          Logger.info("removed Unplugged user " + nmUser.getCanonical());
        }
      }

    } catch (Exception e) {
      Logger.error(e);
    } finally {

      Utils.recycle(docUser, nmUser, dbUnplugged, sessionAsSigner);
    }
  }
示例#7
0
  /*
   * Create an Unplugged application definition in the Unplugged database
   * and add the specified user to it. The user is created if Unplugged
   * if he doesn't exist yet.
   */
  @SuppressWarnings("unchecked")
  public static boolean createApplication(String userName, String appPath, boolean isActive) {

    Session sessionAsSigner = null;
    Database dbUnplugged = null;
    Document docApp = null;
    Document docUser = null;
    View vwUsers = null;
    Name nmUser = null;

    try {

      String correctedPath = appPath.replace("\\", "/");

      Logger.debug("create unplugged application " + correctedPath + " for " + userName);

      Configuration config = Configuration.get();

      // open unplugged db
      sessionAsSigner = Utils.getCurrentSessionAsSigner();
      dbUnplugged =
          sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

      // create notes name object for user
      nmUser = sessionAsSigner.createName(userName);

      // check if user already exists in Unplugged
      vwUsers = dbUnplugged.getView(USERS_VIEW);
      docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true);

      if (docUser == null) {

        // user doesn't exist yet: create
        Unplugged.createUser(dbUnplugged, nmUser.getCanonical(), isActive);

      } else if (docUser.getItemValueString("Active").equals("1") && !isActive) {

        // mark user as inactive
        docUser.replaceItemValue("Active", "0");
        docUser.save();

      } else if (!docUser.getItemValueString("Active").equals("1") && isActive) {

        // mark user as active
        docUser.replaceItemValue("Active", "1");
        docUser.save();
      }

      // check if an app document for this app already exists and create it if not
      DocumentCollection dcApp =
          dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\"");

      if (dcApp.getCount() == 0) {

        // create new app document
        Logger.debug("application not found: create new");

        docApp = dbUnplugged.createDocument();
        docApp.replaceItemValue("form", "UserDatabase");
        docApp.replaceItemValue("Path", correctedPath);

      } else {

        // update existing app document
        docApp = dcApp.getFirstDocument();
      }

      Vector<String> appUsers = docApp.getItemValue("UserName");

      if (!appUsers.contains(nmUser.getCanonical())) {

        Logger.debug(nmUser.getCanonical() + " not in list of application users: adding");

        appUsers.add(nmUser.getCanonical());
        docApp.replaceItemValue("UserName", appUsers);
        docApp.replaceItemValue("Active", "1");
        docApp.computeWithForm(true, true);
        docApp.save();
      }

      Logger.debug("done");

    } catch (NotesException e) {

      Logger.error(e);
    } finally {

      Utils.recycle(docUser, docApp, nmUser, dbUnplugged);
    }

    return true;
  }
  private void generateJSONResponse(OutputStream outputStream, QueryResult queryResult)
      throws UnsupportedEncodingException, NamingException {

    String charSet = "UTF-8";
    JsonGenerator jg = Json.createGenerator(new OutputStreamWriter(outputStream, charSet));
    jg.writeStartArray();

    List<String> selects = queryResult.getQuery().getSelects();
    List<String> partIterationSelectedAttributes = getPartIterationSelectedAttributes(selects);
    List<String> pathDataSelectedAttributes = getPathDataSelectedAttributes(selects);

    context = new InitialContext();
    IProductInstanceManagerLocal productInstanceService =
        (IProductInstanceManagerLocal)
            context.lookup(
                "java:global/docdoku-server-ear/docdoku-server-ejb/ProductInstanceManagerBean");

    for (QueryResultRow row : queryResult.getRows()) {

      QueryContext queryContext = row.getContext();

      PartRevision part = row.getPartRevision();
      PartIteration lastCheckedInIteration = part.getLastCheckedInIteration();

      jg.writeStartObject();

      jg.write(QueryField.PART_REVISION_PART_KEY, part.getPartNumber() + '-' + part.getVersion());

      // PartMaster data

      if (selects.contains(QueryField.PART_MASTER_NUMBER)) {
        jg.write(QueryField.PART_MASTER_NUMBER, part.getPartNumber());
      }

      if (selects.contains(QueryField.PART_MASTER_NAME)) {
        String sName = part.getPartName();
        jg.write(QueryField.PART_MASTER_NAME, sName != null ? sName : "");
      }

      if (selects.contains(QueryField.PART_MASTER_TYPE)) {
        String sType = part.getType();
        jg.write(QueryField.PART_MASTER_TYPE, sType != null ? sType : "");
      }

      // PartRevision data

      if (selects.contains(QueryField.PART_REVISION_MODIFICATION_DATE)) {
        PartIteration pi = part.getLastIteration();
        if (pi != null) {
          writeDate(jg, QueryField.PART_REVISION_MODIFICATION_DATE, pi.getModificationDate());
        }
      }

      if (selects.contains(QueryField.PART_REVISION_CREATION_DATE)) {
        writeDate(jg, QueryField.PART_REVISION_CREATION_DATE, part.getCreationDate());
      }

      if (selects.contains(QueryField.PART_REVISION_CHECKOUT_DATE)) {
        writeDate(jg, QueryField.PART_REVISION_CHECKOUT_DATE, part.getCheckOutDate());
      }

      if (selects.contains(QueryField.PART_REVISION_CHECKIN_DATE)) {
        writeDate(
            jg,
            QueryField.PART_REVISION_CHECKIN_DATE,
            lastCheckedInIteration != null ? lastCheckedInIteration.getCheckInDate() : null);
      }

      if (selects.contains(QueryField.PART_REVISION_VERSION)) {
        String version = part.getVersion();
        jg.write(QueryField.PART_REVISION_VERSION, version);
      }

      if (selects.contains(QueryField.PART_REVISION_LIFECYCLE_STATE)) {
        String lifeCycleState = part.getLifeCycleState();
        jg.write(
            QueryField.PART_REVISION_LIFECYCLE_STATE, lifeCycleState != null ? lifeCycleState : "");
      }

      if (selects.contains(QueryField.PART_REVISION_STATUS)) {
        PartRevision.RevisionStatus status = part.getStatus();
        jg.write(QueryField.PART_REVISION_STATUS, status.toString());
      }

      if (selects.contains(QueryField.AUTHOR_LOGIN)) {
        User user = part.getAuthor();
        jg.write(QueryField.AUTHOR_LOGIN, user.getLogin());
      }

      if (selects.contains(QueryField.AUTHOR_NAME)) {
        User user = part.getAuthor();
        jg.write(QueryField.AUTHOR_NAME, user.getName());
      }

      if (selects.contains(QueryField.CTX_DEPTH)) {
        jg.write(QueryField.CTX_DEPTH, row.getDepth());
      }

      if (selects.contains(QueryField.PART_ITERATION_LINKED_DOCUMENTS)) {

        StringBuilder sb = new StringBuilder();

        if (null != queryContext && null != queryContext.getSerialNumber()) {
          try {

            ProductInstanceMaster productInstanceMaster =
                productInstanceService.getProductInstanceMaster(
                    new ProductInstanceMasterKey(
                        queryContext.getSerialNumber(),
                        queryContext.getWorkspaceId(),
                        queryContext.getConfigurationItemId()));
            ProductInstanceIteration lastIteration = productInstanceMaster.getLastIteration();
            ProductBaseline basedOn = lastIteration.getBasedOn();
            PartCollection partCollection = basedOn.getPartCollection();
            BaselinedPart baselinedPart =
                partCollection.getBaselinedPart(
                    new BaselinedPartKey(
                        partCollection.getId(),
                        queryContext.getWorkspaceId(),
                        part.getPartNumber()));
            PartIteration targetPart = baselinedPart.getTargetPart();
            Set<DocumentLink> linkedDocuments = targetPart.getLinkedDocuments();
            DocumentCollection documentCollection = basedOn.getDocumentCollection();

            for (DocumentLink documentLink : linkedDocuments) {
              DocumentRevision targetDocument = documentLink.getTargetDocument();
              BaselinedDocument baselinedDocument =
                  documentCollection.getBaselinedDocument(
                      new BaselinedDocumentKey(
                          documentCollection.getId(),
                          queryContext.getWorkspaceId(),
                          targetDocument.getDocumentMasterId(),
                          targetDocument.getVersion()));
              if (null != baselinedDocument) {
                DocumentIteration targetDocumentIteration = baselinedDocument.getTargetDocument();
                sb.append(targetDocumentIteration.toString() + ",");
              }
            }

          } catch (UserNotFoundException
              | UserNotActiveException
              | WorkspaceNotFoundException
              | ProductInstanceMasterNotFoundException e) {
            LOGGER.log(Level.FINEST, null, e);
          }
        } else {
          if (lastCheckedInIteration != null) {
            Set<DocumentLink> linkedDocuments = lastCheckedInIteration.getLinkedDocuments();

            for (DocumentLink documentLink : linkedDocuments) {
              DocumentRevision targetDocument = documentLink.getTargetDocument();
              DocumentIteration targetDocumentLastCheckedInIteration =
                  targetDocument.getLastCheckedInIteration();
              if (targetDocumentLastCheckedInIteration != null) {
                sb.append(targetDocumentLastCheckedInIteration.toString() + ",");
              }
            }
          }
        }

        jg.write(QueryField.PART_ITERATION_LINKED_DOCUMENTS, sb.toString());
      }

      for (String attributeSelect : partIterationSelectedAttributes) {

        String attributeSelectType =
            attributeSelect
                .substring(0, attributeSelect.indexOf("."))
                .substring(QueryField.PART_REVISION_ATTRIBUTES_PREFIX.length());

        String attributeSelectName = attributeSelect.substring(attributeSelect.indexOf(".") + 1);

        String attributeValue = "";

        PartIteration pi = part.getLastIteration();

        if (pi != null) {
          List<InstanceAttribute> attributes = pi.getInstanceAttributes();

          if (attributes != null) {
            jg.writeStartArray(attributeSelect);

            for (InstanceAttribute attribute : attributes) {
              InstanceAttributeDescriptor attributeDescriptor =
                  new InstanceAttributeDescriptor(attribute);

              if (attributeDescriptor.getName().equals(attributeSelectName)
                  && attributeDescriptor.getStringType().equals(attributeSelectType)) {

                attributeValue = attribute.getValue() + "";

                if (attribute instanceof InstanceDateAttribute) {
                  attributeValue =
                      getFormattedDate(((InstanceDateAttribute) attribute).getDateValue());
                } else if (attribute instanceof InstanceListOfValuesAttribute) {
                  attributeValue = ((InstanceListOfValuesAttribute) attribute).getSelectedName();
                }

                jg.write(attributeValue);
              }
            }

            jg.writeEnd();

          } else {
            jg.write(attributeSelect, attributeValue);
          }

        } else {
          // TODO: maybe this line is useless and should be removed
          jg.write(attributeSelect, attributeValue);
        }
      }

      for (String attributeSelect : pathDataSelectedAttributes) {

        String attributeSelectType =
            attributeSelect
                .substring(0, attributeSelect.indexOf("."))
                .substring(QueryField.PATH_DATA_ATTRIBUTES_PREFIX.length());

        String attributeSelectName = attributeSelect.substring(attributeSelect.indexOf(".") + 1);

        String attributeValue = "";

        PathDataIteration pdi = row.getPathDataIteration();

        if (pdi != null) {
          List<InstanceAttribute> attributes = pdi.getInstanceAttributes();

          if (attributes != null) {
            jg.writeStartArray(attributeSelect);

            for (InstanceAttribute attribute : attributes) {
              InstanceAttributeDescriptor attributeDescriptor =
                  new InstanceAttributeDescriptor(attribute);

              if (attributeDescriptor.getName().equals(attributeSelectName)
                  && attributeDescriptor.getStringType().equals(attributeSelectType)) {

                attributeValue = attribute.getValue() + "";

                if (attribute instanceof InstanceDateAttribute) {
                  attributeValue =
                      getFormattedDate(((InstanceDateAttribute) attribute).getDateValue());
                } else if (attribute instanceof InstanceListOfValuesAttribute) {
                  attributeValue = ((InstanceListOfValuesAttribute) attribute).getSelectedName();
                }

                jg.write(attributeValue);
              }
            }

            jg.writeEnd();

          } else {
            jg.write(attributeSelect, attributeValue);
          }
        }
      }

      if (selects.contains(QueryField.CTX_PRODUCT_ID)) {
        String configurationItemId =
            queryContext != null ? queryContext.getConfigurationItemId() : "";
        jg.write(QueryField.CTX_PRODUCT_ID, configurationItemId);
      }
      if (selects.contains(QueryField.CTX_SERIAL_NUMBER)) {
        String serialNumber = queryContext != null ? queryContext.getSerialNumber() : "";
        jg.write(QueryField.CTX_SERIAL_NUMBER, serialNumber != null ? serialNumber : "");
      }
      if (selects.contains(QueryField.CTX_AMOUNT)) {
        String amount = row.getAmount() + "";
        jg.write(QueryField.CTX_AMOUNT, amount);
      }

      if (selects.contains(QueryField.CTX_P2P_SOURCE)) {
        Map<String, List<PartLinkList>> sources = row.getSources();
        String partLinksAsString = Tools.getPartLinksAsHumanString(sources);
        jg.write(QueryField.CTX_P2P_SOURCE, partLinksAsString);
      }

      if (selects.contains(QueryField.CTX_P2P_TARGET)) {
        Map<String, List<PartLinkList>> targets = row.getTargets();
        String partLinksAsString = Tools.getPartLinksAsHumanString(targets);
        jg.write(QueryField.CTX_P2P_TARGET, partLinksAsString);
      }

      if (selects.contains(QueryField.PART_MASTER_IS_STANDARD)) {
        boolean isStandard = row.getPartRevision().getPartMaster().isStandardPart();
        jg.write(QueryField.PART_MASTER_IS_STANDARD, isStandard);
      }

      jg.writeEnd();
    }

    jg.writeEnd();
    jg.flush();
  }