Search in sources :

Example 1 with PlatformRuntimeException

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;
}
Also used : PlatformRuntimeException(org.springframework.extensions.surf.exception.PlatformRuntimeException) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) Api(org.alfresco.rest.framework.Api) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Api (org.alfresco.rest.framework.Api)1 PlatformRuntimeException (org.springframework.extensions.surf.exception.PlatformRuntimeException)1