use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.
the class ResourceModelEncoder method buildResourceSchema.
/**
* @param resourceModel {@link ResourceModel} to build the schema for
* @return {@link ResourceSchema} for the provided resource model
*/
public ResourceSchema buildResourceSchema(final ResourceModel resourceModel) {
ResourceSchema rootNode = new ResourceSchema();
switch(resourceModel.getResourceType()) {
case ACTIONS:
appendActionsModel(rootNode, resourceModel);
break;
case SIMPLE:
appendSimple(rootNode, resourceModel);
break;
default:
appendCollection(rootNode, resourceModel);
break;
}
final DataMap customAnnotation = resourceModel.getCustomAnnotationData();
if (!customAnnotation.isEmpty()) {
rootNode.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
}
return rootNode;
}
use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.
the class ResourceModelEncoder method createParameters.
@SuppressWarnings("deprecation")
private ParameterSchemaArray createParameters(final ResourceMethodDescriptor resourceMethodDescriptor) {
ParameterSchemaArray parameterSchemaArray = new ParameterSchemaArray();
for (Parameter<?> param : resourceMethodDescriptor.getParameters()) {
// only custom parameters need to be specified in the IDL
if (!param.isCustom()) {
continue;
}
// assocKeys are listed outside the parameters list
if (param.getParamType() == Parameter.ParamType.KEY || param.getParamType() == Parameter.ParamType.ASSOC_KEY_PARAM) {
continue;
}
ParameterSchema paramSchema = new ParameterSchema();
paramSchema.setName(param.getName());
paramSchema.setType(buildDataSchemaType(param.getType(), param.getDataSchema()));
final Object defaultValueData = param.getDefaultValueData();
if (defaultValueData == null && param.isOptional()) {
paramSchema.setOptional(true);
} else if (defaultValueData != null) {
paramSchema.setDefault(defaultValueData.toString());
}
String paramDoc = _docsProvider.getParamDoc(resourceMethodDescriptor.getMethod(), param.getName());
if (paramDoc != null) {
paramSchema.setDoc(paramDoc);
}
final DataMap customAnnotation = param.getCustomAnnotationData();
if (param.getAnnotations().contains(Deprecated.class)) {
customAnnotation.put(DEPRECATED_ANNOTATION_NAME, new DataMap());
}
if (!customAnnotation.isEmpty()) {
paramSchema.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
}
parameterSchemaArray.add(paramSchema);
}
return parameterSchemaArray;
}
use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.
the class ResourceModelEncoder method createFinders.
private FinderSchemaArray createFinders(final ResourceModel resourceModel) {
FinderSchemaArray findersArray = new FinderSchemaArray();
List<ResourceMethodDescriptor> resourceMethodDescriptors = resourceModel.getResourceMethodDescriptors();
Collections.sort(resourceMethodDescriptors, RESOURCE_METHOD_COMPARATOR);
for (ResourceMethodDescriptor resourceMethodDescriptor : resourceMethodDescriptors) {
if (ResourceMethod.FINDER.equals(resourceMethodDescriptor.getType())) {
FinderSchema finder = new FinderSchema();
finder.setName(resourceMethodDescriptor.getFinderName());
String doc = _docsProvider.getMethodDoc(resourceMethodDescriptor.getMethod());
if (doc != null) {
finder.setDoc(doc);
}
ParameterSchemaArray parameters = createParameters(resourceMethodDescriptor);
if (parameters.size() > 0) {
finder.setParameters(parameters);
}
StringArray assocKeys = createAssocKeyParameters(resourceMethodDescriptor);
if (assocKeys.size() > 0) {
finder.setAssocKeys(assocKeys);
}
if (resourceMethodDescriptor.getFinderMetadataType() != null) {
Class<?> metadataType = resourceMethodDescriptor.getFinderMetadataType();
MetadataSchema metadataSchema = new MetadataSchema();
metadataSchema.setType(buildDataSchemaType(metadataType));
finder.setMetadata(metadataSchema);
}
final DataMap customAnnotation = resourceMethodDescriptor.getCustomAnnotationData();
String deprecatedDoc = _docsProvider.getMethodDeprecatedTag(resourceMethodDescriptor.getMethod());
if (deprecatedDoc != null) {
customAnnotation.put(DEPRECATED_ANNOTATION_NAME, deprecateDocToAnnotationMap(deprecatedDoc));
}
if (!customAnnotation.isEmpty()) {
finder.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
}
if (resourceMethodDescriptor.isPagingSupported()) {
finder.setPagingSupported(true);
}
findersArray.add(finder);
}
}
return findersArray;
}
use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.
the class ResourceModelEncoder method buildEntitySchema.
private EntitySchema buildEntitySchema(ResourceModel resourceModel) {
EntitySchema entityNode = new EntitySchema();
entityNode.setPath(buildPathForEntity(resourceModel));
if (resourceModel.getResourceLevel() == ResourceLevel.COLLECTION) {
ActionSchemaArray actions = createActions(resourceModel, ResourceLevel.ENTITY);
if (actions.size() > 0) {
entityNode.setActions(actions);
}
}
// subresources
ResourceSchemaArray subresources = new ResourceSchemaArray();
for (ResourceModel subResourceModel : resourceModel.getSubResources()) {
ResourceSchema subresource = new ResourceSchema();
switch(subResourceModel.getResourceType()) {
case COLLECTION:
case ASSOCIATION:
appendCollection(subresource, subResourceModel);
break;
case SIMPLE:
appendSimple(subresource, subResourceModel);
break;
default:
break;
}
final DataMap customAnnotation = subResourceModel.getCustomAnnotationData();
if (!customAnnotation.isEmpty()) {
subresource.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
}
subresources.add(subresource);
}
if (subresources.size() > 0) {
Collections.sort(subresources, new Comparator<ResourceSchema>() {
@Override
public int compare(ResourceSchema resourceSchema, ResourceSchema resourceSchema2) {
return resourceSchema.getName().compareTo(resourceSchema2.getName());
}
});
entityNode.setSubresources(subresources);
}
return entityNode;
}
use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.
the class ResourceModelEncoder method createRestMethods.
private RestMethodSchemaArray createRestMethods(final ResourceModel resourceModel) {
RestMethodSchemaArray restMethods = new RestMethodSchemaArray();
ResourceMethod[] crudMethods = { ResourceMethod.CREATE, ResourceMethod.GET, ResourceMethod.UPDATE, ResourceMethod.PARTIAL_UPDATE, ResourceMethod.DELETE, ResourceMethod.BATCH_CREATE, ResourceMethod.BATCH_GET, ResourceMethod.BATCH_UPDATE, ResourceMethod.BATCH_PARTIAL_UPDATE, ResourceMethod.BATCH_DELETE, ResourceMethod.GET_ALL };
for (ResourceMethod method : crudMethods) {
ResourceMethodDescriptor descriptor = resourceModel.findMethod(method);
if (descriptor == null) {
continue;
}
RestMethodSchema restMethod = new RestMethodSchema();
restMethod.setMethod(method.toString());
String doc = _docsProvider.getMethodDoc(descriptor.getMethod());
if (doc != null) {
restMethod.setDoc(doc);
}
ParameterSchemaArray parameters = createParameters(descriptor);
if (parameters.size() > 0) {
restMethod.setParameters(parameters);
}
final DataMap customAnnotation = descriptor.getCustomAnnotationData();
String deprecatedDoc = _docsProvider.getMethodDeprecatedTag(descriptor.getMethod());
if (deprecatedDoc != null) {
customAnnotation.put(DEPRECATED_ANNOTATION_NAME, deprecateDocToAnnotationMap(deprecatedDoc));
}
if (!customAnnotation.isEmpty()) {
restMethod.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
}
if (method == ResourceMethod.GET_ALL) {
if (descriptor.getCollectionCustomMetadataType() != null) {
restMethod.setMetadata(createMetadataSchema(descriptor));
}
if (descriptor.isPagingSupported()) {
restMethod.setPagingSupported(true);
}
}
MaxBatchSizeSchema maxBatchSize = descriptor.getMaxBatchSize();
if (maxBatchSize != null) {
restMethod.setMaxBatchSize(maxBatchSize);
}
appendServiceErrors(restMethod, descriptor.getServiceErrors());
appendSuccessStatuses(restMethod, descriptor.getSuccessStatuses());
restMethods.add(restMethod);
}
return restMethods;
}
Aggregations