Search in sources :

Example 1 with ClientSummary

use of org.orcid.jaxb.model.v3.dev1.client.ClientSummary in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method viewClient.

@Override
public Response viewClient(String clientId) {
    orcidSecurityManager.checkScopes(ScopePathType.READ_PUBLIC);
    ClientSummary client = clientManagerReadOnly.getSummary(clientId);
    return Response.ok(client).build();
}
Also used : ClientSummary(org.orcid.jaxb.model.v3.dev1.client.ClientSummary)

Example 2 with ClientSummary

use of org.orcid.jaxb.model.v3.dev1.client.ClientSummary in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_GeneralTest method testViewClient.

@Test
public void testViewClient() {
    Response response = serviceDelegator.viewClient("APP-6666666666666666");
    assertNotNull(response.getEntity());
    assertTrue(response.getEntity() instanceof ClientSummary);
    ClientSummary clientSummary = (ClientSummary) response.getEntity();
    assertEquals("Source Client 2", clientSummary.getName());
    assertEquals("A test source client", clientSummary.getDescription());
}
Also used : Response(javax.ws.rs.core.Response) ClientSummary(org.orcid.jaxb.model.v3.dev1.client.ClientSummary) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with ClientSummary

use of org.orcid.jaxb.model.v3.dev1.client.ClientSummary in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getClientMapperFacade.

public MapperFacade getClientMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<ClientSummary, ClientDetailsEntity> clientSummaryClassMap = mapperFactory.classMap(ClientSummary.class, ClientDetailsEntity.class);
    clientSummaryClassMap.field("name", "clientName");
    clientSummaryClassMap.field("description", "clientDescription");
    clientSummaryClassMap.byDefault();
    clientSummaryClassMap.register();
    ClassMapBuilder<Client, ClientDetailsEntity> clientClassMap = mapperFactory.classMap(Client.class, ClientDetailsEntity.class);
    clientClassMap.field("name", "clientName");
    clientClassMap.field("description", "clientDescription");
    clientClassMap.field("website", "clientWebsite");
    clientClassMap.field("allowAutoDeprecate", "allowAutoDeprecate");
    clientClassMap.fieldBToA("clientId", "id");
    clientClassMap.fieldBToA("clientType", "clientType");
    clientClassMap.fieldBToA("groupProfileId", "groupProfileId");
    clientClassMap.fieldBToA("authenticationProviderId", "authenticationProviderId");
    clientClassMap.fieldBToA("persistentTokensEnabled", "persistentTokensEnabled");
    clientClassMap.customize(new CustomMapper<Client, ClientDetailsEntity>() {

        /**
         * On the way in, from Client to ClientDetailsEntity, we need to care about mapping the redirect uri's, since all config features will not change from UI requests
         */
        @Override
        public void mapAtoB(Client a, ClientDetailsEntity b, MappingContext context) {
            Map<String, ClientRedirectUriEntity> existingRedirectUriEntitiesMap = new HashMap<String, ClientRedirectUriEntity>();
            if (b.getClientRegisteredRedirectUris() != null && !b.getClientRegisteredRedirectUris().isEmpty()) {
                existingRedirectUriEntitiesMap = ClientRedirectUriEntity.mapByUriAndType(b.getClientRegisteredRedirectUris());
            }
            if (b.getClientRegisteredRedirectUris() != null) {
                b.getClientRegisteredRedirectUris().clear();
            } else {
                b.setClientRegisteredRedirectUris(new TreeSet<ClientRedirectUriEntity>());
            }
            if (a.getClientRedirectUris() != null) {
                for (ClientRedirectUri cru : a.getClientRedirectUris()) {
                    String rUriKey = ClientRedirectUriEntity.getUriAndTypeKey(cru.getRedirectUri(), cru.getRedirectUriType());
                    if (existingRedirectUriEntitiesMap.containsKey(rUriKey)) {
                        ClientRedirectUriEntity existingEntity = existingRedirectUriEntitiesMap.get(rUriKey);
                        existingEntity.setLastModified(new Date());
                        existingEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(cru.getPredefinedClientScopes()));
                        existingEntity.setUriActType(cru.getUriActType());
                        existingEntity.setUriGeoArea(cru.getUriGeoArea());
                        b.getClientRegisteredRedirectUris().add(existingEntity);
                    } else {
                        ClientRedirectUriEntity newEntity = new ClientRedirectUriEntity();
                        newEntity.setClientDetailsEntity(b);
                        newEntity.setDateCreated(new Date());
                        newEntity.setLastModified(new Date());
                        newEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(cru.getPredefinedClientScopes()));
                        newEntity.setRedirectUri(cru.getRedirectUri());
                        newEntity.setRedirectUriType(cru.getRedirectUriType());
                        newEntity.setUriActType(cru.getUriActType());
                        newEntity.setUriGeoArea(cru.getUriGeoArea());
                        b.getClientRegisteredRedirectUris().add(newEntity);
                    }
                }
            }
        }

        /**
         * On the way out, from ClientDetailsEntity to Client, we just need to care about mapping the redirect uri's and the primary client secret since all config features will not be visible on the UI
         */
        @Override
        public void mapBtoA(ClientDetailsEntity b, Client a, MappingContext context) {
            if (b.getClientSecrets() != null) {
                for (ClientSecretEntity entity : b.getClientSecrets()) {
                    if (entity.isPrimary()) {
                        a.setDecryptedSecret(encryptionManager.decryptForInternalUse(entity.getClientSecret()));
                    }
                }
            }
            if (b.getRegisteredRedirectUri() != null) {
                a.setClientRedirectUris(new HashSet<ClientRedirectUri>());
                for (ClientRedirectUriEntity entity : b.getClientRegisteredRedirectUris()) {
                    ClientRedirectUri element = new ClientRedirectUri();
                    element.setRedirectUri(entity.getRedirectUri());
                    element.setRedirectUriType(entity.getRedirectUriType());
                    element.setUriActType(entity.getUriActType());
                    element.setUriGeoArea(entity.getUriGeoArea());
                    element.setPredefinedClientScopes(ScopePathType.getScopesFromSpaceSeparatedString(entity.getPredefinedClientScope()));
                    a.getClientRedirectUris().add(element);
                }
            }
        }
    });
    clientClassMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientRedirectUri(org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri) ClientSummary(org.orcid.jaxb.model.v3.dev1.client.ClientSummary) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity) Date(java.util.Date) FuzzyDate(org.orcid.jaxb.model.v3.dev1.common.FuzzyDate) PublicationDate(org.orcid.jaxb.model.v3.dev1.common.PublicationDate) MappingContext(ma.glasnost.orika.MappingContext) TreeSet(java.util.TreeSet) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) Client(org.orcid.jaxb.model.v3.dev1.client.Client) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 4 with ClientSummary

use of org.orcid.jaxb.model.v3.dev1.client.ClientSummary in project ORCID-Source by ORCID.

the class ClientManagerReadOnlyTest method getSummaryTest.

@Test
public void getSummaryTest() {
    String seed = RandomStringUtils.randomAlphanumeric(30);
    when(daoMock.findByClientId(anyString(), anyLong())).thenReturn(getClientDetailsEntity(seed));
    ClientSummary summary = clientManagerReadOnly.getSummary(seed);
    assertEquals(getClientSummary(seed), summary);
}
Also used : ClientSummary(org.orcid.jaxb.model.v3.dev1.client.ClientSummary) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 5 with ClientSummary

use of org.orcid.jaxb.model.v3.dev1.client.ClientSummary in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method getClientSummary.

private ClientSummary getClientSummary() {
    ClientSummary summary = new ClientSummary();
    summary.setDescription("description");
    summary.setName("client-name");
    return summary;
}
Also used : ClientSummary(org.orcid.jaxb.model.v3.dev1.client.ClientSummary)

Aggregations

ClientSummary (org.orcid.jaxb.model.v3.dev1.client.ClientSummary)7 Test (org.junit.Test)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Response (javax.ws.rs.core.Response)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 MappingContext (ma.glasnost.orika.MappingContext)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Client (org.orcid.jaxb.model.v3.dev1.client.Client)1 ClientRedirectUri (org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri)1 FuzzyDate (org.orcid.jaxb.model.v3.dev1.common.FuzzyDate)1 PublicationDate (org.orcid.jaxb.model.v3.dev1.common.PublicationDate)1 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)1 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)1 DBUnitTest (org.orcid.test.DBUnitTest)1