use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class ResourceSchemaToResourceSpecTranslator method collectionToResourceSpec.
@SuppressWarnings("rawtypes")
private ResourceSpec collectionToResourceSpec(ResourceSchema resourceSchema, CollectionSchema collection) {
ActionSchemaArray actions = null, entityActions = null;
StringArray supports = collection.getSupports();
if (collection.hasActions()) {
actions = collection.getActions();
}
if (collection.getEntity().hasActions()) {
entityActions = collection.getEntity().getActions();
}
String schema = resourceSchema.getSchema();
IdentifierSchema identifier = collection.getIdentifier();
if (// in this case we have a "simple" collection resource
identifier.getParams() == null) {
DataSchema key = RestSpecCodec.textToSchema(identifier.getType(), _schemaResolver);
return buildResourceSpec(supports, toTypeSpec(key), null, Collections.<String, Object>emptyMap(), schema, actions, entityActions);
} else // we have a complex collection resource
{
DataSchema keyKeyType = RestSpecCodec.textToSchema(identifier.getType(), _schemaResolver);
DataSchema keyParamsType = RestSpecCodec.textToSchema(identifier.getParams(), _schemaResolver);
ComplexKeySpec<?, ?> complexKeyType = toComplexKey(keyKeyType, keyParamsType);
return buildResourceSpec(supports, new TypeSpec<ComplexResourceKey>(ComplexResourceKey.class, null), complexKeyType, Collections.<String, Object>emptyMap(), schema, actions, entityActions);
}
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchUpdate.
public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchUpdate(BatchPatchRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> patches) {
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse>();
for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>> patch : patches.getData().entrySet()) {
try {
this.partialUpdate(patch.getKey(), patch.getValue());
results.put(patch.getKey(), new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
} catch (DataProcessingException e) {
results.put(patch.getKey(), new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
}
}
return new BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(results);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchGet.
public BatchResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGet(Set<ComplexResourceKey<TwoPartKey, TwoPartKey>> keys) {
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> data = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>();
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException> errors = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException>();
for (ComplexResourceKey<TwoPartKey, TwoPartKey> key : keys) {
String stringKey = keyToString(key.getKey());
if (_db.containsKey(stringKey)) {
data.put(key, _db.get(stringKey));
} else {
errors.put(key, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
}
}
return new BatchResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(data, errors);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchDelete.
public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchDelete(BatchDeleteRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> ids) {
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse>();
for (ComplexResourceKey<TwoPartKey, TwoPartKey> id : ids.getKeys()) {
_db.remove(keyToString(id.getKey()));
results.put(id, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
}
return new BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(results);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method create.
public ComplexResourceKey<TwoPartKey, TwoPartKey> create(Message message) {
TwoPartKey key = new TwoPartKey();
key.setMajor(message.getMessage());
key.setMinor(message.getMessage());
_db.put(keyToString(key), message);
return new ComplexResourceKey<TwoPartKey, TwoPartKey>(key, new TwoPartKey());
}
Aggregations