Search in sources :

Example 6 with GroupIdRecord

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

the class GroupIdRecordManagerTest method testCreateDuplicateGroupIdRecords.

@Test
public void testCreateDuplicateGroupIdRecords() {
    GroupIdRecord g1 = new GroupIdRecord();
    g1.setDescription("Description");
    g1.setGroupId("orcid-generated:valid-group-id#1");
    g1.setName("Group # " + System.currentTimeMillis());
    g1.setType("publisher");
    // Create the first one
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode = g1.getPutCode();
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    // Try to create a duplicate
    try {
        g1.setPutCode(null);
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    // Try to create a UPPER duplicate
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VALID-GROUP-ID#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    // Try to create a duplicate mixed cases
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    // Create a different one
    g1.setPutCode(null);
    g1.setGroupId("orcid-generated:valid-group-id#2");
    GroupIdRecord g2 = groupIdRecordManager.createGroupIdRecord(g1);
    assertNotNull(g2);
    assertNotNull(g2.getPutCode());
    assertTrue(!g2.getPutCode().equals(putCode));
    assertEquals("orcid-generated:valid-group-id#2", g2.getGroupId());
    assertNotNull(g2.getSource());
    assertNotNull(g2.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g2.getSource().getSourceClientId().getPath());
    // Try to create again a duplicate for any of the two existing
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#2");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    groupIdRecordManager.deleteGroupIdRecord(putCode);
    groupIdRecordManager.deleteGroupIdRecord(g2.getPutCode());
}
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)

Example 7 with GroupIdRecord

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

the class GroupIdRecordManagerReadOnlyImpl method getGroupIdRecords.

@Override
public GroupIdRecords getGroupIdRecords(String pageSize, String pageNum) {
    int pageNumInt = convertToInteger(pageNum);
    int pageSizeInt = convertToInteger(pageSize);
    GroupIdRecords records = new GroupIdRecords();
    records.setPage(pageNumInt);
    records.setPageSize(pageSizeInt);
    List<GroupIdRecordEntity> recordEntities = groupIdRecordDao.getGroupIdRecords(pageSizeInt, pageNumInt);
    List<GroupIdRecord> recordsReturned = jpaJaxbGroupIdRecordAdapter.toGroupIdRecords(recordEntities);
    if (recordsReturned != null) {
        records.setTotal(recordsReturned.size());
        records.getGroupIdRecord().addAll(recordsReturned);
    } else {
        records.setTotal(0);
    }
    return records;
}
Also used : GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) GroupIdRecords(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecords) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity)

Example 8 with GroupIdRecord

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

the class Api3_0_Dev1LastModifiedDatesHelper method calculateLastModified.

public static void calculateLastModified(GroupIdRecords groupIdRecords) {
    if (groupIdRecords != null && groupIdRecords.getGroupIdRecord() != null && !groupIdRecords.getGroupIdRecord().isEmpty()) {
        LastModifiedDate latest = null;
        for (GroupIdRecord groupid : groupIdRecords.getGroupIdRecord()) {
            if (groupid.getLastModifiedDate() != null && groupid.getLastModifiedDate().after(latest)) {
                latest = groupid.getLastModifiedDate();
            }
        }
        groupIdRecords.setLastModifiedDate(latest);
    }
}
Also used : LastModifiedDate(org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord)

Example 9 with GroupIdRecord

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

the class MemberV3ApiServiceDelegator_GroupIdTest method testGetGroupIdRecord.

@Test
public void testGetGroupIdRecord() {
    SecurityContextTestUtils.setUpSecurityContextForGroupIdClientOnly();
    Response response = serviceDelegator.viewGroupIdRecord(Long.valueOf("2"));
    assertNotNull(response);
    GroupIdRecord groupIdRecord = (GroupIdRecord) response.getEntity();
    assertNotNull(groupIdRecord);
    Utils.verifyLastModified(groupIdRecord.getLastModifiedDate());
    assertEquals(Long.valueOf(2), groupIdRecord.getPutCode());
    assertEquals("issn:0000002", groupIdRecord.getGroupId());
    assertEquals("TestGroup2", groupIdRecord.getName());
    assertEquals("TestDescription2", groupIdRecord.getDescription());
    assertEquals("publisher", groupIdRecord.getType());
}
Also used : Response(javax.ws.rs.core.Response) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 10 with GroupIdRecord

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

the class MemberV3ApiServiceDelegator_GroupIdTest method testDeleteGroupIdRecord.

@Test(expected = GroupIdRecordNotFoundException.class)
public void testDeleteGroupIdRecord() {
    SecurityContextTestUtils.setUpSecurityContextForGroupIdClientOnly();
    // Verify if the record exists
    Response response = serviceDelegator.viewGroupIdRecord(5L);
    assertNotNull(response);
    GroupIdRecord groupIdRecord = (GroupIdRecord) response.getEntity();
    assertNotNull(groupIdRecord);
    // Delete the record
    serviceDelegator.deleteGroupIdRecord(5L);
    // Throws a record not found exception
    serviceDelegator.viewGroupIdRecord(5L);
}
Also used : Response(javax.ws.rs.core.Response) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

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