Search in sources :

Example 6 with ActionSchema

use of com.linkedin.restli.restspec.ActionSchema in project rest.li by linkedin.

the class ResourceSchemaToResourceSpecTranslator method toDynamicRecordMetadata.

private ActionCollectionMetadata toDynamicRecordMetadata(ActionSchemaArray actions, ActionSchemaArray entityActions) {
    Map<String, DynamicRecordMetadata> response = new HashMap<String, DynamicRecordMetadata>();
    Map<String, DynamicRecordMetadata> request = new HashMap<String, DynamicRecordMetadata>();
    ActionSchemaArray[] actionGroups = new ActionSchemaArray[] { actions, entityActions };
    for (ActionSchemaArray actionGroup : actionGroups) {
        if (actionGroup != null) {
            for (ActionSchema action : actionGroup) {
                ActionMetadata metadata = toActionMetadata(action);
                request.put(metadata._name, metadata._request);
                response.put(metadata._name, metadata._response);
            }
        }
    }
    return new ActionCollectionMetadata(request, response);
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) HashMap(java.util.HashMap) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 7 with ActionSchema

use of com.linkedin.restli.restspec.ActionSchema in project rest.li by linkedin.

the class TestResourceSchemaToResourceSpecTranslator method compareActions.

private void compareActions(ResourceSpec actual, ResourceSpec expected, ActionSchemaArray actions) {
    for (ActionSchema action : actions) {
        ParameterSchemaArray parameters = action.getParameters();
        DynamicRecordMetadata actualRequest = actual.getRequestMetadata(action.getName());
        DynamicRecordMetadata expectedRequest = expected.getRequestMetadata(action.getName());
        if (expectedRequest != null) {
            Assert.assertNotNull(actualRequest);
            Assert.assertEquals(actualRequest.getRecordDataSchema(), expectedRequest.getRecordDataSchema());
            if (parameters != null) {
                for (ParameterSchema parameter : parameters) {
                    compareFieldDef(actualRequest.getFieldDef(parameter.getName()), expectedRequest.getFieldDef(parameter.getName()));
                }
            }
        } else {
            Assert.assertNull(actualRequest);
        }
        compareParameters(actual.getActionResponseMetadata(action.getName()), expected.getActionResponseMetadata(action.getName()));
    }
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 8 with ActionSchema

use of com.linkedin.restli.restspec.ActionSchema in project rest.li by linkedin.

the class ResourceModelEncoder method createActions.

private ActionSchemaArray createActions(final ResourceModel resourceModel, final ResourceLevel resourceLevel) {
    ActionSchemaArray actionsArray = new ActionSchemaArray();
    List<ResourceMethodDescriptor> resourceMethodDescriptors = resourceModel.getResourceMethodDescriptors();
    Collections.sort(resourceMethodDescriptors, new Comparator<ResourceMethodDescriptor>() {

        @Override
        public int compare(final ResourceMethodDescriptor o1, final ResourceMethodDescriptor o2) {
            if (o1.getType().equals(ResourceMethod.ACTION)) {
                if (o2.getType().equals(ResourceMethod.ACTION)) {
                    return o1.getActionName().compareTo(o2.getActionName());
                } else {
                    return 1;
                }
            } else if (o2.getType().equals(ResourceMethod.ACTION)) {
                return -1;
            } else {
                return 0;
            }
        }
    });
    for (ResourceMethodDescriptor resourceMethodDescriptor : resourceMethodDescriptors) {
        if (ResourceMethod.ACTION.equals(resourceMethodDescriptor.getType())) {
            //do not apply entity-level actions at collection level or vice-versa
            if (resourceMethodDescriptor.getActionResourceLevel() != resourceLevel) {
                continue;
            }
            ActionSchema action = new ActionSchema();
            action.setName(resourceMethodDescriptor.getActionName());
            //We have to construct the method doc for the action which includes the action return type
            final String methodDoc = _docsProvider.getMethodDoc(resourceMethodDescriptor.getMethod());
            if (methodDoc != null) {
                final StringBuilder methodDocBuilder = new StringBuilder(methodDoc.trim());
                if (methodDocBuilder.length() > 0) {
                    final String returnDoc = sanitizeDoc(_docsProvider.getReturnDoc(resourceMethodDescriptor.getMethod()));
                    if (returnDoc != null && !returnDoc.isEmpty()) {
                        methodDocBuilder.append("\n");
                        methodDocBuilder.append("Service Returns: ");
                        //Capitalize the first character
                        methodDocBuilder.append(returnDoc.substring(0, 1).toUpperCase());
                        methodDocBuilder.append(returnDoc.substring(1));
                    }
                }
                action.setDoc(methodDocBuilder.toString());
            }
            ParameterSchemaArray parameters = createParameters(resourceMethodDescriptor);
            if (parameters.size() > 0) {
                action.setParameters(parameters);
            }
            Class<?> returnType = resourceMethodDescriptor.getActionReturnType();
            if (returnType != Void.TYPE) {
                String returnTypeString = buildDataSchemaType(returnType, resourceMethodDescriptor.getActionReturnRecordDataSchema().getField(ActionResponse.VALUE_NAME).getType());
                action.setReturns(returnTypeString);
            }
            final DataMap customAnnotation = resourceMethodDescriptor.getCustomAnnotationData();
            String deprecatedDoc = _docsProvider.getMethodDeprecatedTag(resourceMethodDescriptor.getMethod());
            if (deprecatedDoc != null) {
                customAnnotation.put(DEPRECATED_ANNOTATION_NAME, deprecateDocToAnnotationMap(deprecatedDoc));
            }
            if (!customAnnotation.isEmpty()) {
                action.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
            }
            actionsArray.add(action);
        }
    }
    return actionsArray;
}
Also used : ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 9 with ActionSchema

use of com.linkedin.restli.restspec.ActionSchema in project rest.li by linkedin.

the class SnapshotGenerator method findModelsAssocation.

private void findModelsAssocation(ResourceSchema resourceSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    AssociationSchema association = resourceSchema.getAssociation();
    if (association != null) {
        for (AssocKeySchema assocKeySchema : association.getAssocKeys()) {
            String type = assocKeySchema.getType();
            recordType(type, foundTypes, typeOrder);
        }
        if (association.hasFinders()) {
            for (FinderSchema restMethodSchema : association.getFinders()) {
                findModelsFinder(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (association.hasMethods()) {
            for (RestMethodSchema restMethodSchema : association.getMethods()) {
                findModelsMethod(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (association.hasActions()) {
            for (ActionSchema actionSchema : association.getActions()) {
                findModelsAction(actionSchema, foundTypes, typeOrder);
            }
        }
        if (association.hasEntity()) {
            EntitySchema entitySchema = association.getEntity();
            findModelsEntity(entitySchema, foundTypes, typeOrder);
        }
    }
}
Also used : AssociationSchema(com.linkedin.restli.restspec.AssociationSchema) RestMethodSchema(com.linkedin.restli.restspec.RestMethodSchema) FinderSchema(com.linkedin.restli.restspec.FinderSchema) EntitySchema(com.linkedin.restli.restspec.EntitySchema) ActionSchema(com.linkedin.restli.restspec.ActionSchema) AssocKeySchema(com.linkedin.restli.restspec.AssocKeySchema)

Example 10 with ActionSchema

use of com.linkedin.restli.restspec.ActionSchema in project rest.li by linkedin.

the class SnapshotGenerator method findModelsSimple.

private void findModelsSimple(ResourceSchema resourceSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    SimpleSchema simple = resourceSchema.getSimple();
    if (simple != null) {
        if (simple.hasMethods()) {
            for (RestMethodSchema restMethodSchema : simple.getMethods()) {
                findModelsMethod(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (simple.hasActions()) {
            for (ActionSchema actionSchema : simple.getActions()) {
                findModelsAction(actionSchema, foundTypes, typeOrder);
            }
        }
        if (simple.hasEntity()) {
            EntitySchema entity = simple.getEntity();
            findModelsEntity(entity, foundTypes, typeOrder);
        }
    }
}
Also used : SimpleSchema(com.linkedin.restli.restspec.SimpleSchema) RestMethodSchema(com.linkedin.restli.restspec.RestMethodSchema) EntitySchema(com.linkedin.restli.restspec.EntitySchema) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Aggregations

ActionSchema (com.linkedin.restli.restspec.ActionSchema)14 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)5 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)5 AssociationSchema (com.linkedin.restli.restspec.AssociationSchema)4 CollectionSchema (com.linkedin.restli.restspec.CollectionSchema)4 EntitySchema (com.linkedin.restli.restspec.EntitySchema)4 FinderSchema (com.linkedin.restli.restspec.FinderSchema)4 RestMethodSchema (com.linkedin.restli.restspec.RestMethodSchema)4 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)3 ParameterSchemaArray (com.linkedin.restli.restspec.ParameterSchemaArray)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DataMap (com.linkedin.data.DataMap)2 RecordTemplate (com.linkedin.data.template.RecordTemplate)2 AssocKeySchema (com.linkedin.restli.restspec.AssocKeySchema)2 IdentifierSchema (com.linkedin.restli.restspec.IdentifierSchema)2 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)2 ResourceLevel (com.linkedin.restli.server.ResourceLevel)2 JClass (com.sun.codemodel.JClass)2 JInvocation (com.sun.codemodel.JInvocation)2