Search in sources :

Example 6 with GroupIdRecordEntity

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

the class GroupIdRecordManagerImpl method deleteGroupIdRecord.

@Override
public void deleteGroupIdRecord(Long putCode) {
    GroupIdRecordEntity existingEntity = groupIdRecordDao.find(putCode);
    if (existingEntity != null) {
        if (groupIdRecordDao.haveAnyPeerReview(existingEntity.getGroupId())) {
            throw new OrcidElementCantBeDeletedException("Unable to delete group id because there are peer reviews associated to it");
        }
        orcidSecurityManager.checkSource(existingEntity);
        groupIdRecordDao.remove(Long.valueOf(putCode));
    } else {
        throw new GroupIdRecordNotFoundException();
    }
}
Also used : OrcidElementCantBeDeletedException(org.orcid.core.exception.OrcidElementCantBeDeletedException) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException)

Example 7 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 8 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 = new DefaultMapperFactory.Builder().build();
    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) 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)8 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)3 GroupIdRecordNotFoundException (org.orcid.core.exception.GroupIdRecordNotFoundException)2 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)2 AccessControlException (java.security.AccessControlException)1 NoResultException (javax.persistence.NoResultException)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1 Test (org.junit.Test)1 OrcidAccessControlException (org.orcid.core.exception.OrcidAccessControlException)1 OrcidBadRequestException (org.orcid.core.exception.OrcidBadRequestException)1 OrcidElementCantBeDeletedException (org.orcid.core.exception.OrcidElementCantBeDeletedException)1 GroupIdRecords (org.orcid.jaxb.model.groupid_v2.GroupIdRecords)1 DBUnitTest (org.orcid.test.DBUnitTest)1