@Test public void testDescribeUserSetChanges() throws Exception { String changes = null; HttpSession httpSession = getSession(); UserContext.newContext(getRequest(), m_user, m_customer); changes = DiffUtils.describeUserSetChanges(null, null, null); assertNull("DiffUtils.describeUserSetChanges(null, null, null) should return null", changes); SavedUserSet susOld = new SavedUserSet(m_customer.getCustID()); SavedUserSet susNew = new SavedUserSet(m_customer.getCustID()); changes = DiffUtils.describeUserSetChanges(getRequest(), susOld, susNew); assertNull("Expected no diffs for 2 identical user sets", changes); List<SearchConstraint> constraints; constraints = new ArrayList<SearchConstraint>(); constraints.add( new SearchConstraint( IUserManager.PROP_USERID, SearchConstraintOperator.CONSTRAINT_EQUALS, m_user.getUserID())); susNew.addUsers(constraints); changes = DiffUtils.describeUserSetChanges(getRequest(), susOld, susNew); assertNotNull("Expected diffs on 2 different user sets", changes); }
@Test public void testDescribeReviewerGroupReviewerChanges() throws Exception { String changes = null; UserContext.newContext(getRequest(), m_user, m_customer); changes = DiffUtils.describeReviewerGroupReviewerChanges(null, null, null); assertNull( "DiffUtils.describeReviewerGroupReviewerChanges(null, null, null) should return null", changes); List<SearchConstraint> constraints; constraints = new ArrayList<SearchConstraint>(); constraints.add( new SearchConstraint( IUserManager.PROP_USERID, SearchConstraintOperator.CONSTRAINT_EQUALS, m_user.getUserID())); SavedUserSet reviewers = new SavedUserSet(m_customer.getCustID()); reviewers.addUsers(constraints); ReviewerGroup oldRG = new ReviewerGroup(m_customer.getCustID(), 1, "name", reviewers, null, "extra"); ReviewerGroup newRG = new ReviewerGroup(m_customer.getCustID(), 1, "name", reviewers, null, "extra"); changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG); assertNull("Expected no diffs for 2 identical user sets", changes); reviewers = new SavedUserSet(m_customer.getCustID()); newRG.setReviewers(reviewers); changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG); assertNotNull("Expected diffs on 2 different reviewer groups", changes); SavedUserSet reviewers1 = new SavedUserSet(m_customer.getCustID()); reviewers1.addConstraintSets(InternalUserSets.getAllUsersSet(m_customer.getCustID())); oldRG.setReviewers(reviewers1); SavedUserSet reviewers2 = new SavedUserSet(m_customer.getCustID()); newRG.setReviewers(reviewers2); changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG); assertNotNull("Expected diffs on 2 different reviewer groups", changes); }
private Delta compareTriples() { Set<Triple> matchedTriples = Sets.newHashSet(); Set<String> superTypes = Sets.newHashSet(); Set<String> ancestors = Sets.newHashSet(); for (Triple triple1 : m1.triples().fetch()) { ObjectNode mappedS = null; if (triple1.subject().isResource()) { Resource s = (Resource) triple1.subject(); mappedS = (ObjectNode) DiffUtils.mapNodeToAnotherModel(s, m2, namespaceMap); } if (triple1.predicate().getUri().equals(Rdf.TYPE)) { if (!superTypes.contains(triple1.subject().getIdentifier())) { superTypes.add(triple1.subject().getIdentifier()); Set<RdfNode> st = DiffUtils.getSuperTypes(m1, (Resource) triple1.subject(), closureClass1, classMap1); if (mappedS == null) { for (RdfNode node : st) { ((TripleDelta) delta) .insertDeletedTriple(triple1.subject(), triple1.predicate(), node); } continue; } DiffUtils.findDeletedNeighboors( m1, m2, (Resource) triple1.subject(), (Resource) mappedS, triple1.predicate(), st, namespaceMap, delta); } } else if (triple1.predicate().getUri().equals(RdfSchema.SUBCLASSOF)) { if (!ancestors.contains(triple1.subject().getIdentifier())) { ancestors.add(triple1.subject().getIdentifier()); Set<RdfNode> an = DiffUtils.getAncestors(m1, (Resource) triple1.subject(), closureClass1, classMap1); if (mappedS == null) { for (RdfNode node : an) { ((TripleDelta) delta) .insertDeletedTriple(triple1.subject(), triple1.predicate(), node); } continue; } DiffUtils.findDeletedNeighboors( m1, m2, (Resource) triple1.subject(), (Resource) mappedS, triple1.predicate(), an, namespaceMap, delta); } } else if (triple1.predicate().getUri().equals(RdfSchema.SUBPROPERTYOF)) { if (!ancestors.contains(triple1.subject().getIdentifier())) { ancestors.add(triple1.subject().getIdentifier()); Set<RdfNode> an = DiffUtils.getAncestors(m1, (Resource) triple1.subject(), closureProp1, propMap1); if (mappedS == null) { for (RdfNode node : an) { ((TripleDelta) delta) .insertDeletedTriple(triple1.subject(), triple1.predicate(), node); } continue; } DiffUtils.findDeletedNeighboors( m1, m2, (Resource) triple1.subject(), (Resource) mappedS, triple1.predicate(), an, namespaceMap, delta); } } else { RdfNode mappedO = null; if (triple1.object().isResource()) { mappedO = DiffUtils.mapNodeToAnotherModel((Resource) triple1.object(), m2, namespaceMap); } else if (triple1.object().isLiteral()) { if (m2.map(triple1.object().toString()).hasTriples()) { mappedO = m2.map(triple1.object().toString()); } } Resource mappedP = null; if (triple1.predicate().isResource()) { mappedP = (Resource) DiffUtils.mapNodeToAnotherModel(triple1.predicate(), m2, namespaceMap); } if (mappedS == null || mappedO == null || mappedP == null) { ((TripleDelta) delta) .insertDeletedTriple(triple1.subject(), triple1.predicate(), triple1.object()); continue; } // }else // if(m2.triples().s(mappedS).p(mappedP).o(mappedO).fetch().iterator().hasNext()){ // // matchedTriples.add(m2.triples().s(mappedS).p(mappedP).o(mappedO).fetch().iterator().next()); // } else if (!m2.triples().s(mappedS).p(mappedP).o(mappedO).fetch().iterator().hasNext()) { ((TripleDelta) delta) .insertDeletedTriple(triple1.subject(), triple1.predicate(), triple1.object()); } } } for (Triple triple2 : m2.triples().fetch()) { ObjectNode mappedS = null; RdfNode mappedO = null; Resource mappedP = null; if (triple2.subject().isResource()) { Resource s = (Resource) triple2.subject(); mappedS = (ObjectNode) DiffUtils.mapNodeToAnotherModel(s, m1, namespaceMap); } if (triple2.object().isResource()) { Resource o = (Resource) triple2.object(); mappedO = DiffUtils.mapNodeToAnotherModel(o, m1, namespaceMap); } else if (triple2.object().isLiteral()) { if (m1.map(triple2.object().toString()).hasTriples()) { mappedO = m1.map(triple2.object().toString()); } } if (triple2.predicate().isResource()) { Resource p = (Resource) triple2.predicate(); mappedP = (Resource) DiffUtils.mapNodeToAnotherModel(p, m1, namespaceMap); } if (mappedS == null || mappedP == null || mappedO == null) { ((TripleDelta) delta) .insertAddedTriple(triple2.subject(), triple2.predicate(), triple2.object()); continue; } if (!m1.isInferable(mappedS.mappedTo(m1), mappedP.mappedTo(m1), mappedO.mappedTo(m1))) { ((TripleDelta) delta) .insertAddedTriple(triple2.subject(), triple2.predicate(), triple2.object()); } } return delta; }