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);
}
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());
}
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());
}
Aggregations