@Override public boolean isCollection() { return ids == null || ids.getIds().size() > 1; }
private static PathIds createPathIds(String idsString) { List<String> pathIds = Arrays.asList(idsString.split(PathIds.ID_SEPARATOR_PATTERN)); return new PathIds(pathIds); }
/** * Creates a path using the provided JsonPath structure. * * @param jsonPath JsonPath structure to be parsed * @return String representing structure provided in the input */ public static String buildPath(JsonPath jsonPath) { List<String> urlParts = new LinkedList<>(); JsonPath currentJsonPath = jsonPath; String pathPart; do { if (currentJsonPath instanceof RelationshipsPath) { pathPart = RELATIONSHIP_MARK + SEPARATOR + currentJsonPath.getElementName(); } else if (currentJsonPath instanceof FieldPath) { pathPart = currentJsonPath.getElementName(); } else { pathPart = currentJsonPath.getElementName(); if (currentJsonPath.getIds() != null) { pathPart += SEPARATOR + mergeIds(currentJsonPath.getIds()); } } urlParts.add(pathPart); currentJsonPath = currentJsonPath.getParentResource(); } while (currentJsonPath != null); Collections.reverse(urlParts); return SEPARATOR + StringUtils.join(SEPARATOR, urlParts) + SEPARATOR; }
private JsonPath getNonResourcePath(JsonPath previousJsonPath, String elementName, boolean relationshipMark) { String previousElementName = previousJsonPath.getElementName(); RegistryEntry previousEntry = resourceRegistry.getEntry(previousElementName); ResourceInformation resourceInformation = previousEntry.getResourceInformation(); List<ResourceField> resourceFields = resourceInformation.getRelationshipFields(); for (ResourceField field : resourceFields) { if (field.getJsonName().equals(elementName)) { if (relationshipMark) { return new RelationshipsPath(elementName); } else { return new FieldPath(elementName); } } } //TODO: Throw different exception? element name can be null.. throw new ResourceFieldNotFoundException(elementName); }
/** * Iterate over all registered controllers to get the first suitable one. * @param jsonPath built JsonPath object mad from request path * @param requestType type of a HTTP request * @return suitable controller */ public BaseController getController(JsonPath jsonPath, String requestType) { for (BaseController controller : controllers) { if (controller.isAcceptable(jsonPath, requestType)) { return controller; } } throw new MethodNotFoundException(PathBuilder.buildPath(jsonPath), requestType); } }
/** * {@inheritDoc} * * Checks if requested resource method is acceptable - is a DELETE request for a resource. */ @Override public boolean isAcceptable(JsonPath jsonPath, String requestType) { return !jsonPath.isCollection() && jsonPath instanceof ResourcePath && HttpMethod.DELETE.name().equals(requestType); }
/** * Parses path provided by the application. The path provided cannot contain neither hostname nor protocol. It * can start or end with slash e.g. <i>/tasks/1/</i> or <i>tasks/1</i>. * * @param path Path to be parsed * @return doubly-linked list which represents path given at the input * @deprecated use build */ public JsonPath buildPath(String path) { JsonPath jsonPath = build(path); if(jsonPath != null){ return jsonPath; }else{ throw new RepositoryNotFoundException(path); } }
protected AbstractQueryParamsParserContext(ResourceRegistry resourceRegistry, JsonPath path) { resourceInformation = resourceRegistry.getEntry(path.getResourceName()).getResourceInformation(); }
@Override public boolean isAcceptable(JsonPath jsonPath, String requestType) { return !jsonPath.isCollection() && jsonPath instanceof ResourcePath && HttpMethod.PATCH.name().equals(requestType); }
@Override public boolean isCollection() { return parentResource.ids == null || parentResource.ids.getIds().size() > 1; }
/** * Check if it is a GET request for a collection of resources. */ @Override public boolean isAcceptable(JsonPath jsonPath, String requestType) { return jsonPath.isCollection() && jsonPath instanceof ResourcePath && HttpMethod.GET.name().equals(requestType); }
private static String mergeIds(PathIds ids) { return StringUtils.join(PathIds.ID_SEPARATOR, ids.getIds()); } }
/** * {@inheritDoc} * <p> * Check if it is a POST request for a resource. */ @Override public boolean isAcceptable(JsonPath jsonPath, String requestType) { return jsonPath.isCollection() && jsonPath instanceof ResourcePath && HttpMethod.POST.name() .equals(requestType); }
private Serializable getResourceId(PathIds resourceIds, RegistryEntry registryEntry) { String resourceId = resourceIds.getIds().get(0); @SuppressWarnings("unchecked") Class<? extends Serializable> idClass = (Class<? extends Serializable>) registryEntry .getResourceInformation() .getIdField() .getType(); return typeParser.parse(resourceId, idClass); } }
/** * {@inheritDoc} * * Checks if requested resource method is acceptable - is a GET request for * a resource. */ @Override public boolean isAcceptable(JsonPath jsonPath, String requestType) { return !jsonPath.isCollection() && jsonPath instanceof ResourcePath && HttpMethod.GET.name().equals(requestType); }
private Serializable getResourceId(PathIds resourceIds, RegistryEntry registryEntry) { String resourceId = resourceIds.getIds().get(0); @SuppressWarnings("unchecked") Class<? extends Serializable> idClass = (Class<? extends Serializable>) registryEntry .getResourceInformation() .getIdField() .getType(); return typeParser.parse(resourceId, idClass); } }
@Override public boolean isAcceptable(JsonPath jsonPath, String requestType) { return !jsonPath.isCollection() && jsonPath instanceof RelationshipsPath && HttpMethod.GET.name().equals(requestType); }
@Override public boolean isAcceptable(JsonPath jsonPath, String requestType) { return !jsonPath.isCollection() && FieldPath.class.equals(jsonPath.getClass()) && HttpMethod.GET.name().equals(requestType); }
@Override public boolean isAcceptable(JsonPath jsonPath, String requestType) { return !jsonPath.isCollection() && FieldPath.class.equals(jsonPath.getClass()) && HttpMethod.POST.name() .equals(requestType); }
@Override public final boolean isAcceptable(JsonPath jsonPath, String requestType) { return !jsonPath.isCollection() && RelationshipsPath.class.equals(jsonPath.getClass()) && method().name().equals(requestType); }