use of org.orcid.jaxb.model.record_rc4.Keywords in project ORCID-Source by ORCID.
the class ValidateV2SamplesTest method testUnmarshallKeyword.
@Test
public void testUnmarshallKeyword() throws SAXException, URISyntaxException {
Keywords keywords = (Keywords) unmarshallFromPath("/record_2.0/samples/read_samples/keywords-2.0.xml", Keywords.class, "/record_2.0/keyword-2.0.xsd");
assertNotNull(keywords);
assertNotNull(keywords.getKeywords());
assertEquals(2, keywords.getKeywords().size());
for (Keyword keyword : keywords.getKeywords()) {
assertThat(keyword.getContent(), anyOf(is("keyword1"), is("keyword2")));
assertThat(keyword.getPutCode(), anyOf(is(Long.valueOf(1)), is(Long.valueOf(2))));
assertEquals(Visibility.PUBLIC.value(), keyword.getVisibility().value());
assertNotNull(keyword.getCreatedDate());
assertNotNull(keyword.getLastModifiedDate());
assertNotNull(keyword.getSource());
assertEquals("8888-8888-8888-8880", keyword.getSource().retrieveSourcePath());
}
Keyword keyword = (Keyword) unmarshallFromPath("/record_2.0/samples/read_samples/keyword-2.0.xml", Keyword.class);
assertNotNull(keyword);
assertEquals("keyword1", keyword.getContent());
assertEquals(Long.valueOf(1), keyword.getPutCode());
assertEquals(Visibility.PUBLIC.value(), keyword.getVisibility().value());
assertNotNull(keyword.getCreatedDate());
assertNotNull(keyword.getLastModifiedDate());
assertNotNull(keyword.getSource());
assertEquals("8888-8888-8888-8880", keyword.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.record_rc4.Keywords in project ORCID-Source by ORCID.
the class PublicAPISecurityManagerV2Test method filterKeywordsTest.
@Test
public void filterKeywordsTest() {
Keywords x = getKeywordsElement(Visibility.PUBLIC, Visibility.PUBLIC, Visibility.PUBLIC);
assertEquals(3, x.getKeywords().size());
publicAPISecurityManagerV2.filter(x);
assertEquals(3, x.getKeywords().size());
assertAllArePublic(x.getKeywords());
x = getKeywordsElement(Visibility.PUBLIC, Visibility.PUBLIC, Visibility.LIMITED);
assertEquals(3, x.getKeywords().size());
publicAPISecurityManagerV2.filter(x);
assertEquals(2, x.getKeywords().size());
assertAllArePublic(x.getKeywords());
x = getKeywordsElement(Visibility.PUBLIC, Visibility.LIMITED, Visibility.PRIVATE);
assertEquals(3, x.getKeywords().size());
publicAPISecurityManagerV2.filter(x);
assertEquals(1, x.getKeywords().size());
assertAllArePublic(x.getKeywords());
x = getKeywordsElement(Visibility.PRIVATE, Visibility.LIMITED, Visibility.PRIVATE);
assertEquals(3, x.getKeywords().size());
publicAPISecurityManagerV2.filter(x);
assertTrue(x.getKeywords().isEmpty());
}
use of org.orcid.jaxb.model.record_rc4.Keywords in project ORCID-Source by ORCID.
the class KeywordsTest method testCreateGetUpdateAndDeleteKeyword_rc3.
/**
* --------- -- -- -- RC3 -- -- -- ---------
*
*/
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testCreateGetUpdateAndDeleteKeyword_rc3() throws InterruptedException, JSONException {
changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
changeCurrentKeywordsVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
String accessToken = getAccessToken();
assertNotNull(accessToken);
org.orcid.jaxb.model.record_rc3.Keyword newKeyword = new org.orcid.jaxb.model.record_rc3.Keyword();
newKeyword.setContent("keyword-3");
newKeyword.setVisibility(org.orcid.jaxb.model.common_rc3.Visibility.PUBLIC);
// Create
ClientResponse response = memberV2ApiClient_rc3.createKeyword(getUser1OrcidId(), newKeyword, accessToken);
assertNotNull(response);
assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
Map map = response.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List resultWithPutCode = (List) map.get("Location");
String location = resultWithPutCode.get(0).toString();
Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
// Get all and verify
response = memberV2ApiClient_rc3.viewKeywords(getUser1OrcidId(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
Keywords keywords = response.getEntity(Keywords.class);
assertNotNull(keywords);
assertNotNull(keywords.getKeywords());
boolean found1 = false;
boolean found2 = false;
boolean foundNew = false;
for (org.orcid.jaxb.model.record_rc3.Keyword existingKeyword : keywords.getKeywords()) {
if (existingKeyword.getContent().equals(keyword1)) {
assertEquals(org.orcid.jaxb.model.common_rc3.Visibility.PUBLIC, existingKeyword.getVisibility());
found1 = true;
} else if (existingKeyword.getContent().equals(keyword2)) {
assertEquals(org.orcid.jaxb.model.common_rc3.Visibility.PUBLIC, existingKeyword.getVisibility());
found2 = true;
} else if (existingKeyword.getContent().equals(newKeyword.getContent())) {
assertEquals(org.orcid.jaxb.model.common_rc3.Visibility.LIMITED, existingKeyword.getVisibility());
assertEquals("keyword-3", existingKeyword.getContent());
assertEquals(getClient1ClientId(), existingKeyword.getSource().retrieveSourcePath());
foundNew = true;
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(foundNew);
// Get it
response = memberV2ApiClient_rc3.viewKeyword(getUser1OrcidId(), putCode, accessToken);
assertNotNull(response);
newKeyword = response.getEntity(Keyword.class);
assertNotNull(newKeyword);
assertNotNull(newKeyword.getSource());
assertEquals(getClient1ClientId(), newKeyword.getSource().retrieveSourcePath());
assertEquals("keyword-3", newKeyword.getContent());
assertEquals(org.orcid.jaxb.model.common_rc3.Visibility.LIMITED, newKeyword.getVisibility());
assertNotNull(newKeyword.getDisplayIndex());
Long originalDisplayIndex = newKeyword.getDisplayIndex();
// Save the original visibility
org.orcid.jaxb.model.common_rc3.Visibility originalVisibility = newKeyword.getVisibility();
org.orcid.jaxb.model.common_rc3.Visibility updatedVisibility = org.orcid.jaxb.model.common_rc3.Visibility.PRIVATE;
// Verify you cant update the visibility
newKeyword.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV2ApiClient_rc3.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
org.orcid.jaxb.model.error_rc3.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.error_rc3.OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9035), error.getErrorCode());
// Set the visibility again to the initial one
newKeyword.setVisibility(originalVisibility);
// Update
newKeyword.setContent("keyword-3-updated");
response = memberV2ApiClient_rc3.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
assertNotNull(response);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
response = memberV2ApiClient_rc3.viewKeyword(getUser1OrcidId(), putCode, accessToken);
assertNotNull(response);
org.orcid.jaxb.model.record_rc3.Keyword updatedKeyword = response.getEntity(Keyword.class);
assertNotNull(updatedKeyword);
assertEquals("keyword-3-updated", updatedKeyword.getContent());
assertEquals(newKeyword.getPutCode(), updatedKeyword.getPutCode());
assertEquals(originalDisplayIndex, updatedKeyword.getDisplayIndex());
// Delete
response = memberV2ApiClient_rc3.deleteKeyword(getUser1OrcidId(), putCode, accessToken);
assertNotNull(response);
assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.record_rc4.Keywords in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method viewKeywords.
@Override
public Response viewKeywords(String orcid) {
Keywords keywords = profileKeywordManagerReadOnly.getKeywords(orcid, getLastModifiedTime(orcid));
// Lets copy the list so we don't modify the cached collection
if (keywords.getKeywords() != null) {
List<Keyword> filteredList = new ArrayList<Keyword>(keywords.getKeywords());
keywords = new Keywords();
keywords.setKeywords(filteredList);
}
orcidSecurityManager.checkAndFilter(orcid, keywords.getKeywords(), ScopePathType.ORCID_BIO_READ_LIMITED);
ElementUtils.setPathToKeywords(keywords, orcid);
Api2_0_LastModifiedDatesHelper.calculateLastModified(keywords);
sourceUtils.setSourceName(keywords);
return Response.ok(keywords).build();
}
use of org.orcid.jaxb.model.record_rc4.Keywords in project ORCID-Source by ORCID.
the class KeywordsForm method toKeywords.
public Keywords toKeywords() {
Keywords keywords = new Keywords();
List<Keyword> kList = new ArrayList<Keyword>();
for (KeywordForm form : this.keywords) {
kList.add(form.toKeyword());
}
keywords.setKeywords(kList);
return keywords;
}
Aggregations