org.springframework.hateoas.mvc.TypeReferences Java Examples
The following examples show how to use
org.springframework.hateoas.mvc.TypeReferences.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
protected Collection<Resource<ToolItemRubricAssociation>> getRubricAssociationByRubric(String rubricId, String toSite) throws Exception { TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-rubric-id"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, toSite))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("rubricId", Long.valueOf(rubricId)); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); return associationResources.getContent(); }
Example #2
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
@Override public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> options) { Map<String, String> transversalMap = new HashMap<>(); try { TypeReferences.ResourcesType<Resource<Rubric>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<Rubric>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubrics", "search", "rubrics-from-site"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, toContext))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("siteId", fromContext); Resources<Resource<Rubric>> rubricResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<Rubric> rubricResource : rubricResources) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers2 = new HttpHeaders(); headers2.setContentType(MediaType.APPLICATION_JSON); headers2.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, toContext))); HttpEntity<?> requestEntity = new HttpEntity<>(headers2); ResponseEntity<Rubric> rubricEntity = restTemplate.exchange(rubricResource.getLink(Link.REL_SELF).getHref()+"?projection=inlineRubric", HttpMethod.GET, requestEntity, Rubric.class); Rubric rEntity = rubricEntity.getBody(); String newId = cloneRubricToSite(String.valueOf(rEntity.getId()), toContext); String oldId = String.valueOf(rEntity.getId()); transversalMap.put(RubricsConstants.RBCS_PREFIX+oldId, RubricsConstants.RBCS_PREFIX+newId); } } catch (Exception ex){ log.info("Exception on duplicateRubricsFromSite: " + ex.getMessage()); } return transversalMap; }
Example #3
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
protected Collection<Resource<Evaluation>> getRubricEvaluationsByAssociation(Long associationId) throws Exception { TypeReferences.ResourcesType<Resource<Evaluation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<Evaluation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("evaluations", "search", "by-association-id"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolItemRubricAssociationId", associationId); Resources<Resource<Evaluation>> evaluationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); return evaluationResources.getContent(); }
Example #4
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
protected Collection<Resource<ToolItemRubricAssociation>> getRubricAssociationByRubric(String rubricId, String toSite) throws Exception { TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-rubric-id"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, toSite))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("rubricId", Long.valueOf(rubricId)); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); return associationResources.getContent(); }
Example #5
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
protected Collection<Resource<Evaluation>> getRubricEvaluationsByAssociation(Long associationId) throws Exception { TypeReferences.ResourcesType<Resource<Evaluation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<Evaluation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("evaluations", "search", "by-association-id"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolItemRubricAssociationId", associationId); Resources<Resource<Evaluation>> evaluationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); return evaluationResources.getContent(); }
Example #6
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public void softDeleteRubricAssociationsByItemIdPrefix(String itemId, String toolId) { try{ TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-item-id-prefix"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", itemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<ToolItemRubricAssociation> associationResource : associationResources) { String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); ToolItemRubricAssociation association = associationResource.getContent(); String created = association.getMetadata().getCreated().toString(); String owner = association.getMetadata().getOwnerId(); String ownerType = association.getMetadata().getOwnerType(); String creatorId = association.getMetadata().getCreatorId(); Map <String,Boolean> oldParams = association.getParameters(); oldParams.put(RubricsConstants.RBCS_SOFT_DELETED, true); String input = "{\"toolId\" : \""+toolId+"\",\"itemId\" : \"" + association.getItemId() + "\",\"rubricId\" : " + association.getRubricId() + ",\"metadata\" : {\"created\" : \"" + created + "\",\"ownerId\" : \"" + owner + "\",\"ownerType\" : \"" + ownerType + "\",\"creatorId\" : \"" + creatorId + "\"},\"parameters\" : {" + setConfigurationParametersForDuplication(oldParams) + "}}"; log.debug("Soft delete association {}", input); String resultPut = putRubricResource(associationHref, input, toolId, null); log.debug("resultPUT: {}", resultPut); } } catch (Exception e) { log.warn("Error soft deleting rubric association for item id prefix {} : {}", itemId, e.getMessage()); } }
Example #7
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public void deleteSiteRubrics(String siteId) { try { TypeReferences.ResourcesType<Resource<Rubric>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<Rubric>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubrics", "search", "rubrics-from-site"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, siteId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("siteId", siteId); Resources<Resource<Rubric>> rubricResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<Rubric> rubricResource : rubricResources) { String [] rubricSplitted = rubricResource.getLink(Link.REL_SELF).getHref().split("/"); Collection<Resource<ToolItemRubricAssociation>> assocs = getRubricAssociationByRubric(rubricSplitted[rubricSplitted.length-1],siteId); for(Resource<ToolItemRubricAssociation> associationResource : assocs){ String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); deleteRubricResource(associationHref, RubricsConstants.RBCS_TOOL, siteId); } deleteRubricResource(rubricResource.getLink(Link.REL_SELF).getHref(), RubricsConstants.RBCS_TOOL, siteId); } } catch(Exception e){ log.error("Rubrics: error trying to delete rubric -> {}" , e.getMessage()); } }
Example #8
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public void restoreRubricAssociationsByItemIdPrefix(String itemId, String toolId) { try{ TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-item-id-prefix"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", itemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<ToolItemRubricAssociation> associationResource : associationResources) { String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); ToolItemRubricAssociation association = associationResource.getContent(); String created = association.getMetadata().getCreated().toString(); String owner = association.getMetadata().getOwnerId(); String ownerType = association.getMetadata().getOwnerType(); String creatorId = association.getMetadata().getCreatorId(); Map <String,Boolean> oldParams = association.getParameters(); oldParams.put(RubricsConstants.RBCS_SOFT_DELETED, false); String input = "{\"toolId\" : \""+toolId+"\",\"itemId\" : \"" + association.getItemId() + "\",\"rubricId\" : " + association.getRubricId() + ",\"metadata\" : {\"created\" : \"" + created + "\",\"ownerId\" : \"" + owner + "\",\"ownerType\" : \"" + ownerType + "\",\"creatorId\" : \"" + creatorId + "\"},\"parameters\" : {" + setConfigurationParametersForDuplication(oldParams) + "}}"; log.debug("Restoring association {}", input); String resultPut = putRubricResource(associationHref, input, toolId, null); log.debug("resultPUT: {}", resultPut); } } catch (Exception e) { log.warn("Error restoring rubric association for id {} : {}", itemId, e.getMessage()); } }
Example #9
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public void softDeleteRubricAssociationsByItemIdPrefix(String itemId, String toolId) { try{ TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-item-id-prefix"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", itemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<ToolItemRubricAssociation> associationResource : associationResources) { String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); ToolItemRubricAssociation association = associationResource.getContent(); String created = association.getMetadata().getCreated().toString(); String owner = association.getMetadata().getOwnerId(); String ownerType = association.getMetadata().getOwnerType(); String creatorId = association.getMetadata().getCreatorId(); Map <String,Boolean> oldParams = association.getParameters(); oldParams.put(RubricsConstants.RBCS_SOFT_DELETED, true); String input = "{\"toolId\" : \""+toolId+"\",\"itemId\" : \"" + association.getItemId() + "\",\"rubricId\" : " + association.getRubricId() + ",\"metadata\" : {\"created\" : \"" + created + "\",\"ownerId\" : \"" + owner + "\",\"ownerType\" : \"" + ownerType + "\",\"creatorId\" : \"" + creatorId + "\"},\"parameters\" : {" + setConfigurationParametersForDuplication(oldParams) + "}}"; log.debug("Soft delete association {}", input); String resultPut = putRubricResource(associationHref, input, toolId, null); log.debug("resultPUT: {}", resultPut); } } catch (Exception e) { log.warn("Error soft deleting rubric association for item id prefix {} : {}", itemId, e.getMessage()); } }
Example #10
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Delete all the rubric associations starting with itemId. * @param itemId The formatted item id. */ public void deleteRubricAssociationsByItemIdPrefix(String itemId, String toolId) { try{ TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-item-id-prefix"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", itemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters( parameters).toObject(resourceParameterizedTypeReference); for (Resource<ToolItemRubricAssociation> associationResource : associationResources) { String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); deleteRubricEvaluationsForAssociation(associationHref, toolId); deleteRubricResource(associationHref, toolId, null); hasAssociatedRubricCache.remove(toolId + "#" + itemId); } } catch (Exception e) { log.warn("Error deleting rubric association for id {} : {}", itemId, e.getMessage()); } }
Example #11
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Returns the ToolItemRubricAssociation resource for the given tool and associated item ID, wrapped as an Optional. * @param toolId the tool id, something like "sakai.assignment" * @param associatedToolItemId the id of the associated element within the tool * @return */ protected Optional<Resource<ToolItemRubricAssociation>> getRubricAssociationResource(String toolId, String associatedToolItemId, String siteId) throws Exception { TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-tool-item-ids"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId, siteId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", associatedToolItemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters( parameters).toObject(resourceParameterizedTypeReference); // Should only be one matching this search criterion if (associationResources.getContent().size() > 1) { throw new IllegalStateException(String.format( "Number of rubric association resources greater than one for request: %s", associationResources.getLink(Link.REL_SELF).toString())); } Optional<Resource<ToolItemRubricAssociation>> associationResource = associationResources.getContent().stream().findFirst(); return associationResource; }
Example #12
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public void deleteSiteRubrics(String siteId) { try { TypeReferences.ResourcesType<Resource<Rubric>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<Rubric>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubrics", "search", "rubrics-from-site"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, siteId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("siteId", siteId); Resources<Resource<Rubric>> rubricResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<Rubric> rubricResource : rubricResources) { String [] rubricSplitted = rubricResource.getLink(Link.REL_SELF).getHref().split("/"); Collection<Resource<ToolItemRubricAssociation>> assocs = getRubricAssociationByRubric(rubricSplitted[rubricSplitted.length-1],siteId); for(Resource<ToolItemRubricAssociation> associationResource : assocs){ String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); deleteRubricResource(associationHref, RubricsConstants.RBCS_TOOL, siteId); } deleteRubricResource(rubricResource.getLink(Link.REL_SELF).getHref(), RubricsConstants.RBCS_TOOL, siteId); } } catch(Exception e){ log.error("Rubrics: error trying to delete rubric -> {}" , e.getMessage()); } }
Example #13
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
@Override public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> options) { Map<String, String> transversalMap = new HashMap<>(); try { TypeReferences.ResourcesType<Resource<Rubric>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<Rubric>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubrics", "search", "rubrics-from-site"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, toContext))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("siteId", fromContext); Resources<Resource<Rubric>> rubricResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<Rubric> rubricResource : rubricResources) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers2 = new HttpHeaders(); headers2.setContentType(MediaType.APPLICATION_JSON); headers2.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL, toContext))); HttpEntity<?> requestEntity = new HttpEntity<>(headers2); ResponseEntity<Rubric> rubricEntity = restTemplate.exchange(rubricResource.getLink(Link.REL_SELF).getHref()+"?projection=inlineRubric", HttpMethod.GET, requestEntity, Rubric.class); Rubric rEntity = rubricEntity.getBody(); String newId = cloneRubricToSite(String.valueOf(rEntity.getId()), toContext); String oldId = String.valueOf(rEntity.getId()); transversalMap.put(RubricsConstants.RBCS_PREFIX+oldId, RubricsConstants.RBCS_PREFIX+newId); } } catch (Exception ex){ log.info("Exception on duplicateRubricsFromSite: " + ex.getMessage()); } return transversalMap; }
Example #14
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public void restoreRubricAssociationsByItemIdPrefix(String itemId, String toolId) { try{ TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-item-id-prefix"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", itemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(parameters).toObject(resourceParameterizedTypeReference); for (Resource<ToolItemRubricAssociation> associationResource : associationResources) { String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); ToolItemRubricAssociation association = associationResource.getContent(); String created = association.getMetadata().getCreated().toString(); String owner = association.getMetadata().getOwnerId(); String ownerType = association.getMetadata().getOwnerType(); String creatorId = association.getMetadata().getCreatorId(); Map <String,Boolean> oldParams = association.getParameters(); oldParams.put(RubricsConstants.RBCS_SOFT_DELETED, false); String input = "{\"toolId\" : \""+toolId+"\",\"itemId\" : \"" + association.getItemId() + "\",\"rubricId\" : " + association.getRubricId() + ",\"metadata\" : {\"created\" : \"" + created + "\",\"ownerId\" : \"" + owner + "\",\"ownerType\" : \"" + ownerType + "\",\"creatorId\" : \"" + creatorId + "\"},\"parameters\" : {" + setConfigurationParametersForDuplication(oldParams) + "}}"; log.debug("Restoring association {}", input); String resultPut = putRubricResource(associationHref, input, toolId, null); log.debug("resultPUT: {}", resultPut); } } catch (Exception e) { log.warn("Error restoring rubric association for id {} : {}", itemId, e.getMessage()); } }
Example #15
Source File: XyzApplication.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@GetMapping("{username}/messages") public String userMessages(@PathVariable("username") String username, Model model) { RequestEntity<Void> request = RequestEntity .get(URI.create(String.format("http://localhost:8080/messages/search/messagesBy?username=%s", username))) .build(); ResponseEntity<Resources<Message>> response = restTemplate.exchange(request, new TypeReferences.ResourcesType<Message>() {}); model.addAttribute("title", String.format("%s 的訊息", username)); model.addAttribute("messages", new ArrayList<>(response.getBody().getContent())); return "user"; }
Example #16
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Delete all the rubric associations starting with itemId. * @param itemId The formatted item id. */ public void deleteRubricAssociationsByItemIdPrefix(String itemId, String toolId) { try{ TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-item-id-prefix"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", itemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters( parameters).toObject(resourceParameterizedTypeReference); for (Resource<ToolItemRubricAssociation> associationResource : associationResources) { String associationHref = associationResource.getLink(Link.REL_SELF).getHref(); deleteRubricEvaluationsForAssociation(associationHref, toolId); deleteRubricResource(associationHref, toolId, null); hasAssociatedRubricCache.remove(toolId + "#" + itemId); } } catch (Exception e) { log.warn("Error deleting rubric association for id {} : {}", itemId, e.getMessage()); } }
Example #17
Source File: RubricsServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Returns the ToolItemRubricAssociation resource for the given tool and associated item ID, wrapped as an Optional. * @param toolId the tool id, something like "sakai.assignment" * @param associatedToolItemId the id of the associated element within the tool * @return */ protected Optional<Resource<ToolItemRubricAssociation>> getRubricAssociationResource(String toolId, String associatedToolItemId, String siteId) throws Exception { TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference = new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {}; URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX); Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON); Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search", "by-tool-item-ids"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId, siteId))); builder.withHeaders(headers); Map<String, Object> parameters = new HashMap<>(); parameters.put("toolId", toolId); parameters.put("itemId", associatedToolItemId); Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters( parameters).toObject(resourceParameterizedTypeReference); // Should only be one matching this search criterion if (associationResources.getContent().size() > 1) { throw new IllegalStateException(String.format( "Number of rubric association resources greater than one for request: %s", associationResources.getLink(Link.REL_SELF).toString())); } Optional<Resource<ToolItemRubricAssociation>> associationResource = associationResources.getContent().stream().findFirst(); return associationResource; }
Example #18
Source File: AsyncGetService.java From orders with Apache License 2.0 | 5 votes |
@Async public <T> Future<Resources<T>> getDataList(URI url, TypeReferences.ResourcesType<T> type) throws InterruptedException, IOException { RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build(); LOG.debug("Requesting: " + request.toString()); Resources<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody(); LOG.debug("Received: " + body.toString()); return new AsyncResult<>(body); }
Example #19
Source File: AsyncGetService.java From orders with Apache License 2.0 | 5 votes |
@Async public <T> Future<Resource<T>> getResource(URI url, TypeReferences.ResourceType<T> type) throws InterruptedException, IOException { RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build(); LOG.debug("Requesting: " + request.toString()); Resource<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody(); LOG.debug("Received: " + body.toString()); return new AsyncResult<>(body); }
Example #20
Source File: MessageServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
public List<Message> newestMessages(int n) { RequestEntity<Void> request = RequestEntity .get(URI.create(String.format("http://localhost:8083/newestMessages?n=%d", n))) .build(); ResponseEntity<Resources<Message>> response = restTemplate.exchange(request, new TypeReferences.ResourcesType<Message>() {}); return new ArrayList<>(response.getBody().getContent()); }
Example #21
Source File: MessageServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
public List<Message> messages(String username) { RequestEntity<Void> request = RequestEntity .get(URI.create(String.format("http://localhost:8083/messagesBy?username=%s", username))) .build(); ResponseEntity<Resources<Message>> response = restTemplate.exchange(request, new TypeReferences.ResourcesType<Message>() {}); return new ArrayList<>(response.getBody().getContent()); }
Example #22
Source File: AccountServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Optional<Account> accountByName(String name) { RequestEntity<Void> request = RequestEntity .get(URI.create(String.format("http://localhost:8084/accountByName?username=%s", name))) .build(); ResponseEntity<Resource<Account>> response = restTemplate.exchange(request, new TypeReferences.ResourceType<Account>() {}); return Optional.ofNullable(response.getBody().getContent()); }
Example #23
Source File: AccountServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
public Optional<Account> accountByNameEmail(String name, String email) { RequestEntity<Void> request = RequestEntity .get(URI.create(String.format("http://localhost:8084/accountByNameEmail?username=%s&email=%s", name, email))) .build(); ResponseEntity<Resource<Account>> response = restTemplate.exchange(request, new TypeReferences.ResourceType<Account>() {}); return Optional.ofNullable(response.getBody().getContent()); }
Example #24
Source File: AccountServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
public Optional<Account> verify(String email, String token) { RequestEntity<Void> request = RequestEntity .put(URI.create(String.format("http://localhost:8084/verify?email=%s&token=%s", email, token))) .build(); ResponseEntity<Resource<Account>> response = restTemplate.exchange(request, new TypeReferences.ResourceType<Account>() {}); return Optional.ofNullable(response.getBody().getContent()); }
Example #25
Source File: AccountServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
public boolean userExisted(String username) { RequestEntity<Void> request = RequestEntity .post(URI.create(String.format("http://localhost:8084/userExisted?username=%s", username))) .build(); ResponseEntity<Resource<Boolean>> response = restTemplate.exchange(request, new TypeReferences.ResourceType<Boolean>() {}); return response.getBody().getContent(); }
Example #26
Source File: AccountServiceRest.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
public Optional<Account> tryCreateUser(String email, String username, String password) { RequestEntity<Void> request = RequestEntity .post(URI.create(String.format("http://localhost:8084/tryCreateUser?email=%s&username=%s&password=%s", email, username, password))) .build(); ResponseEntity<Resource<Account>> response = restTemplate.exchange(request, new TypeReferences.ResourceType<Account>() {}); return Optional.ofNullable(response.getBody().getContent()); }
Example #27
Source File: RestTmplApplicationTests.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void index() { RequestEntity<Void> request = RequestEntity .get(URI.create(String.format("%s/messages", serviceUri))) .build(); ResponseEntity<Resources<Message>> response = restTemplate.exchange(request, new TypeReferences.ResourcesType<Message>() {}); assertTrue(response.getBody().getContent().size() > 0); }
Example #28
Source File: RestTmplApplicationTests.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void index() { RequestEntity<Void> request = RequestEntity .get(URI.create("http://localhost:8080/messages/")) .build(); ResponseEntity<Resources<Message>> response = restTemplate.exchange(request, new TypeReferences.ResourcesType<Message>() {}); assertTrue(response.getBody().getContent().size() > 0); }