Search in sources :

Example 21 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_v2.GroupIdRecord in project ORCID-Source by ORCID.

the class OrcidInfo method getPeerReviewsJson.

@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/peer-reviews.json")
@ResponseBody
public List<PeerReviewForm> getPeerReviewsJson(HttpServletRequest request, @PathVariable("orcid") String orcid, @RequestParam(value = "peerReviewIds") String peerReviewIdsStr) {
    Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
    List<PeerReviewForm> peerReviews = new ArrayList<PeerReviewForm>();
    Map<Long, PeerReview> peerReviewMap = peerReviewMap(orcid, getLastModifiedTime(orcid));
    String[] peerReviewIds = peerReviewIdsStr.split(",");
    for (String id : peerReviewIds) {
        PeerReview peerReview = peerReviewMap.get(Long.valueOf(id));
        validateVisibility(peerReview.getVisibility());
        sourceUtils.setSourceName(peerReview);
        PeerReviewForm form = PeerReviewForm.valueOf(peerReview);
        // Set language name
        form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, peerReview.getOrganization().getAddress().getCountry().name())));
        if (!PojoUtil.isEmpty(form.getTranslatedSubjectName())) {
            // Set translated title language name
            if (!StringUtils.isEmpty(form.getTranslatedSubjectName().getLanguageCode())) {
                String languageName = languages.get(form.getTranslatedSubjectName().getLanguageCode());
                form.getTranslatedSubjectName().setLanguageName(languageName);
            }
        }
        // the group id
        if (form.getGroupId() != null && !PojoUtil.isEmpty(form.getGroupId().getValue())) {
            GroupIdRecord groupId = groupIdRecordManager.findByGroupId(form.getGroupId().getValue()).get();
            form.setGroupIdPutCode(Text.valueOf(groupId.getPutCode()));
        }
        peerReviews.add(form);
    }
    return peerReviews;
}
Also used : GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) ArrayList(java.util.ArrayList) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 22 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_v2.GroupIdRecord in project ORCID-Source by ORCID.

the class PublicProfileVisibilityTest method peerReviewPrivacyTest.

@Test
public void peerReviewPrivacyTest() throws InterruptedException, JSONException, URISyntaxException {
    // Create peer review group               
    String accessToken = getAccessToken(getScopes(ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE));
    List<GroupIdRecord> groups = createGroupIds();
    assertNotNull(groups);
    assertTrue(groups.size() > 0);
    GroupIdRecord g1 = groups.get(0);
    // Create peer review
    long time = System.currentTimeMillis();
    PeerReview peerReview = new PeerReview();
    peerReview.setGroupId(g1.getGroupId());
    ExternalIDs extIds = new ExternalIDs();
    peerReview.setExternalIdentifiers(extIds);
    peerReview.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType(WorkExternalIdentifierType.AGR.value());
    wExtId.setRelationship(Relationship.SELF);
    peerReview.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    Organization organization = new Organization();
    organization.setName("My org name " + System.currentTimeMillis());
    OrganizationAddress address = new OrganizationAddress();
    address.setCity("Imagination city");
    address.setCountry(Iso3166Country.US);
    organization.setAddress(address);
    peerReview.setOrganization(organization);
    peerReview.setRole(Role.CHAIR);
    peerReview.setType(PeerReviewType.EVALUATION);
    peerReview.setCompletionDate(new FuzzyDate(new Year(2016), new Month(1), new Day(1)));
    ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    peerReview = getResponse.getEntity(PeerReview.class);
    showMyOrcidPage();
    changePeerReviewVisibility(g1.getName(), Visibility.PRIVATE);
    try {
        //Verify it doesn't appear in the public page
        showPublicProfilePage(getUser1OrcidId());
        peerReviewAppearsInPublicPage(g1.getName());
        fail();
    } catch (Exception e) {
    }
    showMyOrcidPage();
    changePeerReviewVisibility(g1.getName(), Visibility.LIMITED);
    try {
        //Verify it doesn't appear in the public page
        showPublicProfilePage(getUser1OrcidId());
        peerReviewAppearsInPublicPage(g1.getName());
        fail();
    } catch (Exception e) {
    }
    showMyOrcidPage();
    changePeerReviewVisibility(g1.getName(), Visibility.PUBLIC);
    showPublicProfilePage(getUser1OrcidId());
    peerReviewAppearsInPublicPage(g1.getName());
    // Rollback
    ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), peerReview.getPutCode(), accessToken);
    assertNotNull(deleteResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) Organization(org.orcid.jaxb.model.common_v2.Organization) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) OrganizationAddress(org.orcid.jaxb.model.common_v2.OrganizationAddress) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Month(org.orcid.jaxb.model.common_v2.Month) Year(org.orcid.jaxb.model.common_v2.Year) Day(org.orcid.jaxb.model.common_v2.Day) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 23 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_v2.GroupIdRecord in project ORCID-Source by ORCID.

the class GroupIdRecordManagerTest method testUpdateDuplicateGroupIdRecords.

@Test
public void testUpdateDuplicateGroupIdRecords() {
    String groupName = "Group # " + System.currentTimeMillis();
    GroupIdRecord g1 = new GroupIdRecord();
    g1.setDescription("Description");
    g1.setGroupId("orcid-generated:valid-group-id#1");
    g1.setName(groupName);
    g1.setType("publisher");
    //Create the first one
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode1 = g1.getPutCode();
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    //Create another one
    g1.setPutCode(null);
    g1.setGroupId("orcid-generated:valid-group-id#2");
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode2 = g1.getPutCode();
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    //Create another one
    g1.setPutCode(null);
    g1.setGroupId("orcid-generated:valid-group-id#3");
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode3 = g1.getPutCode();
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    //Update #1 with an existing group id
    try {
        GroupIdRecord existingOne = groupIdRecordManager.findByGroupId("orcid-generated:valid-group-id#1").get();
        existingOne.setGroupId("orcid-generated:valid-group-id#2");
        existingOne.setDescription("updated-description");
        groupIdRecordManager.updateGroupIdRecord(existingOne.getPutCode(), existingOne);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    //Update #1 with an existing group id
    try {
        GroupIdRecord existingOne = groupIdRecordManager.findByGroupId("orcid-generated:valid-group-id#1").get();
        existingOne.setGroupId("orcid-generated:valid-group-id#3");
        existingOne.setDescription("updated-description");
        groupIdRecordManager.updateGroupIdRecord(existingOne.getPutCode(), existingOne);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    //Update #1 with a new group id
    GroupIdRecord existingOne = groupIdRecordManager.findByGroupId("orcid-generated:valid-group-id#1").get();
    existingOne.setGroupId("orcid-generated:valid-group-id#1-updated");
    existingOne.setDescription("updated-description");
    existingOne = groupIdRecordManager.updateGroupIdRecord(existingOne.getPutCode(), existingOne);
    assertNotNull(existingOne);
    assertEquals(putCode1, existingOne.getPutCode());
    assertEquals("orcid-generated:valid-group-id#1-updated", existingOne.getGroupId());
    assertEquals("updated-description", existingOne.getDescription());
    assertEquals(groupName, existingOne.getName());
    assertNotNull(existingOne.getSource());
    assertNotNull(existingOne.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, existingOne.getSource().getSourceClientId().getPath());
    //Delete them
    groupIdRecordManager.deleteGroupIdRecord(putCode1);
    groupIdRecordManager.deleteGroupIdRecord(putCode2);
    groupIdRecordManager.deleteGroupIdRecord(putCode3);
}
Also used : GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 24 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_v2.GroupIdRecord in project ORCID-Source by ORCID.

the class GroupIdRecordManagerTest method testCreateUpdateGetDeleteGroupIdRecord.

@Test
public void testCreateUpdateGetDeleteGroupIdRecord() {
    GroupIdRecord g1 = new GroupIdRecord();
    g1.setDescription("Description");
    g1.setGroupId("orcid-generated:valid-group-id");
    g1.setName("Group # " + System.currentTimeMillis());
    g1.setType("publisher");
    //Test create
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode = g1.getPutCode();
    assertNotNull(putCode);
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    //Test find
    assertTrue(groupIdRecordManager.exists(g1.getGroupId()));
    Optional<GroupIdRecord> existingByGroupId = groupIdRecordManager.findByGroupId(g1.getGroupId());
    assertTrue(existingByGroupId.isPresent());
    assertNotNull(existingByGroupId.get().getPutCode());
    assertEquals(putCode, existingByGroupId.get().getPutCode());
    assertEquals(g1.getGroupId(), existingByGroupId.get().getGroupId());
    assertNotNull(existingByGroupId.get().getSource());
    assertNotNull(existingByGroupId.get().getSource().getSourceClientId());
    assertEquals(CLIENT_ID, existingByGroupId.get().getSource().getSourceClientId().getPath());
    GroupIdRecord existingByPutCode = groupIdRecordManager.getGroupIdRecord(g1.getPutCode());
    assertNotNull(existingByPutCode);
    assertNotNull(existingByPutCode.getPutCode());
    assertEquals(putCode, existingByPutCode.getPutCode());
    assertEquals(g1.getGroupId(), existingByPutCode.getGroupId());
    assertNotNull(existingByPutCode.getSource());
    assertNotNull(existingByPutCode.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, existingByPutCode.getSource().getSourceClientId().getPath());
    //Test update with invalid value        
    try {
        g1.setGroupId("invalid-group-id");
        groupIdRecordManager.updateGroupIdRecord(g1.getPutCode(), g1);
        fail();
    } catch (OrcidValidationException e) {
        assertEquals("Invalid group-id: '" + g1.getGroupId() + "'", e.getMessage());
    } catch (Exception e) {
        fail();
    }
    //Test update with valid value
    try {
        g1.setGroupId("orcid-generated:other-valid-group-id");
        g1 = groupIdRecordManager.updateGroupIdRecord(g1.getPutCode(), g1);
        assertNotNull(g1);
        assertEquals("orcid-generated:other-valid-group-id", g1.getGroupId());
    } catch (Exception e) {
        fail();
    }
    //Test create with put code
    try {
        g1.setGroupId("orcid-generated:valid-group-id");
        groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (InvalidPutCodeException e) {
    } catch (Exception e) {
        fail();
    }
    //Test create with invalid group id
    try {
        g1.setPutCode(null);
        g1.setGroupId("other-invalid-group-id");
        groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (OrcidValidationException e) {
        assertEquals("Invalid group-id: '" + g1.getGroupId() + "'", e.getMessage());
    } catch (Exception e) {
        fail();
    }
    //Test delete
    groupIdRecordManager.deleteGroupIdRecord(putCode);
    try {
        groupIdRecordManager.deleteGroupIdRecord(Long.valueOf(-1L));
    } catch (GroupIdRecordNotFoundException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 25 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_v2.GroupIdRecord in project ORCID-Source by ORCID.

the class Utils method getGroupIdRecord.

public static GroupIdRecord getGroupIdRecord() {
    GroupIdRecord newRecord = new GroupIdRecord();
    newRecord.setGroupId("issn:0000006");
    newRecord.setName("TestGroup5");
    newRecord.setDescription("TestDescription5");
    newRecord.setType("publisher");
    return newRecord;
}
Also used : GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord)

Aggregations

GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)22 Test (org.junit.Test)12 DBUnitTest (org.orcid.test.DBUnitTest)4 Response (javax.ws.rs.core.Response)3 BaseTest (org.orcid.core.BaseTest)3 DuplicatedGroupIdRecordException (org.orcid.core.exception.DuplicatedGroupIdRecordException)3 GroupIdRecordNotFoundException (org.orcid.core.exception.GroupIdRecordNotFoundException)3 InvalidPutCodeException (org.orcid.core.exception.InvalidPutCodeException)3 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)3 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)3 GroupIdRecordEntity (org.orcid.persistence.jpa.entities.GroupIdRecordEntity)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LastModifiedDate (org.orcid.jaxb.model.common_v2.LastModifiedDate)2 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)2 IOException (java.io.IOException)1 URI (java.net.URI)1 AccessControlException (java.security.AccessControlException)1