示例#1
0
  protected void recomputeDocumentTypes() {
    // effective descriptors with override
    // linked hash map to keep order for reproducibility
    Map<String, DocumentTypeDescriptor> dtds = new LinkedHashMap<>();
    for (DocumentTypeDescriptor dtd : allDocumentTypes) {
      String name = dtd.name;
      DocumentTypeDescriptor newDtd = dtd;
      if (dtd.append && dtds.containsKey(dtd.name)) {
        newDtd = mergeDocumentTypeDescriptors(dtd, dtds.get(name));
      }
      dtds.put(name, newDtd);
    }
    // recompute all types, parents first
    documentTypes.clear();
    documentTypesExtending.clear();
    registerDocumentType(new DocumentTypeImpl(TypeConstants.DOCUMENT)); // Document
    for (String name : dtds.keySet()) {
      LinkedHashSet<String> stack = new LinkedHashSet<>();
      recomputeDocumentType(name, stack, dtds);
    }

    // document types having a given facet
    documentTypesForFacet.clear();
    for (DocumentType docType : documentTypes.values()) {
      for (String facet : docType.getFacets()) {
        Set<String> set = documentTypesForFacet.get(facet);
        if (set == null) {
          documentTypesForFacet.put(facet, set = new HashSet<>());
        }
        set.add(docType.getName());
      }
    }
  }
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    Document doc;
    NamedNodeMap notations;
    DocumentType docType;
    Node retval;
    Element elem;
    doc = (Document) load("hc_staff", true);
    docType = doc.getDoctype();

    if (!(("text/html".equals(getContentType())))) {
      assertNotNull("docTypeNotNull", docType);
      notations = docType.getNotations();
      assertNotNull("notationsNotNull", notations);
      elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "br");

      try {
        retval = notations.setNamedItemNS(elem);
        fail("throw_HIER_OR_NO_MOD_ERR");

      } catch (DOMException ex) {
        switch (ex.code) {
          case 3:
            break;
          case 7:
            break;
          default:
            throw ex;
        }
      }
    }
  }
示例#3
0
  @Test
  public void purgeFortressRemovesConcepts() throws Exception {
    try {
      logger.debug("### uniqueRelationshipByDocType");
      setSecurity();

      engineConfig.setConceptsEnabled(true);
      engineConfig.setTestMode(true);

      Transaction t;

      SystemUser su = registerSystemUser("relationshipWorkForMultipleDocuments", mike_admin);
      assertNotNull(su);

      Fortress fortress =
          fortressService.registerFortress(
              su.getCompany(), new FortressInputBean("relationshipWorkForMultipleDocuments", true));

      t = beginManualTransaction();
      DocumentType claim = conceptService.resolveByDocCode(fortress, "Claim", true);
      commitManualTransaction(t);

      EntityInputBean promoInput =
          new EntityInputBean(fortress, "jinks", claim.getName(), new DateTime());
      promoInput.addTag(new TagInputBean("a1065", "Claim", "identifier").setLabel("Claim"));

      mediationFacade.trackEntity(su.getCompany(), promoInput).getEntity();

      Collection<String> docs = new ArrayList<>();
      docs.add(claim.getName());
      validateConcepts(docs, su, 1);
      docs.clear();
      docs.add(claim.getName());
      Set<DocumentResultBean> foundDocs = validateConcepts(docs, su, 1);
      for (DocumentResultBean foundDoc : foundDocs) {
        assertEquals("Claim", foundDoc.getName());
        Collection<ConceptResultBean> concepts = foundDoc.getConcepts();
        assertEquals(1, concepts.size());
        boolean claimFound = false;
        for (ConceptResultBean concept : concepts) {
          if (concept.getName().equalsIgnoreCase("Claim")) {
            claimFound = true;
            assertEquals(1, concept.getRelationships().size());
          }
        }

        assertEquals(true, claimFound);
        logger.info(foundDoc.toString());
      }
      mediationFacade.purge(fortress);
      waitAWhile("Waiting for Async processing to complete");
      assertEquals(0, conceptService.getDocumentsInUse(fortress.getCompany()).size());
    } finally {
      cleanUpGraph();
    }
  }
示例#4
0
 private void setDocumentType(String name) {
   NodeReference schemaGlobal = connection.createNodeReference("Schema");
   schemaGlobal.appendSubscript(name);
   if (!schemaGlobal.exists()) {
     documentType = null;
     return;
   }
   documentType = DocumentType.createDocumentType(name);
   documentType.load(connection, schemaGlobal.getList());
 }
示例#5
0
 /**
  * Runs the test case.
  *
  * @throws Throwable Any uncaught exception causes test to fail
  */
 public void runTest() throws Throwable {
   Document doc;
   DocumentType docType;
   NamedNodeMap entitiesMap;
   Entity entity;
   String encodingName;
   doc = (Document) load("external_barfoo", false);
   docType = doc.getDoctype();
   entitiesMap = docType.getEntities();
   entity = (Entity) entitiesMap.getNamedItem("ent5");
   encodingName = entity.getXmlEncoding();
   assertNull("entitygetxmlencoding02", encodingName);
 }
示例#6
0
  @Test
  public void multipleDocsSameFortress() throws Exception {
    try {
      logger.debug("### multipleDocsSameFortress");

      setSecurity();
      engineConfig.setConceptsEnabled(true);

      Transaction t = beginManualTransaction();
      SystemUser su = registerSystemUser("multipleDocsSameFortress", mike_admin);
      assertNotNull(su);

      Fortress fortress =
          fortressService.registerFortress(
              su.getCompany(), new FortressInputBean("multipleDocsSameFortress", true));
      DocumentType dType = conceptService.resolveByDocCode(fortress, "ABC123", true);
      commitManualTransaction(t); // Should only be only one docTypes

      assertNotNull(dType);
      Long id = dType.getId();
      dType = conceptService.resolveByDocCode(fortress, "ABC123", false);
      assertEquals(id, dType.getId());

      EntityInputBean input = new EntityInputBean(fortress, "jinks", "DocA", new DateTime());
      input.addTag(new TagInputBean("cust123", "Customer", "purchased").setLabel("Customer"));
      mediationFacade.trackEntity(su.getCompany(), input).getEntity();
      validateConcepts("DocA", su, 1);

      // Different docs, same concepts
      input = new EntityInputBean(fortress, "jinks", "DocB", new DateTime());
      input.addTag(new TagInputBean("cust123", "Customer", "purchased").setLabel("Customer"));
      mediationFacade.trackEntity(su.getCompany(), input).getEntity();

      validateConcepts((Collection<String>) null, su, 3); // 3 Doc types.
      assertEquals(
          "Docs In Use not supporting 'null args' for fortress'",
          3,
          conceptService.getDocumentsInUse(su.getCompany()).size());

      // DAT-112
      Set<DocumentResultBean> found = validateConcepts("DocA", su, 1);
      assertEquals(1, found.size());
      assertEquals(1, found.iterator().next().getConcepts().size());
      found = validateConcepts("DocB", su, 1);
      assertEquals(1, found.size());
      // Removed the mock user
      assertEquals("Didn't find the Document ", 1, found.iterator().next().getConcepts().size());
    } finally {
      cleanUpGraph();
    }
  }
  private static void printHelp() {
    String path =
        HeidelTimeStandalone.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    String filename = path.substring(path.lastIndexOf(System.getProperty("file.separator")) + 1);

    System.out.println("HeidelTime Standalone");
    System.out.println("Copyright © 2011-2015 Jannik Strötgen");
    System.out.println("This software is free. See the COPYING file for copying conditions.");
    System.out.println();

    System.out.println("Usage:");
    System.out.println("  java -jar " + filename + " <input-document> [-param1 <value1> ...]");
    System.out.println();
    System.out.println("Parameters and expected values:");
    for (CLISwitch c : CLISwitch.values()) {
      System.out.println(
          "  "
              + c.getSwitchString()
              + "\t"
              + ((c.getSwitchString().length() > 4) ? "" : "\t")
              + c.getName());

      if (c == CLISwitch.LANGUAGE) {
        System.out.print("\t\t" + "Available languages: [ ");
        for (Language l : Language.values())
          if (l != Language.WILDCARD) System.out.print(l.getName().toLowerCase() + " ");
        System.out.println("]");
      }

      if (c == CLISwitch.POSTAGGER) {
        System.out.print("\t\t" + "Available taggers: [ ");
        for (POSTagger p : POSTagger.values()) System.out.print(p.toString().toLowerCase() + " ");
        System.out.println("]");
      }

      if (c == CLISwitch.DOCTYPE) {
        System.out.print("\t\t" + "Available types: [ ");
        for (DocumentType t : DocumentType.values())
          System.out.print(t.toString().toLowerCase() + " ");
        System.out.println("]");
      }
    }

    System.out.println();
  }
示例#8
0
  /**
   * Assert that we only get back relationships for a the selected document type. Checks that
   * Relationships, created via an association to a tag (Linux:Tag), can be filtered by doc type.
   * e.g. Sales and Promo both have a differently named relationship to the Device tag. When
   * retrieving Sales, we should only get the "purchased" relationship. Likewise with Promo, we
   * should only get the "offer"
   *
   * @throws Exception
   */
  @Test
  public void uniqueRelationshipByDocType() throws Exception {
    try {
      logger.debug("### uniqueRelationshipByDocType");
      setSecurity();
      engineConfig.setConceptsEnabled(true);
      engineConfig.setTestMode(true);

      Transaction t = beginManualTransaction();

      SystemUser su = registerSystemUser("uniqueRelationshipByDocType", mike_admin);
      assertNotNull(su);

      Fortress fortress =
          fortressService.registerFortress(su.getCompany(), new FortressInputBean("fortA", true));

      DocumentType sale = conceptService.resolveByDocCode(fortress, "Sale", true);
      commitManualTransaction(t);
      t = beginManualTransaction();
      DocumentType promo = conceptService.resolveByDocCode(fortress, "Promotion", true);
      commitManualTransaction(t);

      EntityInputBean promoInput =
          new EntityInputBean(fortress, "jinks", promo.getName(), new DateTime());
      promoInput.addTag(new TagInputBean("Linux", "Device", "offer").setLabel("Device"));
      // promoInput.addTag(new TagInputBean("Mike", "sold").setLabel("Person"));
      mediationFacade.trackEntity(su.getCompany(), promoInput).getEntity();

      EntityInputBean salesInput =
          new EntityInputBean(fortress, "jinks", sale.getName(), new DateTime());
      salesInput.addTag(new TagInputBean("Linux", "Device", "purchased").setLabel("Device"));
      // promoInput.addTag(new TagInputBean("Gary", "authorised").setLabel("Person"));
      mediationFacade.trackEntity(su.getCompany(), salesInput).getEntity();

      Collection<String> docs = new ArrayList<>();
      docs.add(promo.getName());
      docs.add(sale.getName());
      validateConcepts(docs, su, 2);
      docs.clear();
      docs.add(promo.getName());
      Set<DocumentResultBean> foundDocs = validateConcepts(docs, su, 1);
      for (DocumentResultBean foundDoc : foundDocs) {
        assertEquals("Promotion", foundDoc.getName());
        Collection<ConceptResultBean> concepts = foundDoc.getConcepts();
        assertEquals(1, concepts.size());
        boolean deviceFound = false;
        //                boolean userFound = false;
        for (ConceptResultBean concept : concepts) {
          if (concept.getName().equalsIgnoreCase("Device")) {
            deviceFound = true;
            assertEquals(1, concept.getRelationships().size());
          }
        }
        assertEquals(true, deviceFound);
      }
    } finally {
      cleanUpGraph();
    }
  }
示例#9
0
  @Test
  public void documentType_InputThroughToDb() throws Exception {
    // DAT-540
    DocumentTypeInputBean documentTypeInputBean =
        new DocumentTypeInputBean("DTIB")
            .getVersionStrategy(DocumentType.VERSION.DISABLE)
            .setTagStructure(EntityService.TAG_STRUCTURE.TAXONOMY)
            .setGeoQuery("Testing GeoQuery");

    String json = JsonUtils.toJson(documentTypeInputBean);
    documentTypeInputBean = JsonUtils.toObject(json.getBytes(), DocumentTypeInputBean.class);

    Fortress fortress = new Fortress(new FortressInputBean("DocTypes"), new Company("Testing"));
    DocumentType documentType =
        new DocumentType(fortress.getDefaultSegment(), documentTypeInputBean);
    TestCase.assertEquals(EntityService.TAG_STRUCTURE.TAXONOMY, documentType.getTagStructure());
    TestCase.assertEquals(DocumentType.VERSION.DISABLE, documentType.getVersionStrategy());
    TestCase.assertEquals("Testing GeoQuery", documentType.getGeoQuery());
  }
示例#10
0
  protected DocumentType recomputeDocumentType(
      String name, DocumentTypeDescriptor dtd, DocumentType parent) {
    // find the facets and schemas names
    Set<String> facetNames = new HashSet<>();
    Set<String> schemaNames = SchemaDescriptor.getSchemaNames(dtd.schemas);
    facetNames.addAll(Arrays.asList(dtd.facets));

    // inherited
    if (parent != null) {
      facetNames.addAll(parent.getFacets());
      schemaNames.addAll(Arrays.asList(parent.getSchemaNames()));
    }

    // add schemas names from facets
    for (String facetName : facetNames) {
      CompositeType ct = facets.get(facetName);
      if (ct == null) {
        log.warn("Undeclared facet: " + facetName + " used in document type: " + name);
        // register it with no schemas
        ct = registerFacet(facetName, Collections.<String>emptySet());
      }
      schemaNames.addAll(Arrays.asList(ct.getSchemaNames()));
    }

    // find the schemas
    List<Schema> docTypeSchemas = new ArrayList<>();
    for (String schemaName : schemaNames) {
      Schema schema = schemas.get(schemaName);
      if (schema == null) {
        log.error("Document type: " + name + " uses unknown schema: " + schemaName);
        continue;
      }
      docTypeSchemas.add(schema);
    }

    // create doctype
    PrefetchInfo prefetch = dtd.prefetch == null ? prefetchInfo : new PrefetchInfo(dtd.prefetch);
    DocumentTypeImpl docType =
        new DocumentTypeImpl(name, parent, docTypeSchemas, facetNames, prefetch);
    registerDocumentType(docType);

    return docType;
  }
示例#11
0
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    Document doc;
    DocumentType docType;
    Entity entity;
    NamedNodeMap entitymap;
    String textContent;
    doc = (Document) load("hc_staff", true);
    docType = doc.getDoctype();
    entitymap = docType.getEntities();
    entity = (Entity) entitymap.getNamedItem("delta");

    {
      boolean success = false;
      try {
        entity.setTextContent("NA");
      } catch (DOMException ex) {
        success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
      }
      assertTrue("nodesettextcontent13", success);
    }
  }
示例#12
0
  private String addDocumentType(Map<String, String> parameters) throws Exception {
    DocumentType docType = new DocumentType();
    docType.setUid(Long.parseLong(parameters.get("uid")));
    docType.setName(parameters.get("name"));
    if (parameters.get("heritedfrom").isEmpty()) {
      docType.setDocumentTypeUid(-1);
    } else {
      docType.setDocumentTypeUid(Long.parseLong(parameters.get("heritedfrom")));
    }

    ArrayList<Map<String, String>> l =
        (ArrayList<Map<String, String>>)
            new JSONDeserializer().deserialize(parameters.get("jsonParameters"));
    List<Meta> metas = new ArrayList<Meta>();
    for (Map metaDatas : l) {
      Meta meta = new Meta();
      meta.setUid(-1);
      meta.setName(String.valueOf(metaDatas.get("name")));
      meta.setMetaType((Integer) metaDatas.get("metaType"));
      if (String.valueOf(metaDatas.get("metaFeedUid")).isEmpty()) {
        meta.setMetaFeedUid(-1L);
      } else {
        meta.setMetaFeedUid(((Integer) metaDatas.get("metaFeedUid")).longValue());
      }
      meta.setDocumentTypeUid(docType.getUid());
      metas.add(meta);
    }
    String xmlStream = XMLGenerators.getDocumentTypeXMLDescriptor(docType, metas);
    studioController.addDocumentType(sessionUid, xmlStream);
    return "";
  }
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    Document doc;
    DocumentType docType;
    NamedNodeMap entities;
    NamedNodeMap notations;
    Entity entity;
    Notation notation;
    Node newNode;
    String nullNS = null;

    doc = (Document) load("staffNS", true);
    docType = doc.getDoctype();
    entities = docType.getEntities();
    assertNotNull("entitiesNotNull", entities);
    notations = docType.getNotations();
    assertNotNull("notationsNotNull", notations);
    entity = (Entity) entities.getNamedItem("ent1");
    notation = (Notation) notations.getNamedItem("notation1");

    {
      boolean success = false;
      try {
        newNode = entities.setNamedItemNS(entity);
      } catch (DOMException ex) {
        success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
      }
      assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR_entities", success);
    }

    {
      boolean success = false;
      try {
        newNode = notations.setNamedItemNS(notation);
      } catch (DOMException ex) {
        success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
      }
      assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR_notations", success);
    }
  }
 @Override
 public void read(org.apache.thrift.protocol.TProtocol prot, QueryResult struct)
     throws org.apache.thrift.TException {
   TTupleProtocol iprot = (TTupleProtocol) prot;
   BitSet incoming = iprot.readBitSet(2);
   if (incoming.get(0)) {
     struct.documentType = DocumentType.findByValue(iprot.readI32());
     struct.setDocumentTypeIsSet(true);
   }
   if (incoming.get(1)) {
     struct.id = iprot.readString();
     struct.setIdIsSet(true);
   }
 }
示例#15
0
  @Test
  public void outerHtmlGeneration() {
    DocumentType html5 = new DocumentType("html", "", "", "");
    assertEquals("<!DOCTYPE html>", html5.outerHtml());

    DocumentType publicDocType = new DocumentType("html", "-//IETF//DTD HTML//", "", "");
    assertEquals("<!DOCTYPE html PUBLIC \"-//IETF//DTD HTML//\">", publicDocType.outerHtml());

    DocumentType systemDocType =
        new DocumentType(
            "html", "", "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd", "");
    assertEquals(
        "<!DOCTYPE html \"http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd\">",
        systemDocType.outerHtml());

    DocumentType combo = new DocumentType("notHtml", "--public", "--system", "");
    assertEquals("<!DOCTYPE notHtml PUBLIC \"--public\" \"--system\">", combo.outerHtml());
  }
    public void read(org.apache.thrift.protocol.TProtocol iprot, QueryResult struct)
        throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true) {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
          break;
        }
        switch (schemeField.id) {
          case 1: // DOCUMENT_TYPE
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.documentType = DocumentType.findByValue(iprot.readI32());
              struct.setDocumentTypeIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // ID
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.id = iprot.readString();
              struct.setIdIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }
  /**
   * Handle document type definition with validation of publicId and systemId.
   *
   * @param received
   * @param source
   * @param validationContext
   * @param namespaceContext
   */
  private void doDocumentTypeDefinition(
      Node received,
      Node source,
      XmlMessageValidationContext validationContext,
      NamespaceContext namespaceContext,
      TestContext context) {

    Assert.isTrue(
        source instanceof DocumentType,
        "Missing document type definition in expected xml fragment");

    DocumentType receivedDTD = (DocumentType) received;
    DocumentType sourceDTD = (DocumentType) source;

    if (log.isDebugEnabled()) {
      log.debug(
          "Validating document type definition: "
              + receivedDTD.getPublicId()
              + " ("
              + receivedDTD.getSystemId()
              + ")");
    }

    if (!StringUtils.hasText(sourceDTD.getPublicId())) {
      Assert.isNull(
          receivedDTD.getPublicId(),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type public id not equal",
              sourceDTD.getPublicId(),
              receivedDTD.getPublicId()));
    } else if (sourceDTD.getPublicId().trim().equals(CitrusConstants.IGNORE_PLACEHOLDER)) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Document type public id: '"
                + receivedDTD.getPublicId()
                + "' is ignored by placeholder '"
                + CitrusConstants.IGNORE_PLACEHOLDER
                + "'");
      }
    } else {
      Assert.isTrue(
          StringUtils.hasText(receivedDTD.getPublicId())
              && receivedDTD.getPublicId().equals(sourceDTD.getPublicId()),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type public id not equal",
              sourceDTD.getPublicId(),
              receivedDTD.getPublicId()));
    }

    if (!StringUtils.hasText(sourceDTD.getSystemId())) {
      Assert.isNull(
          receivedDTD.getSystemId(),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type system id not equal",
              sourceDTD.getSystemId(),
              receivedDTD.getSystemId()));
    } else if (sourceDTD.getSystemId().trim().equals(CitrusConstants.IGNORE_PLACEHOLDER)) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Document type system id: '"
                + receivedDTD.getSystemId()
                + "' is ignored by placeholder '"
                + CitrusConstants.IGNORE_PLACEHOLDER
                + "'");
      }
    } else {
      Assert.isTrue(
          StringUtils.hasText(receivedDTD.getSystemId())
              && receivedDTD.getSystemId().equals(sourceDTD.getSystemId()),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type system id not equal",
              sourceDTD.getSystemId(),
              receivedDTD.getSystemId()));
    }

    validateXmlTree(
        received.getNextSibling(),
        source.getNextSibling(),
        validationContext,
        namespaceContext,
        context);
  }
  /** @param args */
  public static void main(String[] args) {
    String docPath = null;
    for (int i = 0; i < args.length; i++) { // iterate over cli parameter tokens
      if (args[i].startsWith("-")) { // assume we found a switch
        // get the relevant enum
        CLISwitch sw = CLISwitch.getEnumFromSwitch(args[i]);
        if (sw == null) { // unsupported CLI switch
          logger.log(Level.WARNING, "Unsupported switch: " + args[i] + ". Quitting.");
          System.exit(-1);
        }

        if (sw.getHasFollowingValue()) { // handle values for switches
          if (args.length > i + 1
              && !args[i + 1].startsWith(
                  "-")) { // we still have an array index after this one and it's not a switch
            sw.setValue(args[++i]);
          } else { // value is missing or malformed
            logger.log(
                Level.WARNING, "Invalid or missing parameter after " + args[i] + ". Quitting.");
            System.exit(-1);
          }
        } else { // activate the value-less switches
          sw.setValue(null);
        }
      } else { // assume we found the document's path/name
        docPath = args[i];
      }
    }

    // display help dialog if HELP-switch is given
    if (CLISwitch.HELP.getIsActive()) {
      printHelp();
      System.exit(0);
    }

    // start off with the verbosity recognition -- lots of the other
    // stuff can be skipped if this is set too high
    if (CLISwitch.VERBOSITY2.getIsActive()) {
      logger.setLevel(Level.ALL);
      logger.log(Level.INFO, "Verbosity: '-vv'; Logging level set to ALL.");

      // output the found language resource folders
      String languagesList = "";
      for (String language : ResourceScanner.getInstance().getDetectedResourceFolders()) {
        languagesList += System.getProperty("line.separator") + "- " + language;
      }
      logger.log(Level.INFO, "Listing detected language folders:" + languagesList);
    } else if (CLISwitch.VERBOSITY.getIsActive()) {
      logger.setLevel(Level.INFO);
      logger.log(Level.INFO, "Verbosity: '-v'; Logging level set to INFO and above.");
    } else {
      logger.setLevel(Level.WARNING);
      logger.log(
          Level.INFO,
          "Verbosity -v/-vv NOT FOUND OR RECOGNIZED; Logging level set to WARNING and above.");
    }

    // Check input encoding
    String encodingType = null;
    if (CLISwitch.ENCODING.getIsActive()) {
      encodingType = CLISwitch.ENCODING.getValue().toString();
      logger.log(Level.INFO, "Encoding '-e': " + encodingType);
    } else {
      // Encoding type not found
      encodingType = CLISwitch.ENCODING.getValue().toString();
      logger.log(Level.INFO, "Encoding '-e': NOT FOUND OR RECOGNIZED; set to 'UTF-8'");
    }

    // Check output format
    OutputType outputType = null;
    if (CLISwitch.OUTPUTTYPE.getIsActive()) {
      outputType = OutputType.valueOf(CLISwitch.OUTPUTTYPE.getValue().toString().toUpperCase());
      logger.log(Level.INFO, "Output '-o': " + outputType.toString().toUpperCase());
    } else {
      // Output type not found
      outputType = (OutputType) CLISwitch.OUTPUTTYPE.getValue();
      logger.log(
          Level.INFO,
          "Output '-o': NOT FOUND OR RECOGNIZED; set to " + outputType.toString().toUpperCase());
    }

    // Check language
    Language language = null;
    if (CLISwitch.LANGUAGE.getIsActive()) {
      language = Language.getLanguageFromString((String) CLISwitch.LANGUAGE.getValue());

      if (language == Language.WILDCARD
          && !ResourceScanner.getInstance()
              .getDetectedResourceFolders()
              .contains(language.getName())) {
        logger.log(
            Level.SEVERE,
            "Language '-l': " + CLISwitch.LANGUAGE.getValue() + " NOT RECOGNIZED; aborting.");
        printHelp();
        System.exit(-1);
      } else {
        logger.log(Level.INFO, "Language '-l': " + language.getName());
      }
    } else {
      // Language not found
      language = Language.getLanguageFromString((String) CLISwitch.LANGUAGE.getValue());
      logger.log(
          Level.INFO, "Language '-l': NOT FOUND; set to " + language.toString().toUpperCase());
    }

    // Check type
    DocumentType type = null;
    if (CLISwitch.DOCTYPE.getIsActive()) {
      try {
        if (CLISwitch.DOCTYPE
            .getValue()
            .equals("narrative")) { // redirect "narrative" to "narratives"
          CLISwitch.DOCTYPE.setValue("narratives");
        }
        type = DocumentType.valueOf(CLISwitch.DOCTYPE.getValue().toString().toUpperCase());
      } catch (IllegalArgumentException e) {
        logger.log(
            Level.WARNING,
            "Type '-t': NOT RECOGNIZED. These are the available options: "
                + Arrays.asList(DocumentType.values()));
        System.exit(-1);
      }
      logger.log(Level.INFO, "Type '-t': " + type.toString().toUpperCase());
    } else {
      // Type not found
      type = (DocumentType) CLISwitch.DOCTYPE.getValue();
      logger.log(Level.INFO, "Type '-t': NOT FOUND; set to " + type.toString().toUpperCase());
    }

    // Check document creation time
    Date dct = null;
    if (CLISwitch.DCT.getIsActive()) {
      try {
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        dct = formatter.parse(CLISwitch.DCT.getValue().toString());
        logger.log(Level.INFO, "Document Creation Time '-dct': " + dct.toString());
      } catch (Exception e) {
        // DCT was not parseable
        logger.log(Level.WARNING, "Document Creation Time '-dct': NOT RECOGNIZED. Quitting.");
        printHelp();
        System.exit(-1);
      }
    } else {
      if ((type == DocumentType.NEWS) || (type == DocumentType.COLLOQUIAL)) {
        // Dct needed
        dct = (Date) CLISwitch.DCT.getValue();
        logger.log(
            Level.INFO,
            "Document Creation Time '-dct': NOT FOUND; set to local date ("
                + dct.toString()
                + ").");
      } else {
        logger.log(Level.INFO, "Document Creation Time '-dct': NOT FOUND; skipping.");
      }
    }

    // Handle locale switch
    String locale = (String) CLISwitch.LOCALE.getValue();
    Locale myLocale = null;
    if (CLISwitch.LOCALE.getIsActive()) {
      // check if the requested locale is available
      for (Locale l : Locale.getAvailableLocales()) {
        if (l.toString().toLowerCase().equals(locale.toLowerCase())) myLocale = l;
      }

      try {
        Locale.setDefault(myLocale); // try to set the locale
        logger.log(Level.INFO, "Locale '-locale': " + myLocale.toString());
      } catch (Exception e) { // if the above fails, spit out error message and available locales
        logger.log(
            Level.WARNING,
            "Supplied locale parameter couldn't be resolved to a working locale. Try one of these:");
        logger.log(
            Level.WARNING,
            Arrays.asList(Locale.getAvailableLocales()).toString()); // list available locales
        printHelp();
        System.exit(-1);
      }
    } else {
      // no -locale parameter supplied: just show default locale
      logger.log(
          Level.INFO,
          "Locale '-locale': NOT FOUND, set to environment locale: "
              + Locale.getDefault().toString());
    }

    // Read configuration from file
    String configPath = CLISwitch.CONFIGFILE.getValue().toString();
    try {
      logger.log(Level.INFO, "Configuration path '-c': " + configPath);

      readConfigFile(configPath);

      logger.log(Level.FINE, "Config initialized");
    } catch (Exception e) {
      e.printStackTrace();
      logger.log(
          Level.WARNING,
          "Config could not be initialized! Please supply the -c switch or "
              + "put a config.props into this directory.");
      printHelp();
      System.exit(-1);
    }

    // Set the preprocessing POS tagger
    POSTagger posTagger = null;
    if (CLISwitch.POSTAGGER.getIsActive()) {
      try {
        posTagger = POSTagger.valueOf(CLISwitch.POSTAGGER.getValue().toString().toUpperCase());
      } catch (IllegalArgumentException e) {
        logger.log(
            Level.WARNING,
            "Given POS Tagger doesn't exist. Please specify a valid one as listed in the help.");
        printHelp();
        System.exit(-1);
      }
      logger.log(Level.INFO, "POS Tagger '-pos': " + posTagger.toString().toUpperCase());
    } else {
      // Type not found
      posTagger = (POSTagger) CLISwitch.POSTAGGER.getValue();
      logger.log(
          Level.INFO,
          "POS Tagger '-pos': NOT FOUND OR RECOGNIZED; set to "
              + posTagger.toString().toUpperCase());
    }

    // Set whether or not to use the Interval Tagger
    Boolean doIntervalTagging = false;
    if (CLISwitch.INTERVALS.getIsActive()) {
      doIntervalTagging = CLISwitch.INTERVALS.getIsActive();
      logger.log(Level.INFO, "Interval Tagger '-it': " + doIntervalTagging.toString());
    } else {
      logger.log(
          Level.INFO,
          "Interval Tagger '-it': NOT FOUND OR RECOGNIZED; set to " + doIntervalTagging.toString());
    }

    // make sure we have a document path
    if (docPath == null) {
      logger.log(Level.WARNING, "No input file given; aborting.");
      printHelp();
      System.exit(-1);
    }

    // Run HeidelTime
    RandomAccessFile aFile = null;
    MappedByteBuffer buffer = null;
    FileChannel inChannel = null;
    PrintWriter pwOut = null;
    try {
      logger.log(Level.INFO, "Reading document using charset: " + encodingType);

      aFile = new RandomAccessFile(docPath, "r");
      inChannel = aFile.getChannel();
      buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size());
      buffer.load();
      byte[] inArr = new byte[(int) inChannel.size()];

      for (int i = 0; i < buffer.limit(); i++) {
        inArr[i] = buffer.get();
      }

      // double-newstring should not be necessary, but without this, it's not running on Windows (?)
      String input = new String(new String(inArr, encodingType).getBytes("UTF-8"), "UTF-8");

      HeidelTimeStandalone standalone =
          new HeidelTimeStandalone(language, type, outputType, null, posTagger, doIntervalTagging);
      String out = standalone.process(input, dct);

      // Print output always as UTF-8
      pwOut = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"));
      pwOut.println(out);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (pwOut != null) {
        pwOut.close();
      }
      if (buffer != null) {
        buffer.clear();
      }
      if (inChannel != null) {
        try {
          inChannel.close();
        } catch (IOException e) {
        }
      }
      if (aFile != null) {
        try {
          aFile.close();
        } catch (IOException e) {
        }
      }
    }
  }
示例#19
0
  public void serializeNode(Node node, Writer writer, String indentLevel) throws IOException {
    // Determine action based on node type
    switch (node.getNodeType()) {
      case Node.DOCUMENT_NODE:
        writer.write("<?xml version = '1.0'?>"); // "<xml version=\"1.0\">");
        writer.write(lineSeparator);
        // recurse on each child
        NodeList nodes = node.getChildNodes();
        if (nodes != null) {
          for (int i = 0; i < nodes.getLength(); i++) {
            serializeNode(nodes.item(i), writer, "");
          }
        }

        /*
         *  Document doc = (Document)node;
         *  serializeNode(doc.getDocumentElement( ), writer, " ");
         */
        break;
      case Node.ELEMENT_NODE:
        String name = node.getNodeName();
        writer.write(indentLevel + "<" + name);
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
          Node current = attributes.item(i);
          writer.write(" " + current.getNodeName() + "=\"" + current.getNodeValue() + "\"");
        }
        writer.write(">");
        // recurse on each child
        NodeList children = node.getChildNodes();
        if (children != null) {
          if ((children.item(0) != null) && (children.item(0).getNodeType() == Node.ELEMENT_NODE)) {
            writer.write(lineSeparator);
          }
          for (int i = 0; i < children.getLength(); i++) {
            serializeNode(children.item(i), writer, indentLevel + indent);
          }
          if ((children.item(0) != null)
              && (children.item(children.getLength() - 1).getNodeType() == Node.ELEMENT_NODE)) {
            writer.write(indentLevel);
          }
        }
        writer.write("</" + name + ">");
        writer.write(lineSeparator);
        break;
      case Node.TEXT_NODE:
        writer.write(node.getNodeValue());
        break;
      case Node.CDATA_SECTION_NODE:
        writer.write("<![CDATA[" + node.getNodeValue() + "]]>");
        break;
      case Node.COMMENT_NODE:
        writer.write(indentLevel + "<!-- " + node.getNodeValue() + " -->");
        writer.write(lineSeparator);
        break;
      case Node.PROCESSING_INSTRUCTION_NODE:
        writer.write("<?" + node.getNodeName() + " " + node.getNodeValue() + "?>");
        writer.write(lineSeparator);
        break;
      case Node.ENTITY_REFERENCE_NODE:
        writer.write("&" + node.getNodeName() + ";");
        break;
      case Node.DOCUMENT_TYPE_NODE:
        DocumentType docType = (DocumentType) node;
        writer.write("<!DOCTYPE " + docType.getName());
        if (docType.getPublicId() != null) {
          System.out.print(" PUBLIC \"" + docType.getPublicId() + "\" ");
        } else {
          writer.write(" SYSTEM ");
        }
        writer.write("\"" + docType.getSystemId() + "\">");
        writer.write(lineSeparator);
        break;
    }
  }
示例#20
0
  public Entity(
      String metaKey,
      FortressSegment segment,
      @NotEmpty EntityInputBean entityInput,
      @NotEmpty DocumentType documentType)
      throws FlockException {
    this();

    assert documentType != null;
    assert segment != null;

    labels.add(documentType.getName());
    this.metaKey = metaKey;
    this.noLogs = entityInput.isEntityOnly();
    this.segment = segment; // (FortressNode)documentType.getFortress();
    // DAT-278
    String docType = documentType.getName();
    if (docType == null) docType = documentType.getCode();

    if (docType == null)
      throw new RuntimeException(
          "Unable to resolve the doc type code [" + documentType + "] for  " + entityInput);

    newEntity = true;

    docType = docType.toLowerCase();
    code = entityInput.getCode();
    key =
        EntityHelper.parseKey(
            this.segment.getFortress().getId(),
            documentType.getId(),
            (code != null ? code : this.metaKey));
    // key = this.fortress.getId() + "." + documentType.getId() + "." + (code != null ? code :
    // metaKey);

    if (entityInput.getName() == null || entityInput.getName().equals(""))
      this.name = (code == null ? docType : (docType + "." + code));
    else this.name = entityInput.getName();

    //        if ( entityInput.getDescription()!=null &&
    // !entityInput.getDescription().equals(entityInput.getName()))
    //            this.description = entityInput.getDescription();

    //        indexName = indexHelper.getIndexRoot(this.segment);

    if (entityInput.getProperties() != null && !entityInput.getProperties().isEmpty()) {
      props = new DynamicPropertiesContainer(entityInput.getProperties());
    }

    Date when = entityInput.getWhen();

    if (when == null)
      fortressCreate =
          new DateTime(
                  dateCreated,
                  DateTimeZone.forTimeZone(
                      TimeZone.getTimeZone(this.segment.getFortress().getTimeZone())))
              .getMillis();
    else
      fortressCreate =
          new DateTime(when.getTime())
              .getMillis(); // new DateTime( when.getTime(),
                            // DateTimeZone.forTimeZone(TimeZone.getTimeZone(entityInput.getMetaTZ()))).toDate().getTime();
    if (entityInput.getLastChange() != null) {
      long fWhen = entityInput.getLastChange().getTime();
      if (fWhen != fortressCreate) fortressLastWhen = fWhen;
    }

    // Content date has the last say on when the update happened
    if (entityInput.getContent() != null && entityInput.getContent().getWhen() != null) {
      fortressLastWhen = entityInput.getContent().getWhen().getTime();
    }

    // lastUpdate = 0l;
    if (entityInput.isEntityOnly()) this.event = entityInput.getEvent();
    this.suppressSearch(entityInput.isSearchSuppressed());
  }
示例#21
0
  @Test
  public void fortressConcepts() throws Exception {
    try {
      logger.debug("### fortressConcepts");

      Transaction t = beginManualTransaction();
      setSecurity();
      SystemUser su = registerSystemUser("fortressConcepts", mike_admin);
      assertNotNull(su);
      engineConfig.setConceptsEnabled(true);
      engineConfig.setTestMode(true);

      Fortress fortA =
          fortressService.registerFortress(
              su.getCompany(), new FortressInputBean("fortressConcepts", true));

      DocumentType dType = conceptService.resolveByDocCode(fortA, "ABC123", true);
      commitManualTransaction(t); // Should only be only one docTypes

      assertNotNull(dType);
      Long id = dType.getId();
      dType = conceptService.resolveByDocCode(fortA, "ABC123", false);
      assertEquals(id, dType.getId());

      EntityInputBean input = new EntityInputBean(fortA, "jinks", "DocA", new DateTime());
      input.addTag(new TagInputBean("cust123", "Customer", "purchased"));
      Entity meta = mediationFacade.trackEntity(su.getCompany(), input).getEntity();

      assertNotNull(entityService.getEntity(su.getCompany(), meta.getKey()));

      input = new EntityInputBean(fortA, "jinks", "DocA", new DateTime());
      input.addTag(new TagInputBean("cust124", "Customer", "purchased").setLabel("Customer"));

      mediationFacade.trackEntity(su.getCompany(), input).getEntity();

      Collection<String> docs = new ArrayList<>();
      docs.add("DocA");
      Collection<DocumentResultBean> documentTypes =
          conceptService.findConcepts(su.getCompany(), docs, false);
      assertNotNull(documentTypes);
      assertEquals(1, documentTypes.size());

      // add a second docTypes
      input = new EntityInputBean(fortA, "jinks", "DocA", new DateTime());
      input.addTag(new TagInputBean("cust123", "Rep", "sold").setLabel("Rep"));
      mediationFacade.trackEntity(su.getCompany(), input);

      documentTypes = conceptService.getConceptsWithRelationships(su.getCompany(), docs);
      assertEquals("Only one doc type should exist", 1, documentTypes.size());

      Boolean foundCustomer = false, foundRep = false;

      for (DocumentResultBean docTypes : documentTypes) {
        for (ConceptResultBean concept : docTypes.getConcepts()) {
          if (concept.getName().equals("Customer")) {
            foundCustomer = true;
            assertEquals(1, concept.getRelationships().size());
            Assert.assertEquals(
                "purchased", concept.getRelationships().iterator().next().getName());
            assertEquals(true, concept.toString().contains(concept.getName()));
          }
          if (concept.getName().equals("Rep")) {
            foundRep = true;
            assertEquals(1, concept.getRelationships().size());
            Assert.assertEquals("sold", concept.getRelationships().iterator().next().getName());
            assertEquals(true, concept.toString().contains(concept.getName()));
          }
        }
      }
      assertTrue("Didn't find Customer concept", foundCustomer);
      assertTrue("Didn't find Rep concept", foundRep);
    } finally {
      cleanUpGraph();
    }
  }
示例#22
0
  @Test
  public void relationshipWorkForMultipleDocuments() throws Exception {
    try {
      logger.debug("### relationshipWorkForMultipleDocuments");
      setSecurity();
      engineConfig.setConceptsEnabled(true);
      engineConfig.setTestMode(true);

      Transaction t = beginManualTransaction();

      SystemUser su = registerSystemUser("relationshipWorkForMultipleDocuments", mike_admin);
      assertNotNull(su);

      Fortress fortress =
          fortressService.registerFortress(
              su.getCompany(), new FortressInputBean("relationshipWorkForMultipleDocuments", true));

      DocumentType docA = conceptService.resolveByDocCode(fortress, "DOCA", true);
      DocumentType docB = conceptService.resolveByDocCode(fortress, "DOCB", true);
      commitManualTransaction(t); // Should only be only one docTypes

      assertNotNull(docA);
      Long idA = docA.getId();
      docA = conceptService.resolveByDocCode(fortress, docA.getName(), false);
      assertEquals(idA, docA.getId());

      EntityInputBean input = new EntityInputBean(fortress, "jinks", "DocA", new DateTime());
      input.addTag(new TagInputBean("cust123", "Customer", "purchased").setLabel("Customer"));
      mediationFacade.trackEntity(su.getCompany(), input).getEntity();
      input = new EntityInputBean(fortress, "jinks", docB.getName(), new DateTime());
      input.addTag(new TagInputBean("cust121", "Customer", "purchased").setLabel("Customer"));
      mediationFacade.trackEntity(su.getCompany(), input).getEntity();

      Collection<String> docs = new ArrayList<>();
      docs.add(docA.getName());
      docs.add(docB.getName());

      Set<DocumentResultBean> docTypes =
          conceptService.getConceptsWithRelationships(su.getCompany(), docs);
      for (DocumentResultBean docType : docTypes) {
        Collection<ConceptResultBean> concepts = docType.getConcepts();
        for (ConceptResultBean concept : concepts) {
          Collection<RelationshipResultBean> relationships = concept.getRelationships();
          TestCase.assertEquals(1, relationships.size());
          //                    for (RelationshipResultBean relationship : relationships) {
          //                        assertEquals(1, relationship.getDocumentTypes().size());
          //                        if (docType.getName().equals(docA.getName()))
          //                            docAFound = true;
          //                        else if (docType.getName().equals(docB.getName()))
          //                            docBFound = true;
          //                    }
        }
      }
      // ToDo: it is unclear if we should track in this manner
      //            assertTrue("DocA Not Found in the concept", docAFound);
      //            assertTrue("DocB Not Found in the concept", docBFound);
      assertEquals(
          "Docs In Use not supporting 'null args'",
          2,
          conceptService.getConceptsWithRelationships(su.getCompany(), null).size());
    } finally {
      cleanUpGraph();
    }
  }
示例#23
0
  @Test
  public void multipleRelationships() throws Exception {
    try {
      logger.debug("### multipleRelationships");
      setSecurity();
      engineConfig.setConceptsEnabled(true);
      Transaction t = beginManualTransaction();

      SystemUser su = registerSystemUser("multipleRelationships", mike_admin);
      assertNotNull(su);

      Fortress fortress =
          fortressService.registerFortress(
              su.getCompany(), new FortressInputBean("multipleRelationships", true));

      DocumentType dType = conceptService.resolveByDocCode(fortress, "ABC123", true);
      commitManualTransaction(t); // Should only be only one docTypes

      assertNotNull(dType);
      Long id = dType.getId();
      dType = conceptService.resolveByDocCode(fortress, "ABC123", false);
      assertEquals(id, dType.getId());

      EntityInputBean input = new EntityInputBean(fortress, "jinks", "DocA", new DateTime());
      input.addTag(new TagInputBean("cust123", "Customer", "purchased").setLabel("Customer"));
      input.addTag(new TagInputBean("harry", "Customer", "soldto").setLabel("Customer"));
      mediationFacade.trackEntity(su.getCompany(), input).getEntity();
      Set<DocumentResultBean> docResults =
          conceptService.findConcepts(su.getCompany(), "DocA", true);
      assertEquals(1, docResults.size());
      assertEquals(1, docResults.iterator().next().getConcepts().size());
      assertEquals(
          "should have been two relationships",
          2,
          docResults.iterator().next().getConcepts().iterator().next().getRelationships().size());

      input = new EntityInputBean(fortress, "jinks", "DocA", new DateTime());
      input.addTag(new TagInputBean("cust121", "Customer", "purchased").setLabel("Customer"));
      input.addTag(new TagInputBean("harry", "Customer", "soldto").setLabel("Customer"));
      mediationFacade.trackEntity(su.getCompany(), input).getEntity();
      validateConcepts("DocA", su, 1);

      Collection<String> docs = new ArrayList<>();
      docs.add("DocA");
      Set<DocumentResultBean> docTypes =
          conceptService.getConceptsWithRelationships(su.getCompany(), docs);
      for (DocumentResultBean docType : docTypes) {
        Collection<ConceptResultBean> concepts = docType.getConcepts();
        for (ConceptResultBean concept : concepts) {
          Collection<RelationshipResultBean> relationships = concept.getRelationships();
          for (RelationshipResultBean relationship : relationships) {
            logger.debug(relationship.getName());
          }
          if (concept.getName().equals("User")) {
            // Currently only tracking the created. Should be 2 when tracking the updated
            assertEquals(1, relationships.size());
          } else assertEquals(2, relationships.size());
        }
      }
      assertEquals(
          "Docs In Use not supporting 'null args'",
          2,
          conceptService.getConceptsWithRelationships(su.getCompany(), null).size());
    } finally {
      cleanUpGraph();
    }
  }