Search in sources :

Example 16 with NoSuchMessageException

use of org.springframework.context.NoSuchMessageException in project ORCID-Source by ORCID.

the class ProfileEntityManagerImpl method getApplications.

@Override
public List<ApplicationSummary> getApplications(String orcid) {
    List<OrcidOauth2TokenDetail> tokenDetails = orcidOauth2TokenService.findByUserName(orcid);
    List<ApplicationSummary> applications = new ArrayList<ApplicationSummary>();
    Map<Pair<String, Set<ScopePathType>>, ApplicationSummary> existingApplications = new HashMap<Pair<String, Set<ScopePathType>>, ApplicationSummary>();
    if (tokenDetails != null && !tokenDetails.isEmpty()) {
        for (OrcidOauth2TokenDetail token : tokenDetails) {
            if (token.getTokenDisabled() == null || !token.getTokenDisabled()) {
                ClientDetailsEntity client = clientDetailsEntityCacheManager.retrieve(token.getClientDetailsId());
                if (client != null) {
                    ApplicationSummary applicationSummary = new ApplicationSummary();
                    // Check the scopes
                    Set<ScopePathType> scopesGrantedToClient = ScopePathType.getScopesFromSpaceSeparatedString(token.getScope());
                    Map<ScopePathType, String> scopePathMap = new HashMap<ScopePathType, String>();
                    String scopeFullPath = ScopePathType.class.getName() + ".";
                    for (ScopePathType tempScope : scopesGrantedToClient) {
                        try {
                            scopePathMap.put(tempScope, localeManager.resolveMessage(scopeFullPath + tempScope.toString()));
                        } catch (NoSuchMessageException e) {
                            LOGGER.warn("No message to display for scope " + tempScope.toString());
                        }
                    }
                    // the application summary element
                    if (!scopePathMap.isEmpty()) {
                        applicationSummary.setScopePaths(scopePathMap);
                        applicationSummary.setOrcidHost(orcidUrlManager.getBaseHost());
                        applicationSummary.setOrcidUri(orcidUrlManager.getBaseUriHttp() + "/" + client.getId());
                        applicationSummary.setOrcidPath(client.getId());
                        applicationSummary.setName(client.getClientName());
                        applicationSummary.setWebsiteValue(client.getClientWebsite());
                        applicationSummary.setApprovalDate(token.getDateCreated());
                        applicationSummary.setTokenId(String.valueOf(token.getId()));
                        // Add member information
                        if (!PojoUtil.isEmpty(client.getGroupProfileId())) {
                            ProfileEntity member = profileEntityCacheManager.retrieve(client.getGroupProfileId());
                            applicationSummary.setGroupOrcidPath(member.getId());
                            applicationSummary.setGroupName(getMemberDisplayName(member));
                        }
                        if (shouldBeAddedToTheApplicationsList(applicationSummary, scopesGrantedToClient, existingApplications)) {
                            applications.add(applicationSummary);
                        }
                    }
                }
            }
        }
    }
    return applications;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) NoSuchMessageException(org.springframework.context.NoSuchMessageException) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationSummary(org.orcid.pojo.ApplicationSummary) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Pair(org.apache.commons.lang3.tuple.Pair)

Example 17 with NoSuchMessageException

use of org.springframework.context.NoSuchMessageException in project webofneeds by researchstudio-sat.

the class LinkedDataWebController method readAtomDeep.

/**
 * This request URL should be protected by WebID filter because the result
 * contains events data - which is data with restricted access. See
 * filterChainProxy in node-context.xml.
 *
 * @param request
 * @param identifier
 * @return
 */
@RequestMapping(value = "${uri.path.data}/atom/{identifier}/deep", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads" })
public ResponseEntity<Dataset> readAtomDeep(HttpServletRequest request, @PathVariable(value = "identifier") String identifier, @RequestParam(value = "layer-size", required = false) Integer layerSize) {
    logger.debug("readAtom() called");
    URI atomUri = URI.create(this.atomResourceURIPrefix + "/" + identifier);
    try {
        Dataset dataset = linkedDataService.getAtomDataset(atomUri, true, layerSize, WonAclRequestHelper.getWonAclEvaluationContext(request));
        // TODO: atom information does change over time. The immutable atom information
        // should never expire, the mutable should
        HttpHeaders headers = new HttpHeaders();
        addCORSHeader(headers);
        return new ResponseEntity<>(dataset, headers, HttpStatus.OK);
    } catch (NoSuchAtomException | NoSuchConnectionException | NoSuchMessageException e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) NoSuchMessageException(org.springframework.context.NoSuchMessageException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) Dataset(org.apache.jena.query.Dataset) NoSuchAtomException(won.protocol.exception.NoSuchAtomException) URI(java.net.URI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with NoSuchMessageException

use of org.springframework.context.NoSuchMessageException in project spring-framework by spring-projects.

the class MessageTag method doEndTag.

/**
 * Resolves the message, escapes it if demanded,
 * and writes it to the page (or exposes it as variable).
 * @see #resolveMessage()
 * @see org.springframework.web.util.HtmlUtils#htmlEscape(String)
 * @see org.springframework.web.util.JavaScriptUtils#javaScriptEscape(String)
 * @see #writeMessage(String)
 */
@Override
public int doEndTag() throws JspException {
    try {
        // Resolve the unescaped message.
        String msg = resolveMessage();
        // HTML and/or JavaScript escape, if demanded.
        msg = htmlEscape(msg);
        msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg;
        // Expose as variable, if demanded, else write to the page.
        if (this.var != null) {
            this.pageContext.setAttribute(this.var, msg, TagUtils.getScope(this.scope));
        } else {
            writeMessage(msg);
        }
        return EVAL_PAGE;
    } catch (IOException ex) {
        throw new JspTagException(ex.getMessage(), ex);
    } catch (NoSuchMessageException ex) {
        throw new JspTagException(getNoSuchMessageExceptionDescription(ex));
    }
}
Also used : NoSuchMessageException(org.springframework.context.NoSuchMessageException) IOException(java.io.IOException) JspTagException(jakarta.servlet.jsp.JspTagException)

Aggregations

NoSuchMessageException (org.springframework.context.NoSuchMessageException)18 Locale (java.util.Locale)5 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 URI (java.net.URI)4 HashMap (java.util.HashMap)4 Dataset (org.apache.jena.query.Dataset)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 NoSuchConnectionException (won.protocol.exception.NoSuchConnectionException)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 Properties (java.util.Properties)2 Set (java.util.Set)2 Pair (org.apache.commons.lang3.tuple.Pair)2 OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)2 ApplicationSummary (org.orcid.pojo.ApplicationSummary)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 NoSuchAtomException (won.protocol.exception.NoSuchAtomException)2