Search in sources :

Example 6 with IdentityProviderEntity

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

the class IdentityProviderManagerImpl method retrieveFreshIdentitifyProviderName.

@Override
@Transactional
public String retrieveFreshIdentitifyProviderName(String providerid, Locale locale) {
    IdentityProviderEntity idp = identityProviderDao.findByProviderid(providerid);
    List<IdentityProviderNameEntity> names = idp.getNames();
    if (names != null) {
        Optional<IdentityProviderNameEntity> idpNameEntity = names.stream().filter(n -> n.getLang().equals(locale.getLanguage())).findFirst();
        if (idpNameEntity.isPresent()) {
            return idpNameEntity.get().getDisplayName();
        }
    }
    return idp.getDisplayName();
}
Also used : IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity) XPathExpressionException(javax.xml.xpath.XPathExpressionException) XPath(javax.xml.xpath.XPath) XPathConstants(javax.xml.xpath.XPathConstants) ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggerFactory(org.slf4j.LoggerFactory) IdentityProviderManager(org.orcid.core.manager.IdentityProviderManager) XPathExpression(javax.xml.xpath.XPathExpression) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) MediaType(javax.ws.rs.core.MediaType) Locale(java.util.Locale) Document(org.w3c.dom.Document) Map(java.util.Map) Node(org.w3c.dom.Node) IdentityProviderNameEntity(org.orcid.persistence.jpa.entities.IdentityProviderNameEntity) WebResource(com.sun.jersey.api.client.WebResource) IdentityProviderDao(org.orcid.persistence.dao.IdentityProviderDao) Logger(org.slf4j.Logger) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) NodeList(org.w3c.dom.NodeList) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Transactional(javax.transaction.Transactional) Resource(javax.annotation.Resource) Collectors(java.util.stream.Collectors) NamespaceMap(org.orcid.core.utils.NamespaceMap) XPathFactory(javax.xml.xpath.XPathFactory) LocaleManager(org.orcid.core.locale.LocaleManager) List(java.util.List) Element(org.w3c.dom.Element) Client(com.sun.jersey.api.client.Client) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ReleaseNameUtils(org.orcid.utils.ReleaseNameUtils) IdentityProviderNameEntity(org.orcid.persistence.jpa.entities.IdentityProviderNameEntity) IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity) Transactional(javax.transaction.Transactional)

Example 7 with IdentityProviderEntity

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

the class IdentityProviderManagerTest method testCreateEntityFromXml.

@Test
public void testCreateEntityFromXml() throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(getClass().getResourceAsStream("example_idp.xml"));
    Element idpElement = doc.getDocumentElement();
    IdentityProviderEntity result = identityProviderManager.createEntityFromXml(idpElement);
    assertNotNull(result);
    assertEquals("https://idp.example.ch/idp/shibboleth", result.getProviderid());
    List<IdentityProviderNameEntity> names = result.getNames();
    assertNotNull(names);
    assertEquals(4, names.size());
    Map<String, IdentityProviderNameEntity> mapByLang = names.stream().collect(Collectors.toMap(IdentityProviderNameEntity::getLang, Function.identity()));
    assertEquals("Universität Example Display", mapByLang.get("de").getDisplayName());
    assertEquals("University of Example Display", mapByLang.get("en").getDisplayName());
    assertEquals("Université de Example Display", mapByLang.get("fr").getDisplayName());
    assertEquals("Università di Example Display", mapByLang.get("it").getDisplayName());
    assertEquals("Universität Example Display", result.getDisplayName());
    assertEquals("support@example.ch", result.getSupportEmail());
    assertNull(result.getAdminEmail());
    assertEquals("technical@example.ch", result.getTechEmail());
}
Also used : IdentityProviderNameEntity(org.orcid.persistence.jpa.entities.IdentityProviderNameEntity) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

IdentityProviderEntity (org.orcid.persistence.jpa.entities.IdentityProviderEntity)7 IdentityProviderNameEntity (org.orcid.persistence.jpa.entities.IdentityProviderNameEntity)4 Document (org.w3c.dom.Document)4 Element (org.w3c.dom.Element)4 XPath (javax.xml.xpath.XPath)3 XPathExpression (javax.xml.xpath.XPathExpression)3 ArrayList (java.util.ArrayList)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 Test (org.junit.Test)2 NodeList (org.w3c.dom.NodeList)2 Client (com.sun.jersey.api.client.Client)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Pattern (java.util.regex.Pattern)1