Search in sources :

Example 1 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_GeneralTest method testOrcidProfileCreateCanViewAndCreateGroupIds.

@Test
public void testOrcidProfileCreateCanViewAndCreateGroupIds() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly();
    try {
        serviceDelegator.viewGroupIdRecord(1L);
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewGroupIdRecords("10", "1");
    } catch (Exception e) {
        fail();
    }
    GroupIdRecord groupIdRecord = Utils.getGroupIdRecord();
    try {
        serviceDelegator.createGroupIdRecord(groupIdRecord);
    } catch (Exception e) {
        fail();
    }
    GroupIdRecordEntity toDelete = groupIdRecordDao.findByGroupId(groupIdRecord.getGroupId());
    groupIdRecordDao.remove(toDelete.getId());
}
Also used : GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) NoResultException(javax.persistence.NoResultException) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) AccessControlException(java.security.AccessControlException) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 2 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_GroupIdTest method testUpdateGroupIdRecord.

@Test
public void testUpdateGroupIdRecord() {
    SecurityContextTestUtils.setUpSecurityContextForGroupIdClientOnly();
    Response response = serviceDelegator.viewGroupIdRecord(Long.valueOf("3"));
    assertNotNull(response);
    GroupIdRecord groupIdRecord = (GroupIdRecord) response.getEntity();
    assertNotNull(groupIdRecord);
    Utils.verifyLastModified(groupIdRecord.getLastModifiedDate());
    LastModifiedDate before = groupIdRecord.getLastModifiedDate();
    // Verify the name
    assertEquals(groupIdRecord.getName(), "TestGroup3");
    // Set a new name for update
    groupIdRecord.setName("TestGroup33");
    serviceDelegator.updateGroupIdRecord(groupIdRecord, Long.valueOf("3"));
    // Get the entity again and verify the name
    response = serviceDelegator.viewGroupIdRecord(Long.valueOf("3"));
    assertNotNull(response);
    GroupIdRecord groupIdRecordNew = (GroupIdRecord) response.getEntity();
    assertNotNull(groupIdRecordNew);
    Utils.verifyLastModified(groupIdRecordNew.getLastModifiedDate());
    assertTrue(groupIdRecordNew.getLastModifiedDate().after(before));
    // Verify the name
    assertEquals(groupIdRecordNew.getName(), "TestGroup33");
}
Also used : Response(javax.ws.rs.core.Response) LastModifiedDate(org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class PeerReviewsController method createPeerReviewIdList.

/**
 * Create a funding id list and sorts a map associated with the list in in
 * the session
 */
private List<String> createPeerReviewIdList(HttpServletRequest request) {
    String orcid = getCurrentUserOrcid();
    List<PeerReview> peerReviews = peerReviewManager.findPeerReviews(orcid);
    Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
    HashMap<Long, PeerReviewForm> peerReviewMap = new HashMap<>();
    List<String> peerReviewIds = new ArrayList<String>();
    if (peerReviews != null) {
        for (PeerReview peerReview : peerReviews) {
            try {
                PeerReviewForm form = PeerReviewForm.valueOf(peerReview);
                if (form.getExternalIdentifiers() != null && !form.getExternalIdentifiers().isEmpty()) {
                    for (WorkExternalIdentifier wExtId : form.getExternalIdentifiers()) {
                        if (PojoUtil.isEmpty(wExtId.getRelationship())) {
                            wExtId.setRelationship(Text.valueOf(Relationship.SELF.value()));
                        }
                    }
                }
                if (form.getTranslatedSubjectName() != null) {
                    // Set translated title language name
                    if (!(form.getTranslatedSubjectName() == null) && !StringUtils.isEmpty(form.getTranslatedSubjectName().getLanguageCode())) {
                        String languageName = languages.get(form.getTranslatedSubjectName().getLanguageCode());
                        form.getTranslatedSubjectName().setLanguageName(languageName);
                    }
                }
                form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, peerReview.getOrganization().getAddress().getCountry().name())));
                // Set the numeric id (the table id in the group_id_record table) of 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()));
                }
                peerReviewMap.put(peerReview.getPutCode(), form);
                peerReviewIds.add(String.valueOf(peerReview.getPutCode()));
            } catch (Exception e) {
                LOGGER.error("Failed to parse as PeerReview. Put code" + peerReview.getPutCode(), e);
            }
        }
        request.getSession().setAttribute(PEER_REVIEW_MAP, peerReviewMap);
    }
    return peerReviewIds;
}
Also used : HashMap(java.util.HashMap) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) ArrayList(java.util.ArrayList) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview)

Example 4 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getGroupIdRecordMapperFacade.

public MapperFacade getGroupIdRecordMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<GroupIdRecord, GroupIdRecordEntity> classMap = mapperFactory.classMap(GroupIdRecord.class, GroupIdRecordEntity.class);
    addV3CommonFields(classMap);
    registerSourceConverters(mapperFactory, classMap);
    classMap.field("name", "groupName");
    classMap.field("groupId", "groupId");
    classMap.field("description", "groupDescription");
    classMap.field("type", "groupType");
    classMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity)

Example 5 with GroupIdRecord

use of org.orcid.jaxb.model.v3.dev1.groupid.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.v3.dev1.groupid.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)

Aggregations

GroupIdRecord (org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord)21 Test (org.junit.Test)10 InvalidPutCodeException (org.orcid.core.exception.InvalidPutCodeException)4 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)4 DBUnitTest (org.orcid.test.DBUnitTest)4 HashMap (java.util.HashMap)3 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 GroupIdRecordEntity (org.orcid.persistence.jpa.entities.GroupIdRecordEntity)3 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)3 ArrayList (java.util.ArrayList)2 LastModifiedDate (org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate)2 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)2 PeerReviewForm (org.orcid.pojo.ajaxForm.PeerReviewForm)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 AccessControlException (java.security.AccessControlException)1