List of usage examples for org.springframework.data.rest.webmvc RootResourceInformation getDomainType
public Class<?> getDomainType()
From source file:org.moserp.common.json_schema.JsonSchemaController.java
@RequestMapping(value = BASE_PATH + REPOSITORY, method = GET) public HttpEntity<BusinessEntity> schema(RootResourceInformation resourceInformation) { BusinessEntity schema = jsonSchemaBuilder.buildFor(resourceInformation.getDomainType()); return new ResponseEntity<>(schema, HttpStatus.OK); }
From source file:org.moserp.common.structure.ApplicationStructureController.java
@RequestMapping(value = BASE_PATH + REPOSITORY, method = GET) public HttpEntity<BusinessEntity> schema(RootResourceInformation resourceInformation) { BusinessEntity schema = applicationStructureBuilder.buildFor(resourceInformation.getDomainType()); return new ResponseEntity<>(schema, HttpStatus.OK); }
From source file:org.lightadmin.core.web.util.RepositoryNewEntityController.java
@RequestMapping(value = BASE_MAPPING + "/new", method = GET) public ResponseEntity<Resource<?>> getItemResource(RootResourceInformation resourceInformation, PersistentEntityResourceAssembler assembler) throws HttpRequestMethodNotSupportedException { Constructor<?> constructor = getConstructorIfAvailable(resourceInformation.getDomainType()); if (constructor == null) { return new ResponseEntity<Resource<?>>(NOT_IMPLEMENTED); }/*from w w w. ja v a 2 s.c om*/ Object domainObj = BeanUtils.instantiateClass(constructor); return new ResponseEntity<Resource<?>>(assembler.toResource(domainObj), OK); }
From source file:org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.java
private Object read(IncomingRequest request, HttpMessageConverter<Object> converter, RootResourceInformation information) { try {/*w w w . j a va 2s. co m*/ return converter.read(information.getDomainType(), request.getServerHttpRequest()); } catch (IOException o_O) { throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, information.getDomainType()), o_O); } }
From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java
public Alps convert(RootResourceInformation resourceInformation) { Class<?> type = resourceInformation.getDomainType(); List<Descriptor> descriptors = new ArrayList<Descriptor>(); Descriptor representationDescriptor = buildRepresentationDescriptor(type); descriptors.add(representationDescriptor); SupportedHttpMethods supportedHttpMethods = resourceInformation.getSupportedMethods(); for (HttpMethod method : supportedHttpMethods.getMethodsFor(ResourceType.COLLECTION)) { if (!UNDOCUMENTED_METHODS.contains(method)) { descriptors.add(buildCollectionResourceDescriptor(type, resourceInformation, representationDescriptor, method)); }/*from w w w .j a v a 2 s .com*/ } for (HttpMethod method : supportedHttpMethods.getMethodsFor(ResourceType.ITEM)) { if (!UNDOCUMENTED_METHODS.contains(method)) { descriptors.add(buildItemResourceDescriptor(resourceInformation, representationDescriptor, method)); } } descriptors.addAll(buildSearchResourceDescriptors(resourceInformation.getPersistentEntity())); return Alps.alps().descriptors(descriptors).build(); }
From source file:org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { RootResourceInformation resourceInformation = resourceInformationResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); HttpServletRequest nativeRequest = webRequest.getNativeRequest(HttpServletRequest.class); ServletServerHttpRequest request = new ServletServerHttpRequest(nativeRequest); IncomingRequest incoming = new IncomingRequest(request); Class<?> domainType = resourceInformation.getDomainType(); MediaType contentType = request.getHeaders().getContentType(); for (HttpMessageConverter converter : messageConverters) { if (!converter.canRead(PersistentEntityResource.class, contentType)) { continue; }/* w ww .j a va2 s . co m*/ Serializable id = idResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); Object objectToUpdate = getObjectToUpdate(id, resourceInformation); boolean forUpdate = false; Object entityIdentifier = null; PersistentEntity<?, ?> entity = resourceInformation.getPersistentEntity(); if (objectToUpdate != null) { forUpdate = true; entityIdentifier = entity.getIdentifierAccessor(objectToUpdate).getIdentifier(); } Object obj = read(resourceInformation, incoming, converter, objectToUpdate); if (obj == null) { throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, domainType)); } if (entityIdentifier != null) { entity.getPropertyAccessor(obj).setProperty(entity.getIdProperty(), entityIdentifier); } Builder build = PersistentEntityResource.build(obj, entity); return forUpdate ? build.build() : build.forCreation(); } throw new HttpMessageNotReadableException(String.format(NO_CONVERTER_FOUND, domainType, contentType)); }