use of org.springframework.extensions.surf.exception.PlatformRuntimeException in project alfresco-remote-api by Alfresco.
the class ResourceDictionaryBuilder method parseResources.
/**
* Sort through the resources grouping them by api name/scope, then version.
* @param resources Collection<Object>
* @return Map
*/
private static <T> Map<ApiScopeKey, Map<Integer, List<ResourceWithMetadata>>> parseResources(Collection<Object> resources) {
Map<ApiScopeKey, Map<Integer, List<ResourceWithMetadata>>> apiMap = new HashMap<ApiScopeKey, Map<Integer, List<ResourceWithMetadata>>>();
for (Object bean : resources) {
List<ResourceMetadata> metaData = ResourceInspector.inspect(bean.getClass());
Api api = ResourceInspector.inspectApi(bean.getClass());
if (api == null) {
throw new PlatformRuntimeException("Invalid resource bean defintion. No @WebApi defined for package: " + bean.getClass().getPackage().getName());
}
ApiScopeKey key = new ApiScopeKey(api);
// Find api scope/name and use a key
Map<Integer, List<ResourceWithMetadata>> apiVersions = apiMap.get(key);
if (apiVersions == null) {
// if doesn't exist then create it.
apiVersions = new HashMap<Integer, List<ResourceWithMetadata>>();
apiMap.put(key, apiVersions);
}
List<ResourceWithMetadata> resourcesWithMeta = apiVersions.get(api.getVersion());
if (resourcesWithMeta == null) {
// if doesn't exist then create it.
resourcesWithMeta = new ArrayList<ResourceWithMetadata>();
apiVersions.put(api.getVersion(), resourcesWithMeta);
}
// For each meta just add it to the list.
for (ResourceMetadata resourceMeta : metaData) {
resourcesWithMeta.add(new ResourceWithMetadata(bean, resourceMeta));
}
}
return apiMap;
}