Search in sources :

Example 1 with GroupIdRecord

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

the class MemberV2ApiServiceDelegatorImpl method createGroupIdRecord.

@Override
public Response createGroupIdRecord(GroupIdRecord groupIdRecord) {
    orcidSecurityManager.checkScopes(ScopePathType.GROUP_ID_RECORD_UPDATE);
    GroupIdRecord newRecord = groupIdRecordManager.createGroupIdRecord(groupIdRecord);
    try {
        return Response.created(new URI(String.valueOf(newRecord.getPutCode()))).build();
    } catch (URISyntaxException ex) {
        throw new RuntimeException(localeManager.resolveMessage("apiError.creategroupidrecord_response.exception"), ex);
    }
}
Also used : GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with GroupIdRecord

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

the class MemberV2ApiServiceDelegatorImpl method updateGroupIdRecord.

@Override
public Response updateGroupIdRecord(GroupIdRecord groupIdRecord, Long putCode) {
    orcidSecurityManager.checkScopes(ScopePathType.GROUP_ID_RECORD_UPDATE);
    if (!putCode.equals(groupIdRecord.getPutCode())) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("urlPutCode", String.valueOf(putCode));
        params.put("bodyPutCode", String.valueOf(groupIdRecord.getPutCode()));
        throw new MismatchedPutCodeException(params);
    }
    GroupIdRecord updatedRecord = groupIdRecordManager.updateGroupIdRecord(putCode, groupIdRecord);
    return Response.ok(updatedRecord).build();
}
Also used : HashMap(java.util.HashMap) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) MismatchedPutCodeException(org.orcid.core.exception.MismatchedPutCodeException)

Example 3 with GroupIdRecord

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

the class MemberV2ApiServiceDelegator_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.groupid_v2.GroupIdRecord) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with GroupIdRecord

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

the class MemberV2ApiServiceDelegator_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.common_v2.LastModifiedDate) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with GroupIdRecord

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

the class Api2_0_rc2_LastModifiedDatesHelper method calculateLatest.

public static Date calculateLatest(GroupIdRecords groupIdRecords) {
    Date latestAct = null;
    if (groupIdRecords != null && groupIdRecords.getGroupIdRecord() != null && !groupIdRecords.getGroupIdRecord().isEmpty()) {
        XMLGregorianCalendar latest = groupIdRecords.getGroupIdRecord().get(0).getLastModifiedDate().getValue();
        for (GroupIdRecord groupid : groupIdRecords.getGroupIdRecord()) {
            if (latest.compare(groupid.getLastModifiedDate().getValue()) == -1) {
                latest = groupid.getLastModifiedDate().getValue();
            }
        }
        latestAct = latest.toGregorianCalendar().getTime();
        groupIdRecords.setLastModifiedDate(new LastModifiedDate(latest));
    }
    return latestAct;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) GroupIdRecord(org.orcid.jaxb.model.groupid_rc2.GroupIdRecord) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) Date(java.util.Date)

Aggregations

GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)20 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 GroupIdRecordEntity (org.orcid.persistence.jpa.entities.GroupIdRecordEntity)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 URISyntaxException (java.net.URISyntaxException)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 Date (java.util.Date)1 HashMap (java.util.HashMap)1 NoResultException (javax.persistence.NoResultException)1