protected ContentListDescribeResponseResource describeResponse(Context context, Request req, Response res,
Variant variant, ResourceStoreRequest request,
StorageItem item, Throwable e)
{
ContentListDescribeResponseResource result = new ContentListDescribeResponseResource();
result.getProcessedRepositoriesList().addAll(request.getProcessedRepositories());
// applied mappings
for (Map.Entry<String, List<String>> mappingEntry : request.getAppliedMappings().entrySet()) {
result.addAppliedMapping(mappingEntry.getKey() + " repository applied " + mappingEntry.getValue());
}
if (item == null) {
result.setResponseType("NOT_FOUND");
if (e != null) {
result.addNotFoundReasoning(buildNotFoundReasoning(null, e));
}
return result;
}
if (item instanceof StorageFileItem) {
result.setResponseType("FILE");
}
else if (item instanceof StorageCollectionItem) {
result.setResponseType("COLL");
}
else if (item instanceof StorageLinkItem) {
result.setResponseType("LINK");
}
else {
result.setResponseType(item.getClass().getName());
}
result.setResponseActualClass(item.getClass().getName());
result.setResponsePath(item.getPath());
if (!item.isVirtual()) {
result.setResponseUid(item.getRepositoryItemUid().toString());
result.setOriginatingRepositoryId(item.getRepositoryItemUid().getRepository().getId());
result.setOriginatingRepositoryName(item.getRepositoryItemUid().getRepository().getName());
result.setOriginatingRepositoryMainFacet(
item.getRepositoryItemUid().getRepository().getRepositoryKind().getMainFacet().getName());
}
else {
result.setResponseUid("virtual");
}
// properties
result.addProperty("created=" + item.getCreated());
result.addProperty("modified=" + item.getModified());
result.addProperty("lastRequested=" + item.getLastRequested());
result.addProperty("remoteChecked=" + item.getRemoteChecked());
result.addProperty("remoteUrl=" + item.getRemoteUrl());
result.addProperty("storedLocally=" + item.getStoredLocally());
result.addProperty("isExpired=" + item.isExpired());
result.addProperty("readable=" + item.isReadable());
result.addProperty("writable=" + item.isWritable());
result.addProperty("virtual=" + item.isVirtual());
// attributes
final TreeMap<String, String> sortedAttributes = Maps.newTreeMap();
sortedAttributes.putAll(item.getRepositoryItemAttributes().asMap());
for (Map.Entry<String, String> entry : sortedAttributes.entrySet()) {
result.addAttribute(entry.toString());
}
// sources
if (item instanceof StorageCompositeItem) {
StorageCompositeItem composite = (StorageCompositeItem) item;
for (StorageItem source : composite.getSources()) {
if (!source.isVirtual()) {
result.addSource(source.getRepositoryItemUid().toString());
}
else {
result.addSource(source.getPath());
}
}
}
return result;