Search in sources :

Example 1 with Client

use of org.powerbot.bot.rt6.client.Client in project ORCID-Source by ORCID.

the class PublicV3ApiServiceDelegatorTest method testViewClient.

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

Example 2 with Client

use of org.powerbot.bot.rt6.client.Client 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 3 with Client

use of org.powerbot.bot.rt6.client.Client in project ORCID-Source by ORCID.

the class ClientManagerReadOnlyTest method getClientsTest.

@Test
public void getClientsTest() {
    String seed1 = RandomStringUtils.randomAlphanumeric(30);
    String seed2 = RandomStringUtils.randomAlphanumeric(30);
    String seed3 = RandomStringUtils.randomAlphanumeric(30);
    List<ClientDetailsEntity> clients = new ArrayList<ClientDetailsEntity>();
    clients.add(getClientDetailsEntity(seed1));
    clients.add(getClientDetailsEntity(seed2));
    clients.add(getClientDetailsEntity(seed3));
    when(daoMock.findByGroupId(anyString())).thenReturn(clients);
    Set<Client> results = clientManagerReadOnly.getClients("anything");
    assertEquals(3, results.size());
    for (Client client : results) {
        if (client.getId().equals(seed1)) {
            assertEquals(getClient(seed1), client);
        } else if (client.getId().equals(seed2)) {
            assertEquals(getClient(seed2), client);
        } else if (client.getId().equals(seed3)) {
            assertEquals(getClient(seed3), client);
        } else {
            fail("Unknown id " + client.getId());
        }
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Client(org.orcid.jaxb.model.v3.dev1.client.Client) Test(org.junit.Test)

Example 4 with Client

use of org.powerbot.bot.rt6.client.Client in project ORCID-Source by ORCID.

the class ClientManagerReadOnlyTest method getClient.

private Client getClient(String randomString) {
    Client client = new Client();
    client.setAllowAutoDeprecate(true);
    client.setPersistentTokensEnabled(true);
    client.setClientType(ClientType.CREATOR);
    client.setDescription("description " + randomString);
    client.setGroupProfileId("group-profile-id " + randomString);
    client.setId(randomString);
    client.setName("client-name " + randomString);
    client.setWebsite("client-website " + randomString);
    client.setAuthenticationProviderId("authentication-provider-id " + randomString);
    Set<ClientRedirectUri> clientRedirectUris = new HashSet<ClientRedirectUri>();
    ClientRedirectUri rUri1 = new ClientRedirectUri();
    Set<ScopePathType> scopes1 = new HashSet<ScopePathType>();
    scopes1.add(ScopePathType.ACTIVITIES_READ_LIMITED);
    rUri1.setPredefinedClientScopes(scopes1);
    rUri1.setRedirectUri("redirect-uri-1 " + randomString);
    rUri1.setRedirectUriType("type-1 " + randomString);
    rUri1.setUriActType("uri-act-type-1 " + randomString);
    rUri1.setUriGeoArea("uri-geo-area-1 " + randomString);
    ClientRedirectUri rUri2 = new ClientRedirectUri();
    Set<ScopePathType> scopes2 = new HashSet<ScopePathType>();
    scopes2.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri2.setPredefinedClientScopes(scopes2);
    rUri2.setRedirectUri("redirect-uri-2 " + randomString);
    rUri2.setRedirectUriType("type-2 " + randomString);
    rUri2.setUriActType("uri-act-type-2 " + randomString);
    rUri2.setUriGeoArea("uri-geo-area-2 " + randomString);
    ClientRedirectUri rUri3 = new ClientRedirectUri();
    Set<ScopePathType> scopes3 = new HashSet<ScopePathType>();
    scopes3.add(ScopePathType.AFFILIATIONS_CREATE);
    rUri3.setPredefinedClientScopes(scopes3);
    rUri3.setRedirectUri("redirect-uri-3 " + randomString);
    rUri3.setRedirectUriType("type-3 " + randomString);
    rUri3.setUriActType("uri-act-type-3 " + randomString);
    rUri3.setUriGeoArea("uri-geo-area-3 " + randomString);
    clientRedirectUris.add(rUri1);
    clientRedirectUris.add(rUri2);
    clientRedirectUris.add(rUri3);
    client.setClientRedirectUris(clientRedirectUris);
    return client;
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.v3.dev1.client.Client) HashSet(java.util.HashSet)

Example 5 with Client

use of org.powerbot.bot.rt6.client.Client in project ORCID-Source by ORCID.

the class MembersManagerImpl method getMember.

@Override
@Transactional
public Member getMember(String memberId) {
    Member member = new Member();
    String orcid = memberId;
    if (!OrcidStringUtils.isValidOrcid(memberId)) {
        Map<String, String> ids = emailManager.findOricdIdsByCommaSeparatedEmails(memberId);
        // Check if it is using the email
        if (ids != null && ids.containsKey(memberId)) {
            orcid = ids.get(memberId);
        } else {
            // Check if can find it by name
            try {
                orcid = profileEntityManager.findByCreditName(memberId);
            } catch (Exception e) {
                member.getErrors().add(getMessage("manage_member.email_not_found"));
                orcid = null;
            }
        }
    }
    if (PojoUtil.isEmpty(orcid)) {
        member.getErrors().add(getMessage("manage_member.email_not_found"));
    } else {
        if (profileEntityManager.orcidExists(orcid)) {
            MemberType groupType = profileEntityManager.getGroupType(orcid);
            if (groupType != null) {
                ProfileEntity memberProfile = profileDao.find(orcid);
                member = Member.fromProfileEntity(memberProfile);
                Set<Client> clients = clientManagerReadOnly.getClients(orcid);
                List<org.orcid.pojo.ajaxForm.Client> clientsList = new ArrayList<org.orcid.pojo.ajaxForm.Client>();
                clients.forEach(c -> {
                    clientsList.add(org.orcid.pojo.ajaxForm.Client.fromModelObject(c));
                });
                member.setClients(clientsList);
            } else {
                member.getErrors().add(getMessage("manage_members.orcid_is_not_a_member"));
            }
        } else {
            member.getErrors().add(getMessage("manage_members.orcid_doesnt_exists"));
        }
    }
    return member;
}
Also used : ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) MemberType(org.orcid.jaxb.model.clientgroup.MemberType) Client(org.orcid.jaxb.model.v3.dev1.client.Client) Member(org.orcid.pojo.ajaxForm.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Client (org.powerbot.bot.rt4.client.Client)36 Client (org.powerbot.bot.rt6.client.Client)33 Point (java.awt.Point)26 ArrayList (java.util.ArrayList)13 Client (org.orcid.jaxb.model.v3.dev1.client.Client)11 Test (org.junit.Test)8 Tile (org.powerbot.script.Tile)8 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 HashSet (java.util.HashSet)5 Rectangle (java.awt.Rectangle)4 Reflector (org.powerbot.bot.Reflector)4 Condition (org.powerbot.script.Condition)4 Client (client.Client)3 LinkedList (java.util.LinkedList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ClientRedirectUri (org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri)3 Graphics (java.awt.Graphics)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2