Search in sources :

Example 1 with AssocKeySchemaArray

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

the class ResourceSchemaToResourceSpecTranslator method associationToResourceSpec.

private ResourceSpec associationToResourceSpec(ResourceSchema resourceSchema, AssociationSchema association) {
    ActionSchemaArray actions = null, entityActions = null;
    StringArray supports = association.getSupports();
    if (association.hasActions()) {
        actions = association.getActions();
    }
    if (association.getEntity().hasActions()) {
        entityActions = association.getEntity().getActions();
    }
    String schema = resourceSchema.getSchema();
    AssocKeySchemaArray assocKeys = association.getAssocKeys();
    Map<String, CompoundKey.TypeInfo> keyParts = new HashMap<String, CompoundKey.TypeInfo>();
    for (AssocKeySchema assocKey : assocKeys) {
        TypeSpec<?> type = toTypeSpec(RestSpecCodec.textToSchema(assocKey.getType(), _schemaResolver));
        keyParts.put(assocKey.getName(), new CompoundKey.TypeInfo(type, type));
    }
    return buildResourceSpec(supports, new TypeSpec<CompoundKey>(CompoundKey.class, null), null, keyParts, schema, actions, entityActions);
}
Also used : AssocKeySchemaArray(com.linkedin.restli.restspec.AssocKeySchemaArray) StringArray(com.linkedin.data.template.StringArray) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) AssocKeySchema(com.linkedin.restli.restspec.AssocKeySchema)

Example 2 with AssocKeySchemaArray

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

the class ResourceModelEncoder method appendKeys.

private void appendKeys(final AssociationSchema associationSchema, final ResourceModel collectionModel) {
    AssocKeySchemaArray assocKeySchemaArray = new AssocKeySchemaArray();
    List<Key> sortedKeys = new ArrayList<Key>(collectionModel.getKeys());
    Collections.sort(sortedKeys, new Comparator<Key>() {

        @Override
        public int compare(final Key o1, final Key o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    for (Key key : sortedKeys) {
        AssocKeySchema assocKeySchema = new AssocKeySchema();
        assocKeySchema.setName(key.getName());
        assocKeySchema.setType(buildDataSchemaType(key.getType(), key.getDataSchema()));
        assocKeySchemaArray.add(assocKeySchema);
    }
    associationSchema.setAssocKeys(assocKeySchemaArray);
    associationSchema.setIdentifier(collectionModel.getKeyName());
}
Also used : AssocKeySchemaArray(com.linkedin.restli.restspec.AssocKeySchemaArray) ArrayList(java.util.ArrayList) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) AlternativeKey(com.linkedin.restli.server.AlternativeKey) AssocKeySchema(com.linkedin.restli.restspec.AssocKeySchema)

Example 3 with AssocKeySchemaArray

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

the class TestResourceCompatibilityChecker method testFailAssociationFile.

@Test
public void testFailAssociationFile() throws IOException {
    final AssocKeySchema prevAssocKey = new AssocKeySchema();
    prevAssocKey.setName("key1");
    prevAssocKey.setType("string");
    final Collection<CompatibilityInfo> testErrors = new HashSet<CompatibilityInfo>();
    testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "assocKeys"), CompatibilityInfo.Type.ARRAY_NOT_EQUAL, new AssocKeySchemaArray(Arrays.asList(prevAssocKey))));
    testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "supports"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("create", "get"))));
    testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "methods", "create", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_REQUIRED, "data"));
    testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "methods"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "get"));
    testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "entity", "path"), CompatibilityInfo.Type.VALUE_NOT_EQUAL, "/greetings/assoc/{greetingsId}", "/greetings/association/{greetingsId}"));
    final ResourceSchema prevResource = idlToResource(IDLS_SUFFIX + PREV_ASSOC_FILE);
    final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_ASSOC_FAIL_FILE);
    ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevResource, prevSchemaResolver, currResource, prevSchemaResolver);
    Assert.assertFalse(checker.check(CompatibilityLevel.BACKWARDS));
    final Collection<CompatibilityInfo> incompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getIncompatibles());
    for (CompatibilityInfo te : testErrors) {
        Assert.assertTrue(incompatibles.contains(te), "Reported incompatibles should contain: " + te.toString());
        incompatibles.remove(te);
    }
    Assert.assertTrue(incompatibles.isEmpty());
}
Also used : AssocKeySchemaArray(com.linkedin.restli.restspec.AssocKeySchemaArray) ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) StringArray(com.linkedin.data.template.StringArray) CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo) AssocKeySchema(com.linkedin.restli.restspec.AssocKeySchema) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

AssocKeySchema (com.linkedin.restli.restspec.AssocKeySchema)3 AssocKeySchemaArray (com.linkedin.restli.restspec.AssocKeySchemaArray)3 StringArray (com.linkedin.data.template.StringArray)2 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1 CompoundKey (com.linkedin.restli.common.CompoundKey)1 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)1 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)1 AlternativeKey (com.linkedin.restli.server.AlternativeKey)1 Key (com.linkedin.restli.server.Key)1 CompatibilityInfo (com.linkedin.restli.tools.idlcheck.CompatibilityInfo)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.testng.annotations.Test)1