List of usage examples for org.springframework.data.rest.webmvc ResourceNotFoundException ResourceNotFoundException
public ResourceNotFoundException(String message)
From source file:com.example.endpoint.UserController.java
@GetMapping UserForInternalUseEntity getUserForInternalUse(@RequestParam("username") final String username) { return userRepository.findByName(username) .map(u -> new UserForInternalUseEntity(u.getId(), u.getName(), u.getPassword(), u.getAuthoritiesAsString())) .orElseThrow(() -> new ResourceNotFoundException(username + " does not exist.")); }
From source file:edu.zipcloud.cloudstreetmarket.core.services.IndexServiceImpl.java
@Override public Index getIndex(String id) { Index index = indexRepository.findOne(id); if (index == null) { throw new ResourceNotFoundException(bundle.getFormatted(I18N_INDICES_INDEX_NOT_FOUND, id)); }/*from w w w. j a v a2s . co m*/ return index; }
From source file:org.lightadmin.core.web.RepositoryFilePropertyController.java
private FilePropertyValue evaluateFilePropertyValue(Object instance, PersistentProperty persistentProperty) { FileResourceStorage fileResourceStorage = fileResourceStorage(); try {/* w ww . j a va 2 s .c o m*/ if (!fileResourceStorage.fileExists(instance, persistentProperty)) { return new FilePropertyValue(false); } Link fileLink = entityLinks().linkForFilePropertyLink(instance, persistentProperty); byte[] fileData = fileResourceStorage.load(instance, persistentProperty); return new FilePropertyValue(fileLink, fileData); } catch (Exception e) { throw new ResourceNotFoundException(e.getMessage()); } }
From source file:org.dspace.app.rest.RelationshipRestController.java
/** * This method will retrieve all the Relationships that have a RelationshipType which has a left or right label * equal to the one passed along in the pathvariable. * This is further filtered by an optional dso parameter to filter on only the relationships for the given dso * if this is applicable/*from ww w . j a v a 2s. com*/ * * @param response The response object * @param request The request object * @param label The label on which the Relationship's RelationshipType will be matched * @param dsoId The ID of the dso on which we'll search for relationships if applicable * @param pageable The page object * @return A Resource containing all the relationships that meet the criteria * @throws Exception If something goes wrong */ @RequestMapping(method = RequestMethod.GET, value = REGEX_REQUESTMAPPING_LABEL) public RelationshipResourceWrapper retrieveByLabel(HttpServletResponse response, HttpServletRequest request, @PathVariable String label, @RequestParam(name = "dso", required = false) String dsoId, Pageable pageable) throws Exception { Context context = ContextUtil.obtainContext(request); List<RelationshipType> relationshipTypeList = relationshipTypeService.findByLeftOrRightLabel(context, label); List<Relationship> relationships = new LinkedList<>(); if (StringUtils.isNotBlank(dsoId)) { UUID uuid = UUIDUtils.fromString(dsoId); Item item = itemService.find(context, uuid); if (item == null) { throw new ResourceNotFoundException("The request DSO with id: " + dsoId + " was not found"); } for (RelationshipType relationshipType : relationshipTypeList) { relationships .addAll(relationshipService.findByItemAndRelationshipType(context, item, relationshipType)); } } else { for (RelationshipType relationshipType : relationshipTypeList) { relationships.addAll(relationshipService.findByRelationshipType(context, relationshipType)); } } List<RelationshipRest> relationshipRests = new LinkedList<>(); for (Relationship relationship : relationships) { relationshipRests.add(relationshipConverter.fromModel(relationship)); } RelationshipRestWrapper relationshipRestWrapper = new RelationshipRestWrapper(); relationshipRestWrapper.setLabel(label); relationshipRestWrapper.setDsoId(dsoId); relationshipRestWrapper.setRelationshipRestList(relationshipRests); RelationshipResourceWrapper relationshipResourceWrapper = new RelationshipResourceWrapper( relationshipRestWrapper, utils, relationshipRests.size(), pageable); halLinkService.addLinks(relationshipResourceWrapper, pageable); return relationshipResourceWrapper; }
From source file:org.dspace.app.rest.repository.ClaimedTaskRestRepository.java
@Override @PreAuthorize("hasPermission(#id, 'CLAIMEDTASK', 'WRITE')") protected ClaimedTaskRest action(Context context, HttpServletRequest request, Integer id) throws SQLException, IOException { ClaimedTask task = null;// w w w .ja va 2 s.co m task = claimedTaskService.find(context, id); if (task == null) { throw new ResourceNotFoundException("ClaimedTask ID " + id + " not found"); } XmlWorkflowServiceFactory factory = (XmlWorkflowServiceFactory) XmlWorkflowServiceFactory.getInstance(); Workflow workflow; try { workflow = factory.getWorkflowFactory().getWorkflow(task.getWorkflowItem().getCollection()); Step step = workflow.getStep(task.getStepID()); WorkflowActionConfig currentActionConfig = step.getActionConfig(task.getActionID()); workflowService.doState(context, context.getCurrentUser(), request, task.getWorkflowItem().getID(), workflow, currentActionConfig); if (!Action.getErrorFields(request).isEmpty()) { throw new UnprocessableEntityException( "Missing required fields: " + StringUtils.join(Action.getErrorFields(request), ",")); } } catch (AuthorizeException e) { throw new RESTAuthorizationException(e); } catch (WorkflowException e) { throw new UnprocessableEntityException("Invalid workflow action: " + e.getMessage(), e); } catch (WorkflowConfigurationException | MessagingException e) { throw new RuntimeException(e.getMessage(), e); } return null; }
From source file:org.dspace.app.rest.repository.ClaimedTaskRestRepository.java
@Override /**//w w w . ja v a 2 s. c o m * This method delete only the claimed task. The workflow engine will return it to the pool if there are not * enough other claimed tasks for the same workflowitem. * */ @PreAuthorize("hasPermission(#id, 'CLAIMEDTASK', 'DELETE')") protected void delete(Context context, Integer id) { ClaimedTask task = null; try { task = claimedTaskService.find(context, id); if (task == null) { throw new ResourceNotFoundException("ClaimedTask ID " + id + " not found"); } XmlWorkflowItem workflowItem = task.getWorkflowItem(); workflowService.deleteClaimedTask(context, workflowItem, task); workflowRequirementsService.removeClaimedUser(context, workflowItem, task.getOwner(), task.getStepID()); } catch (AuthorizeException e) { throw new RESTAuthorizationException(e); } catch (SQLException | IOException | WorkflowConfigurationException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:org.dspace.app.rest.repository.CollectionRestRepository.java
@SearchRestMethod(name = "findAuthorizedByCommunity") public Page<CollectionRest> findAuthorizedByCommunity( @Parameter(value = "uuid", required = true) UUID communityUuid, Pageable pageable) { Context context = obtainContext(); List<Collection> it = null; List<Collection> collections = new ArrayList<Collection>(); try {// w w w . j ava 2s . c o m Community com = communityService.find(context, communityUuid); if (com == null) { throw new ResourceNotFoundException(CommunityRest.CATEGORY + "." + CommunityRest.NAME + " with id: " + communityUuid + " not found"); } it = cs.findAuthorized(context, com, Constants.ADD); for (Collection c : it) { collections.add(c); } } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); } Page<CollectionRest> page = utils.getPage(collections, pageable).map(dsoConverter); return page; }
From source file:org.dspace.app.rest.repository.CollectionRestRepository.java
@Override @PreAuthorize("hasPermission(#id, 'COLLECTION', 'WRITE')") protected CollectionRest put(Context context, HttpServletRequest request, String apiCategory, String model, UUID id, JsonNode jsonNode) throws RepositoryMethodNotImplementedException, SQLException, AuthorizeException { CollectionRest collectionRest;//from ww w. j ava2 s . c o m try { collectionRest = new ObjectMapper().readValue(jsonNode.toString(), CollectionRest.class); } catch (IOException e) { throw new UnprocessableEntityException("Error parsing collection json: " + e.getMessage()); } Collection collection = cs.find(context, id); if (collection == null) { throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found"); } CollectionRest originalCollectionRest = converter.fromModel(collection); if (collectionRestEqualityUtils.isCollectionRestEqualWithoutMetadata(originalCollectionRest, collectionRest)) { metadataConverter.setMetadata(context, collection, collectionRest.getMetadata()); } else { throw new IllegalArgumentException("The UUID in the Json and the UUID in the url do not match: " + id + ", " + collectionRest.getId()); } return converter.fromModel(collection); }
From source file:org.dspace.app.rest.repository.CollectionRestRepository.java
@Override @PreAuthorize("hasPermission(#id, 'COLLECTION', 'DELETE')") protected void delete(Context context, UUID id) throws AuthorizeException { Collection collection = null; try {//w ww. ja va2 s . c o m collection = cs.find(context, id); if (collection == null) { throw new ResourceNotFoundException( CollectionRest.CATEGORY + "." + CollectionRest.NAME + " with id: " + id + " not found"); } } catch (SQLException e) { throw new RuntimeException("Unable to find Collection with id = " + id, e); } try { cs.delete(context, collection); } catch (SQLException e) { throw new RuntimeException("Unable to delete Collection with id = " + id, e); } catch (IOException e) { throw new RuntimeException("Unable to delete collection because the logo couldn't be deleted", e); } }