use of org.sagebionetworks.schema.adapter.org.json.AdapterFactoryImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class SearchDocumentDriverImplAutowireTest method testAnnotations.
/**
* All non-blob annotations belong in the free text annotations field, some
* are _also_ facets in the search index
*
* @throws Exception
*/
@Test
public void testAnnotations() throws Exception {
Node node = new Node();
node.setId("5678");
node.setParentId("1234");
node.setETag("0");
node.setNodeType(EntityType.dataset.name());
node.setDescription("Test annotations");
Long nonexistantPrincipalId = 42L;
node.setCreatedByPrincipalId(nonexistantPrincipalId);
node.setCreatedOn(new Date());
node.setModifiedByPrincipalId(nonexistantPrincipalId);
node.setModifiedOn(new Date());
node.setVersionLabel("versionLabel");
NodeRevisionBackup rev = new NodeRevisionBackup();
NamedAnnotations named = new NamedAnnotations();
Annotations primaryAnnos = named.getAdditionalAnnotations();
primaryAnnos.addAnnotation("species", "Dragon");
primaryAnnos.addAnnotation("numSamples", 999L);
Annotations additionalAnnos = named.getAdditionalAnnotations();
additionalAnnos.addAnnotation("Species", "Unicorn");
additionalAnnos.addAnnotation("stringKey", "a multi-word annotation gets underscores so we can exact-match find it");
additionalAnnos.addAnnotation("longKey", 10L);
additionalAnnos.addAnnotation("number_of_samples", "42");
additionalAnnos.addAnnotation("Tissue_Tumor", "ear lobe");
additionalAnnos.addAnnotation("platform", "synapse");
Date dateValue = new Date();
additionalAnnos.addAnnotation("dateKey", dateValue);
additionalAnnos.addAnnotation("blobKey", new String("bytes").getBytes());
rev.setNamedAnnotations(named);
Set<Reference> references = new HashSet<Reference>();
Map<String, Set<Reference>> referenceMap = new HashMap<String, Set<Reference>>();
referenceMap.put("tooMany", references);
node.setReferences(referenceMap);
for (int i = 0; i <= SearchDocumentDriverImpl.FIELD_VALUE_SIZE_LIMIT + 10; i++) {
Reference ref = new Reference();
ref.setTargetId("123" + i);
ref.setTargetVersionNumber(1L);
references.add(ref);
}
Set<ACCESS_TYPE> rwAccessType = new HashSet<ACCESS_TYPE>();
rwAccessType.add(ACCESS_TYPE.READ);
rwAccessType.add(ACCESS_TYPE.UPDATE);
ResourceAccess rwResourceAccess = new ResourceAccess();
// readWriteTest@sagebase.org
rwResourceAccess.setPrincipalId(123L);
rwResourceAccess.setAccessType(rwAccessType);
Set<ACCESS_TYPE> roAccessType = new HashSet<ACCESS_TYPE>();
roAccessType.add(ACCESS_TYPE.READ);
ResourceAccess roResourceAccess = new ResourceAccess();
// readOnlyTest@sagebase.org
roResourceAccess.setPrincipalId(456L);
roResourceAccess.setAccessType(roAccessType);
Set<ResourceAccess> resourceAccesses = new HashSet<ResourceAccess>();
resourceAccesses.add(rwResourceAccess);
resourceAccesses.add(roResourceAccess);
AccessControlList acl = new AccessControlList();
acl.setResourceAccess(resourceAccesses);
EntityPath fakeEntityPath = createFakeEntityPath();
AdapterFactoryImpl adapterFactoryImpl = new AdapterFactoryImpl();
JSONObjectAdapter adapter = adapterFactoryImpl.createNew();
fakeEntityPath.writeToJSONObject(adapter);
String fakeEntityPathJSONString = adapter.toJSONString();
Document document = searchDocumentDriver.formulateSearchDocument(node, rev, acl, fakeEntityPath);
assertEquals(DocumentTypeNames.add, document.getType());
assertEquals("en", document.getLang());
assertEquals(node.getId(), document.getId());
assertTrue(0 < document.getVersion());
DocumentFields fields = document.getFields();
// Check entity property fields
assertEquals(node.getId(), fields.getId());
assertEquals(node.getETag(), fields.getEtag());
assertEquals(node.getParentId(), fields.getParent_id());
assertEquals(node.getName(), fields.getName());
assertEquals("study", fields.getNode_type());
assertEquals(node.getDescription(), fields.getDescription());
// since the Principal doesn't exist, the 'created by' display name defaults to the principal ID
assertEquals("" + nonexistantPrincipalId, fields.getCreated_by());
assertEquals(new Long(node.getCreatedOn().getTime() / 1000), fields.getCreated_on());
// since the Principal doesn't exist, the 'modified by' display name defaults to the principal ID
assertEquals("" + nonexistantPrincipalId, fields.getModified_by());
assertEquals(new Long(node.getModifiedOn().getTime() / 1000), fields.getModified_on());
// Check boost field
assertTrue(fields.getBoost().contains(node.getId()));
assertTrue(fields.getBoost().contains(node.getName()));
// Check the faceted fields
assertEquals(2, fields.getNum_samples().size());
assertEquals(new Long(42), fields.getNum_samples().get(0));
assertEquals(new Long(999), fields.getNum_samples().get(1));
assertEquals(2, fields.getSpecies().size());
assertEquals("Dragon", fields.getSpecies().get(0));
assertEquals("Unicorn", fields.getSpecies().get(1));
assertEquals("ear lobe", fields.getTissue().get(0));
assertEquals("synapse", fields.getPlatform().get(0));
// Check ACL fields
assertEquals(2, fields.getAcl().size());
assertEquals(1, fields.getUpdate_acl().size());
// Make sure our references were trimmed
assertTrue(10 < fields.getReferences().size());
assertEquals(SearchDocumentDriverImpl.FIELD_VALUE_SIZE_LIMIT, fields.getReferences().size());
}
Aggregations