Search in sources :

Example 11 with GroupIdRecordEntity

use of org.orcid.persistence.jpa.entities.GroupIdRecordEntity in project ORCID-Source by ORCID.

the class GroupIdRecordManagerImpl method createGroupIdRecord.

@Override
public GroupIdRecord createGroupIdRecord(GroupIdRecord groupIdRecord) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    activityValidator.validateGroupIdRecord(groupIdRecord, true, sourceEntity);
    validateDuplicate(groupIdRecord);
    GroupIdRecordEntity entity = jpaJaxbGroupIdRecordAdapter.toGroupIdRecordEntity(groupIdRecord);
    if (sourceEntity != null) {
        if (sourceEntity.getSourceClient() != null) {
            entity.setClientSourceId(sourceEntity.getSourceClient().getClientId());
        } else if (sourceEntity.getSourceProfile() != null) {
            entity.setSourceId(sourceEntity.getSourceProfile().getId());
        }
    }
    groupIdRecordDao.persist(entity);
    return jpaJaxbGroupIdRecordAdapter.toGroupIdRecord(entity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity)

Example 12 with GroupIdRecordEntity

use of org.orcid.persistence.jpa.entities.GroupIdRecordEntity in project ORCID-Source by ORCID.

the class GroupIdRecordManagerImpl method updateGroupIdRecord.

@Override
public GroupIdRecord updateGroupIdRecord(Long putCode, GroupIdRecord groupIdRecord) {
    GroupIdRecordEntity existingEntity = groupIdRecordDao.find(putCode);
    if (existingEntity == null) {
        throw new GroupIdRecordNotFoundException();
    }
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = existingEntity.getSourceId();
    String existingClientSourceId = existingEntity.getClientSourceId();
    activityValidator.validateGroupIdRecord(groupIdRecord, false, sourceEntity);
    validateDuplicate(groupIdRecord);
    orcidSecurityManager.checkSource(existingEntity);
    GroupIdRecordEntity updatedEntity = jpaJaxbGroupIdRecordAdapter.toGroupIdRecordEntity(groupIdRecord);
    updatedEntity.setDateCreated(existingEntity.getDateCreated());
    // Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    updatedEntity = groupIdRecordDao.merge(updatedEntity);
    return jpaJaxbGroupIdRecordAdapter.toGroupIdRecord(updatedEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException)

Example 13 with GroupIdRecordEntity

use of org.orcid.persistence.jpa.entities.GroupIdRecordEntity in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_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.groupid_v2.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 14 with GroupIdRecordEntity

use of org.orcid.persistence.jpa.entities.GroupIdRecordEntity in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getGroupIdRecordMapperFacade.

public MapperFacade getGroupIdRecordMapperFacade() {
    MapperFactory mapperFactory = getNewMapperFactory();
    ClassMapBuilder<GroupIdRecord, GroupIdRecordEntity> classMap = mapperFactory.classMap(GroupIdRecord.class, GroupIdRecordEntity.class);
    addV2CommonFields(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.groupid_v2.GroupIdRecord) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity)

Aggregations

GroupIdRecordEntity (org.orcid.persistence.jpa.entities.GroupIdRecordEntity)14 GroupIdRecordNotFoundException (org.orcid.core.exception.GroupIdRecordNotFoundException)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)3 GroupIdRecord (org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord)3 AccessControlException (java.security.AccessControlException)2 NoResultException (javax.persistence.NoResultException)2 MapperFactory (ma.glasnost.orika.MapperFactory)2 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)2 Test (org.junit.Test)2 OrcidBadRequestException (org.orcid.core.exception.OrcidBadRequestException)2 OrcidElementCantBeDeletedException (org.orcid.core.exception.OrcidElementCantBeDeletedException)2 DBUnitTest (org.orcid.test.DBUnitTest)2 GroupIdRecords (org.orcid.jaxb.model.groupid_v2.GroupIdRecords)1 GroupIdRecords (org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecords)1