Search in sources :

Example 1 with ImportWizzardClientForm

use of org.orcid.pojo.ajaxForm.ImportWizzardClientForm in project ORCID-Source by ORCID.

the class ThirdPartyLinkManagerImpl method generateImportWizzardForm.

private List<ImportWizzardClientForm> generateImportWizzardForm(RedirectUriType rut, Locale locale) {
    List<ClientRedirectUriEntity> entitiesWithPredefinedScopes = clientRedirectDao.findClientDetailsWithRedirectScope();
    List<ImportWizzardClientForm> clients = new ArrayList<ImportWizzardClientForm>();
    for (ClientRedirectUriEntity entity : entitiesWithPredefinedScopes) {
        if (rut.value().equals(entity.getRedirectUriType())) {
            if (rut.value().equals(entity.getRedirectUriType())) {
                ClientDetailsEntity clientDetails = entity.getClientDetailsEntity();
                ImportWizzardClientForm clientForm = new ImportWizzardClientForm();
                clientForm.setId(clientDetails.getId());
                clientForm.setName(clientDetails.getClientName());
                clientForm.setDescription(clientDetails.getClientDescription());
                clientForm.setRedirectUri(entity.getRedirectUri());
                clientForm.setScopes(entity.getPredefinedClientScope());
                if (RedirectUriType.IMPORT_WORKS_WIZARD.equals(rut)) {
                    if (!PojoUtil.isEmpty(entity.getUriActType())) {
                        JsonNode node = JsonUtils.readTree(entity.getUriActType());
                        List<String> elements = new ArrayList<String>();
                        if (node.has("import-works-wizard")) {
                            node.get("import-works-wizard").forEach(x -> {
                                String value = x.asText();
                                switch(value) {
                                    case "Articles":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.work_type.articles", locale));
                                        break;
                                    case "Data":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.work_type.books", locale));
                                        break;
                                    case "Books":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.work_type.data", locale));
                                        break;
                                    case "Student Publications":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.work_type.student_publications", locale));
                                        break;
                                    default:
                                        elements.add(value);
                                        break;
                                }
                            });
                        }
                        clientForm.setActTypes(elements);
                    }
                    if (!PojoUtil.isEmpty(entity.getUriActType())) {
                        JsonNode node = JsonUtils.readTree(entity.getUriGeoArea());
                        List<String> elements = new ArrayList<String>();
                        if (node.has("import-works-wizard")) {
                            node.get("import-works-wizard").forEach(x -> {
                                String value = x.asText();
                                switch(value) {
                                    case "Africa":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.africa", locale));
                                        break;
                                    case "Asia":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.asia", locale));
                                        break;
                                    case "Australia":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.australia", locale));
                                        break;
                                    case "Europe":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.europe", locale));
                                        break;
                                    case "Global":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.global", locale));
                                        break;
                                    case "North America":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.north_america", locale));
                                        break;
                                    case "South America":
                                        elements.add(localeManager.resolveMessage("workspace.works.import_wizzard.geo_area.south_america", locale));
                                        break;
                                    default:
                                        elements.add(value);
                                        break;
                                }
                            });
                        }
                        clientForm.setGeoAreas(elements);
                    }
                }
                clients.add(clientForm);
            }
        }
    }
    return clients;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ImportWizzardClientForm(org.orcid.pojo.ajaxForm.ImportWizzardClientForm) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)

Example 2 with ImportWizzardClientForm

use of org.orcid.pojo.ajaxForm.ImportWizzardClientForm in project ORCID-Source by ORCID.

the class WorkspaceController method getSourceGrantReadWizard.

@RequestMapping(value = "/my-orcid/sourceGrantReadWizard.json", method = RequestMethod.GET)
@ResponseBody
public ThirdPartyRedirect getSourceGrantReadWizard() {
    ThirdPartyRedirect tpr = new ThirdPartyRedirect();
    ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
    if (profile.getSource() == null || profile.getSource().getSourceId() == null) {
        return tpr;
    }
    String sourcStr = profile.getSource().getSourceId();
    // Check that the cache is up to date
    evictThirdPartyLinkManagerCacheIfNeeded();
    // Get list of clients
    List<ImportWizzardClientForm> clients = thirdPartyLinkManager.findOrcidClientsWithPredefinedOauthScopeReadAccess(localeManager.getLocale());
    for (ImportWizzardClientForm client : clients) {
        if (sourcStr.equals(client.getId())) {
            String redirect = getBaseUri() + "/oauth/authorize?client_id=" + client.getId() + "&response_type=code&scope=" + client.getScopes() + "&redirect_uri=" + client.getRedirectUri();
            tpr.setUrl(redirect);
            tpr.setDisplayName(client.getName());
            tpr.setShortDescription(client.getDescription());
            return tpr;
        }
    }
    return tpr;
}
Also used : ThirdPartyRedirect(org.orcid.pojo.ThirdPartyRedirect) ImportWizzardClientForm(org.orcid.pojo.ajaxForm.ImportWizzardClientForm) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ImportWizzardClientForm (org.orcid.pojo.ajaxForm.ImportWizzardClientForm)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)1 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 ThirdPartyRedirect (org.orcid.pojo.ThirdPartyRedirect)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1