use of org.orcid.persistence.jpa.entities.NotificationAmendedEntity in project ORCID-Source by ORCID.
the class JpaJaxbNotificationAdapterTest method testToNotificationAmendedEntity.
@Test
public void testToNotificationAmendedEntity() {
NotificationAmended notification = new NotificationAmended();
notification.setNotificationType(NotificationType.AMENDED);
Source source = new Source();
notification.setSource(source);
SourceClientId clientId = new SourceClientId();
source.setSourceClientId(clientId);
clientId.setPath("APP-5555-5555-5555-5555");
Items activities = new Items();
notification.setItems(activities);
Item activity = new Item();
activities.getItems().add(activity);
activity.setItemType(ItemType.WORK);
activity.setItemName("Latest Research Article");
ExternalID extId = new ExternalID();
activity.setExternalIdentifier(extId);
extId.setType("doi");
extId.setValue("1234/abc123");
NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
assertTrue(notificationEntity instanceof NotificationAmendedEntity);
NotificationAmendedEntity notificationAmendedEntity = (NotificationAmendedEntity) notificationEntity;
assertNotNull(notificationEntity);
assertEquals(NotificationType.AMENDED, notificationEntity.getNotificationType());
// Source
assertNull(notificationAmendedEntity.getSourceId());
assertNull(notificationAmendedEntity.getClientSourceId());
assertNull(notificationAmendedEntity.getElementSourceId());
}
use of org.orcid.persistence.jpa.entities.NotificationAmendedEntity in project ORCID-Source by ORCID.
the class NotificationDaoTest method testFindLatestByOrcid.
@Test
public void testFindLatestByOrcid() {
NotificationEntity entity = notificationDao.findLatestByOrcid("0000-0000-0000-0003");
assertNull(entity);
Long lastId = null;
for (int i = 0; i < 5; i++) {
Date now = new Date();
NotificationAmendedEntity newEntity = new NotificationAmendedEntity();
newEntity.setAmendedSection(AmendedSection.UNKNOWN);
newEntity.setClientSourceId("APP-6666666666666666");
newEntity.setDateCreated(now);
newEntity.setLastModified(now);
newEntity.setNotificationIntro("Intro");
newEntity.setNotificationSubject("Subject");
newEntity.setNotificationType(NotificationType.AMENDED);
newEntity.setProfile(new ProfileEntity("0000-0000-0000-0003"));
newEntity.setSendable(true);
notificationDao.persist(newEntity);
NotificationEntity freshFromDB = notificationDao.findLatestByOrcid("0000-0000-0000-0003");
assertNotNull(freshFromDB);
if (lastId == null) {
lastId = freshFromDB.getId();
} else {
assertTrue(lastId < freshFromDB.getId());
lastId = freshFromDB.getId();
}
}
}
use of org.orcid.persistence.jpa.entities.NotificationAmendedEntity in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getObject.
@Override
public MapperFacade getObject() throws Exception {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
// Register converters
ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter("singleWorkExternalIdentifierFromJsonConverter", new SingleWorkExternalIdentifierFromJsonConverter());
converterFactory.registerConverter("externalIdentifierIdConverter", new ExternalIdentifierTypeConverter());
// Register factories
mapperFactory.registerObjectFactory(new WorkEntityFactory(workDao), TypeFactory.<NotificationWorkEntity>valueOf(NotificationWorkEntity.class), TypeFactory.<Item>valueOf(Item.class));
// Custom notification
ClassMapBuilder<NotificationCustom, NotificationCustomEntity> notificationCustomClassMap = mapperFactory.classMap(NotificationCustom.class, NotificationCustomEntity.class);
registerSourceConverters(mapperFactory, notificationCustomClassMap);
mapCommonFields(notificationCustomClassMap).register();
// Permission notification
ClassMapBuilder<NotificationPermission, NotificationAddItemsEntity> notificationPermissionClassMap = mapperFactory.classMap(NotificationPermission.class, NotificationAddItemsEntity.class);
registerSourceConverters(mapperFactory, notificationPermissionClassMap);
mapCommonFields(notificationPermissionClassMap.field("authorizationUrl.uri", "authorizationUrl").field("items.items", "notificationItems").customize(new CustomMapper<NotificationPermission, NotificationAddItemsEntity>() {
@Override
public void mapAtoB(NotificationPermission notification, NotificationAddItemsEntity entity, MappingContext context) {
if (StringUtils.isBlank(entity.getAuthorizationUrl())) {
String authUrl = orcidUrlManager.getBaseUrl() + notification.getAuthorizationUrl().getPath();
// validate
validateAndConvertToURI(authUrl);
entity.setAuthorizationUrl(authUrl);
}
}
@Override
public void mapBtoA(NotificationAddItemsEntity entity, NotificationPermission notification, MappingContext context) {
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
if (authUrl != null) {
authUrl.setPath(extractFullPath(authUrl.getUri()));
authUrl.setHost(orcidUrlManager.getBaseHost());
}
}
})).register();
// Institutional sign in notification
ClassMapBuilder<NotificationInstitutionalConnection, NotificationInstitutionalConnectionEntity> institutionalConnectionNotificationClassMap = mapperFactory.classMap(NotificationInstitutionalConnection.class, NotificationInstitutionalConnectionEntity.class);
registerSourceConverters(mapperFactory, institutionalConnectionNotificationClassMap);
mapCommonFields(institutionalConnectionNotificationClassMap.field("authorizationUrl.uri", "authorizationUrl").customize(new CustomMapper<NotificationInstitutionalConnection, NotificationInstitutionalConnectionEntity>() {
@Override
public void mapAtoB(NotificationInstitutionalConnection notification, NotificationInstitutionalConnectionEntity entity, MappingContext context) {
if (StringUtils.isBlank(entity.getAuthorizationUrl())) {
String authUrl = orcidUrlManager.getBaseUrl() + notification.getAuthorizationUrl().getPath();
// validate
validateAndConvertToURI(authUrl);
entity.setAuthorizationUrl(authUrl);
}
}
@Override
public void mapBtoA(NotificationInstitutionalConnectionEntity entity, NotificationInstitutionalConnection notification, MappingContext context) {
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
if (authUrl != null) {
authUrl.setPath(extractFullPath(authUrl.getUri()));
authUrl.setHost(orcidUrlManager.getBaseHost());
}
String providerId = entity.getAuthenticationProviderId();
if (StringUtils.isNotBlank(providerId)) {
String idpName = identityProviderManager.retrieveIdentitifyProviderName(providerId);
notification.setIdpName(idpName);
} else {
notification.setIdpName(LAST_RESORT_IDENTITY_PROVIDER_NAME);
}
}
})).register();
// Amend notification
ClassMapBuilder<NotificationAmended, NotificationAmendedEntity> amendNotificationClassMap = mapperFactory.classMap(NotificationAmended.class, NotificationAmendedEntity.class);
registerSourceConverters(mapperFactory, amendNotificationClassMap);
mapCommonFields(amendNotificationClassMap).register();
mapperFactory.classMap(NotificationItemEntity.class, Item.class).fieldMap("externalIdType", "externalIdentifier.type").converter("externalIdentifierIdConverter").add().field("externalIdValue", "externalIdentifier.value").byDefault().register();
return mapperFactory.getMapperFacade();
}
Aggregations