@Override public UserProfile getUser(Authentication authentication) { Object userName = authentication.getPrincipal(); String login; User auth = null; if (userName instanceof String) login = (String) userName; else { login = ((User) authentication.getPrincipal()).getUsername(); auth = (User) authentication.getPrincipal(); } UserProfile userProfile = new UserProfile(); userProfile.setUserId(login); userProfile.setStatus("ENABLED"); if (auth != null && !auth.getAuthorities().isEmpty()) { for (GrantedAuthority grantedAuthority : auth.getAuthorities()) { userProfile.addUserRole(grantedAuthority.getAuthority()); } } if (auth != null) { SystemUser sysUser = systemUserService.findByLogin(login); if (sysUser != null) { userProfile.setApiKey(sysUser.getApiKey()); userProfile.setCompany(sysUser.getCompany().getName()); } } return userProfile; }
@Test public void created_EntityWithNoUser() throws Exception { logger.debug("### created_EntityWithNoUser"); String callerRef = "mk1hz"; SystemUser su = registerSystemUser("created_EntityWithNoUser"); Fortress fortress = fortressService.registerFortress( su.getCompany(), new FortressInputBean("created_EntityWithNoUser", true)); EntityInputBean entityBean = new EntityInputBean(fortress, null, "CompanyNode", DateTime.now(), callerRef); // No fortress user ContentInputBean contentInputBean = new ContentInputBean( null, null, DateTime.now(), Helper.getSimpleMap("name", "a"), "Answer"); entityBean.setContent(contentInputBean); TrackResultBean resultBean = mediationFacade.trackEntity(su.getCompany(), entityBean); Entity entity = entityService.findByCode(fortress, "CompanyNode", callerRef); Assert.assertEquals(null, entity.getCreatedBy()); SearchChange searchChange = searchService.getSearchChange(resultBean); assertNotNull(searchChange); searchChange = searchService.rebuild(entity, resultBean.getCurrentLog()); assertNotNull(searchChange); }
public EntityRunner( int myThread, SystemUser su, String callerRef, String docType, Fortress fortress, Collection<TagInputBean> tags, int maxRun, CountDownLatch latch, CountDownLatch startSignal) { this.callerRef = callerRef; this.docType = docType; this.fortress = fortress; this.tags = tags; this.latch = latch; this.startSignal = startSignal; this.maxRun = maxRun; this.myThread = myThread; this.apiKey = su.getApiKey(); this.company = su.getCompany(); inputBeans = new ArrayList<>(); int count = 0; while (count < maxRun) { EntityInputBean inputBean = new EntityInputBean(fortress, "wally", docType, new DateTime(), callerRef + count); inputBean.setTags(tags); inputBeans.add(inputBean); count++; } }
/** * 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(); } }
@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(); } }
@Test public void alias_TagsByAlias() throws Exception { cleanUpGraph(); SystemUser su = registerSystemUser("alias_Simple"); Fortress fortress = fortressService.registerFortress( su.getCompany(), new FortressInputBean("alias_Simple", true)); TagInputBean tagInput = new TagInputBean("TagA", "AliasTest", "rlxA"); EntityInputBean inputBean = new EntityInputBean(fortress, "*****@*****.**", "CompanyNode", DateTime.now(), "AAA"); inputBean.addTag(tagInput); // Creating the tag for an entity mediationFacade.trackEntity(su.getCompany(), inputBean).getEntity(); Tag tag = tagService.findTag(su.getCompany(), null, tagInput.getCode()); assertNotNull(tag); // The above is the setup. // Alias nodes are not stored in the _Tag bucket; then are connected to a _Tag. Since we're not // searching by a Tag type(Label) // we can't find JUST by the Alias.key // Now create an alias for TagA such that when we track a new entity with zzz as the tag value // the entity will be mapped to TagA tagService.createAlias(su.getCompany(), tag, "AliasTest", "zzz"); // Make sure creating it twice doesn't cause an error tagService.createAlias(su.getCompany(), tag, "AliasTest", "zzz"); // An alias exists for this tag that points to TagA. tagInput = new TagInputBean("zzz", "AliasTest", "rlxA"); inputBean = new EntityInputBean(fortress, "*****@*****.**", "CompanyNode", DateTime.now(), "BBB"); inputBean.addTag(tagInput); mediationFacade.trackEntity(su.getCompany(), inputBean).getEntity(); Tag aliasTag = tagService.findTag(su.getCompany(), "AliasTest", null, "zzz"); assertNotNull(aliasTag); assertEquals( "The call to find tag with an alias should find the aliased tag", tag.getId(), aliasTag.getId()); assertEquals( "Couldn't find via case-insensitive check", 2, entityTagService.findEntityTags(su.getCompany(), tag.getCode().toLowerCase()).size()); assertEquals( "Couldn't find via case-insensitive check", 2, entityTagService.findEntityTags(su.getCompany(), tag.getCode().toUpperCase()).size()); }
@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(); } }
@Test public void multipleFortressesSameTag() throws Exception { try { logger.debug("### multipleFortressesSameTag"); setSecurity(); engineConfig.setConceptsEnabled(true); Transaction t = beginManualTransaction(); SystemUser su = registerSystemUser("multipleFortressesSameTag", mike_admin); assertNotNull(su); Fortress fortressA = fortressService.registerFortress( su.getCompany(), new FortressInputBean("multipleFortressesSameTagA", true)); Fortress fortressB = fortressService.registerFortress( su.getCompany(), new FortressInputBean("multipleFortressesSameTagB", true)); commitManualTransaction(t); EntityInputBean input = new EntityInputBean(fortressA, "jinks", "DocA", new DateTime()); input.addTag(new TagInputBean("cust123", "Customer", "purchased").setLabel("Customer")); mediationFacade.trackEntity(su.getCompany(), input).getEntity(); Collection<String> documents = new ArrayList<>(); documents.add("DocA"); Set<DocumentResultBean> results = conceptService.findConcepts(su.getCompany(), documents, false); assertEquals(1, results.size()); input = new EntityInputBean(fortressB, "jinks", "DocB", new DateTime()) .addTag(new TagInputBean("cust123", "Customer", "purchased").setLabel("Customer")); mediationFacade.trackEntity(su.getCompany(), input).getEntity(); documents.add("DocB"); results = conceptService.findConcepts(su.getCompany(), documents, false); assertEquals(2, results.size()); adminService.purge(su.getCompany(), fortressB); waitAWhile(); // Previous call is Async results = conceptService.findConcepts(su.getCompany(), documents, false); assertEquals(1, results.size()); Collection<DocumentResultBean> docsInUse = conceptService.getDocumentsInUse(su.getCompany()); assertEquals(1, docsInUse.size()); } finally { cleanUpGraph(); } }
@Test public void merge_Simple() throws Exception { cleanUpGraph(); SystemUser su = registerSystemUser("merge_Simple"); Fortress fortress = fortressService.registerFortress( su.getCompany(), new FortressInputBean("merge_Simple", true)); TagInputBean tagInputA = new TagInputBean("TagA", "MoveTag", "rlxA"); TagInputBean tagInputB = new TagInputBean("TagB", "MoveTag", "rlxB"); EntityInputBean inputBean = new EntityInputBean(fortress, "*****@*****.**", "CompanyNode", DateTime.now(), "AAA"); inputBean.addTag(tagInputA); Entity entityA = mediationFacade.trackEntity(su.getCompany(), inputBean).getEntity(); inputBean = new EntityInputBean(fortress, "*****@*****.**", "CompanyNode", DateTime.now(), "BBB"); inputBean.addTag(tagInputB); Entity entityB = mediationFacade.trackEntity(su.getCompany(), inputBean).getEntity(); assertEquals(1, entityTagService.getEntityTags(entityA).size()); assertEquals(1, entityTagService.getEntityTags(entityB).size()); Tag tagA = tagService.findTag(su.getCompany(), null, tagInputA.getCode()); assertNotNull(tagA); Tag tagB = tagService.findTag(su.getCompany(), null, tagInputB.getCode()); assertNotNull(tagB); // The above is the setup. We will look to merge tagA into tagB. The end result will be that // entity Collection<Long> results = entityTagService.mergeTags(tagA.getId(), tagB.getId()); assertEquals("One Entity should have been affected by this operation", 1, results.size()); Long entityResult = results.iterator().next(); assertEquals("The wrong Entity was affected by this operation", entityA.getId(), entityResult); entityA = entityService.getEntity(su.getCompany(), entityA.getMetaKey()); Collection<EntityTag> tags = entityTagService.getEntityTags(entityA); assertEquals(1, tags.size()); assertEquals(tagInputB.getName(), tags.iterator().next().getTag().getName()); assertNull( "TagA should have been deleted", tagService.findTag(su.getCompany(), null, tagInputA.getCode())); tags = entityTagService.getEntityTags(entityB); assertEquals(1, tags.size()); assertEquals(tagInputB.getName(), tags.iterator().next().getTag().getName()); assertEquals(2, entityTagService.findEntityTags(su.getCompany(), tagInputB.getCode()).size()); // assertEquals("rlxA", tags.iterator().next().); }
private Set<DocumentResultBean> validateConcepts( Collection<String> docs, SystemUser su, int expected) throws Exception { Set<DocumentResultBean> concepts = conceptService.findConcepts(su.getCompany(), docs, true); String message = "Collection"; if (docs != null && docs.size() == 1) message = docs.iterator().next(); assertEquals(message + " concepts", expected, concepts.size()); // Purchased docTypes return concepts; }
@Test public void testEntityConceptsLinkProperties() throws Exception { // Initial setup cleanUpGraph(); engineConfig.setConceptsEnabled(true); engineConfig.setTestMode(true); SystemUser su = registerSystemUser("testEntityConceptsLinkProperties", mike_admin); Fortress fortress = fortressService.registerFortress( su.getCompany(), new FortressInputBean("testEntityConceptsLinkProperties", true)); EntityInputBean staff = new EntityInputBean(fortress, "wally", "Staff", new DateTime(), "ABC123"); mediationFacade.trackEntity(su.getCompany(), staff); assertEquals(1, conceptService.getDocumentsInUse(su.getCompany()).size()); // Checking that the entity is linked when part of the track request EntityInputBean workRecord = new EntityInputBean(fortress, "wally", "Work", new DateTime(), "ABC321") .addTag(new TagInputBean("someTag", "SomeLabel", "somerlx")) .addEntityLink( "worked", new EntityKeyBean("Staff", fortress.getName(), "ABC123") .setRelationshipName("worked") .setParent(true)); mediationFacade.trackEntity(su.getCompany(), workRecord); assertEquals(2, conceptService.getDocumentsInUse(su.getCompany()).size()); Collection<String> docs = new ArrayList<>(); docs.add("Staff"); docs.add("Work"); Set<DocumentResultBean> documentResults = conceptService.findConcepts(su.getCompany(), docs, true); assertEquals(2, documentResults.size()); MatrixResults structure = conceptService.getContentStructure(su.getCompany(), fortress.getName()); assertEquals(3, structure.getNodes().size()); assertEquals(2, structure.getEdges().size()); for (EdgeResult edgeResult : structure.getEdges()) { if (edgeResult.getRelationship().equals("worked")) { // EntityLink relationship assertTrue("parent property was not set", edgeResult.getData().containsKey("parent")); assertTrue( "Parent not true", Boolean.parseBoolean(edgeResult.getData().get("parent").toString())); } } // We should be able to find that a Staff entity has a worked link to a Timesheet }
@Test public void testEntityConceptsLink() throws Exception { // Initial setup cleanUpGraph(); engineConfig.setConceptsEnabled(true); engineConfig.setTestMode(true); SystemUser su = registerSystemUser("testEntityConceptsLink", mike_admin); Fortress fortress = fortressService.registerFortress( su.getCompany(), new FortressInputBean("testEntityConceptsLink", true)); EntityInputBean staff = new EntityInputBean(fortress, "wally", "Staff", new DateTime(), "ABC123"); mediationFacade.trackEntity(su.getCompany(), staff); assertEquals(1, conceptService.getDocumentsInUse(su.getCompany()).size()); // Checking that the entity is linked when part of the track request EntityInputBean workRecord = new EntityInputBean(fortress, "wally", "Work", new DateTime(), "ABC321") .addTag(new TagInputBean("someTag", "SomeLabel", "somerlx")) .addEntityLink( "worked", new EntityKeyBean("Staff", fortress.getName(), "ABC123") .setRelationshipName("worked")); mediationFacade.trackEntity(su.getCompany(), workRecord); assertEquals(2, conceptService.getDocumentsInUse(su.getCompany()).size()); Collection<String> docs = new ArrayList<>(); docs.add("Staff"); docs.add("Work"); Set<DocumentResultBean> documentResults = conceptService.findConcepts(su.getCompany(), docs, true); assertEquals(2, documentResults.size()); for (DocumentResultBean documentResultBean : documentResults) { switch (documentResultBean.getName()) { case "Staff": break; case "Work": // nothing to assert yet assertEquals(1, documentResultBean.getConcepts().size()); assertEquals("SomeLabel", documentResultBean.getConcepts().iterator().next().getName()); break; default: fail("Unexpected Document Type " + documentResultBean); break; } } // We should be able to find that a Staff entity has a worked link to a Timesheet }
@Test public void created_UserAgainstEntityAndLog() throws Exception { logger.debug("### created_UserAgainstEntityAndLog"); String callerRef = "mk1hz"; SystemUser su = registerSystemUser("created_UserAgainstEntityAndLog"); Fortress fortress = fortressService.registerFortress( su.getCompany(), new FortressInputBean("created_UserAgainstEntityAndLog", true)); EntityInputBean entityBean = new EntityInputBean(fortress, "poppy", "CompanyNode", DateTime.now(), callerRef); entityBean.setContent( new ContentInputBean( "billie", null, DateTime.now(), Helper.getSimpleMap("name", "a"), "Answer")); mediationFacade.trackEntity(su.getCompany(), entityBean); Entity entity = entityService.findByCode(fortress, "CompanyNode", callerRef); Assert.assertEquals("poppy", entity.getCreatedBy().getCode().toLowerCase()); Set<EntityLog> logs = entityService.getEntityLogs(su.getCompany(), entity.getMetaKey()); assertEquals(1, logs.size()); EntityLog log = logs.iterator().next(); assertEquals("billie", log.getLog().getMadeBy().getCode().toLowerCase()); entityBean.setContent( new ContentInputBean("nemo", DateTime.now(), Helper.getSimpleMap("name", "b"))); mediationFacade.trackEntity(su.getCompany(), entityBean); assertTrue( "Event name incorrect", log.getLog().getEvent().getCode().equalsIgnoreCase("answer")); entity = entityService.findByCode(fortress, "CompanyNode", callerRef); Assert.assertEquals("poppy", entity.getCreatedBy().getCode().toLowerCase()); logs = entityService.getEntityLogs(su.getCompany(), entity.getMetaKey()); assertTrue(logs.size() == 2); boolean billieFound = false; boolean nemoFound = false; for (EntityLog entityLog : logs) { if (entityLog.getLog().getMadeBy().getCode().equals("billie")) billieFound = true; if (entityLog.getLog().getMadeBy().getCode().equals("nemo")) nemoFound = true; } assertTrue("Didn't find Billie & Nemo", billieFound && nemoFound); }
@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(); } }
@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(); } }
// @Test // @Repeat(value = 1) public void entitiesUnderLoad() throws Exception { // This test suffered under DAT-348 and was quarantined. String companyName = "entitiesUnderLoad"; setSecurity(); SystemUser su = registerSystemUser(companyName, "entitiesUnderLoad"); Fortress fortress = fortressService.registerFortress( su.getCompany(), new FortressInputBean("entitiesUnderLoad", true)); String docType = "entitiesUnderLoad"; int tagCount = 1; // unique tags per entity - tags are shared across the entities int docCount = 1; // how many entities to create per thread // Tried reducing threadMax int threadMax = 3; // Each thread will create a unique document type ArrayList<TagInputBean> tags = getTags(tagCount, false); Collection<Tag> createdTags = tagService.findTags(fortress.getCompany(), tags.get(0).getLabel()); assertEquals("Database is not in a cleared down state", 0, createdTags.size()); Map<Integer, EntityRunner> runners = new HashMap<>(); CountDownLatch latch = new CountDownLatch(threadMax); CountDownLatch startSignal = new CountDownLatch(1); for (int thread = 0; thread < threadMax; thread++) { EntityRunner runner = addEntityRunner( thread + 1, su, fortress, docType, "ABC" + thread, docCount, tags, latch, startSignal); runners.put(thread, runner); } startSignal.countDown(); latch.await(); Tag found = null; for (int thread = 0; thread < threadMax; thread++) { assertEquals("Thread " + (thread + 1), true, runners.get(thread).isWorked()); for (int count = 0; count < docCount; count++) { // Thread.sleep(2000); Entity entity = entityService.findByCode( su.getCompany(), fortress.getName(), docType, "ABC" + thread + "" + count); assertNotNull(entity); Collection<EntityTag> entityTags = entityTagService.findEntityTags(entity); if (entityTags.size() == 0) { logger.debug("Why is this 0?"); } assertEquals(tagCount, entityTags.size()); // Make sure every thread's tags point to the same tag if (found == null) found = entityTags.iterator().next().getTag(); else assertEquals( found.toString() + " / " + entityTags.iterator().next().getTag().toString(), found.getId(), entityTags.iterator().next().getTag().getId()); } } assertNotNull( tagService.findTag(fortress.getCompany(), "Deadlock", null, tags.get(0).getCode())); createdTags = tagService.findTags(fortress.getCompany(), "Deadlock"); assertEquals(false, createdTags.isEmpty()); if (createdTags.size() != tagCount) { for (Tag createdTag : createdTags) { // logger.info(createdTag.toString()); logger.info("Finding... {}", createdTag.toString()); Tag xtra = tagService.findTag(su.getCompany(), createdTag.getLabel(), null, createdTag.getCode()); logger.info(xtra.toString()); } } assertEquals(tagCount, createdTags.size()); }
@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(); } }