@Test public void testGetResourcesNoPredicate() throws Exception { WidgetLayoutResourceProvider provider = createProvider(null); Request request = PropertyHelper.getReadRequest("WidgetLayouts/id"); Set<Resource> results = provider.getResources(request, null); assertEquals(0, results.size()); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<Resource>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); List<WidgetEntity> widgetEntities = new ArrayList<WidgetEntity>(); List<WidgetLayoutEntity> layoutEntities = new ArrayList<WidgetLayoutEntity>(); for (Map<String, Object> propertyMap: propertyMaps) { String userName = getUserName(propertyMap); if (propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID) != null) { final Long id; try { id = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("WidgetLayout should have numerical id"); } final WidgetLayoutEntity entity = widgetLayoutDAO.findById(id); if (entity == null) { throw new NoSuchResourceException("WidgetLayout with id " + id + " does not exists"); } layoutEntities.add(entity); } else { layoutEntities.addAll(widgetLayoutDAO.findAll()); } } for (WidgetLayoutEntity layoutEntity : layoutEntities) { Resource resource = new ResourceImpl(Type.WidgetLayout); resource.setProperty(WIDGETLAYOUT_ID_PROPERTY_ID, layoutEntity.getId()); String clusterName = null; try { clusterName = getManagementController().getClusters().getClusterById(layoutEntity.getClusterId()).getClusterName(); } catch (AmbariException e) { throw new SystemException(e.getMessage()); } resource.setProperty(WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID, clusterName); resource.setProperty(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID, layoutEntity.getLayoutName()); resource.setProperty(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID, layoutEntity.getSectionName()); resource.setProperty(WIDGETLAYOUT_SCOPE_PROPERTY_ID, layoutEntity.getScope()); resource.setProperty(WIDGETLAYOUT_USERNAME_PROPERTY_ID, layoutEntity.getUserName()); resource.setProperty(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID, layoutEntity.getDisplayName()); List<HashMap> widgets = new ArrayList<HashMap>(); List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = layoutEntity.getListWidgetLayoutUserWidgetEntity(); for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : widgetLayoutUserWidgetEntityList) { WidgetEntity widgetEntity = widgetLayoutUserWidgetEntity.getWidget(); HashMap<String, Object> widgetInfoMap = new HashMap<String, Object>(); widgetInfoMap.put("WidgetInfo",WidgetResponse.coerce(widgetEntity)); widgets.add(widgetInfoMap); } resource.setProperty(WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgets); resources.add(resource); } return resources; }
WidgetLayoutResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<Resource>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); List<WidgetEntity> widgetEntities = new ArrayList<WidgetEntity>(); List<WidgetLayoutEntity> layoutEntities = new ArrayList<WidgetLayoutEntity>(); for (Map<String, Object> propertyMap: propertyMaps) { String userName = getUserName(propertyMap); if (propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID) != null) { final Long id; try { id = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("WidgetLayout should have numerical id"); } final WidgetLayoutEntity entity = widgetLayoutDAO.findById(id); if (entity == null) { throw new NoSuchResourceException("WidgetLayout with id " + id + " does not exists"); } layoutEntities.add(entity); } else { layoutEntities.addAll(widgetLayoutDAO.findAll()); } } for (WidgetLayoutEntity layoutEntity : layoutEntities) { Resource resource = new ResourceImpl(Type.WidgetLayout); resource.setProperty(WIDGETLAYOUT_ID_PROPERTY_ID, layoutEntity.getId()); String clusterName = null; try { clusterName = getManagementController().getClusters().getClusterById(layoutEntity.getClusterId()).getClusterName(); } catch (AmbariException e) { throw new SystemException(e.getMessage()); } resource.setProperty(WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID, clusterName); resource.setProperty(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID, layoutEntity.getLayoutName()); resource.setProperty(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID, layoutEntity.getSectionName()); resource.setProperty(WIDGETLAYOUT_SCOPE_PROPERTY_ID, layoutEntity.getScope()); resource.setProperty(WIDGETLAYOUT_USERNAME_PROPERTY_ID, layoutEntity.getUserName()); resource.setProperty(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID, layoutEntity.getDisplayName()); List<HashMap> widgets = new ArrayList<HashMap>(); List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = layoutEntity.getListWidgetLayoutUserWidgetEntity(); for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : widgetLayoutUserWidgetEntityList) { WidgetEntity widgetEntity = widgetLayoutUserWidgetEntity.getWidget(); HashMap<String, Object> widgetInfoMap = new HashMap<String, Object>(); widgetInfoMap.put("WidgetInfo",WidgetResponse.coerce(widgetEntity)); widgets.add(widgetInfoMap); } resource.setProperty(WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgets); resources.add(resource); } return resources; } }
WidgetLayoutResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<Resource>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); List<WidgetEntity> widgetEntities = new ArrayList<WidgetEntity>(); List<WidgetLayoutEntity> layoutEntities = new ArrayList<WidgetLayoutEntity>(); for (Map<String, Object> propertyMap: propertyMaps) { String userName = getUserName(propertyMap); if (propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID) != null) { final Long id; try { id = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("WidgetLayout should have numerical id"); } final WidgetLayoutEntity entity = widgetLayoutDAO.findById(id); if (entity == null) { throw new NoSuchResourceException("WidgetLayout with id " + id + " does not exists"); } layoutEntities.add(entity); } else { layoutEntities.addAll(widgetLayoutDAO.findAll()); } } for (WidgetLayoutEntity layoutEntity : layoutEntities) { Resource resource = new ResourceImpl(Type.WidgetLayout); resource.setProperty(WIDGETLAYOUT_ID_PROPERTY_ID, layoutEntity.getId()); String clusterName = null; try { clusterName = getManagementController().getClusters().getClusterById(layoutEntity.getClusterId()).getClusterName(); } catch (AmbariException e) { throw new SystemException(e.getMessage()); } resource.setProperty(WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID, clusterName); resource.setProperty(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID, layoutEntity.getLayoutName()); resource.setProperty(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID, layoutEntity.getSectionName()); resource.setProperty(WIDGETLAYOUT_SCOPE_PROPERTY_ID, layoutEntity.getScope()); resource.setProperty(WIDGETLAYOUT_USERNAME_PROPERTY_ID, layoutEntity.getUserName()); resource.setProperty(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID, layoutEntity.getDisplayName()); List<HashMap> widgets = new ArrayList<HashMap>(); List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = layoutEntity.getListWidgetLayoutUserWidgetEntity(); for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : widgetLayoutUserWidgetEntityList) { WidgetEntity widgetEntity = widgetLayoutUserWidgetEntity.getWidget(); HashMap<String, Object> widgetInfoMap = new HashMap<String, Object>(); widgetInfoMap.put("WidgetInfo",WidgetResponse.coerce(widgetEntity)); widgets.add(widgetInfoMap); } resource.setProperty(WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgets); resources.add(resource); } return resources; } WidgetLayoutResourceProvider(AmbariManagementController managementController); }
WidgetLayoutResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<Resource>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); List<WidgetEntity> widgetEntities = new ArrayList<WidgetEntity>(); List<WidgetLayoutEntity> layoutEntities = new ArrayList<WidgetLayoutEntity>(); for (Map<String, Object> propertyMap: propertyMaps) { String userName = getUserName(propertyMap); if (propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID) != null) { final Long id; try { id = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("WidgetLayout should have numerical id"); } final WidgetLayoutEntity entity = widgetLayoutDAO.findById(id); if (entity == null) { throw new NoSuchResourceException("WidgetLayout with id " + id + " does not exists"); } layoutEntities.add(entity); } else { layoutEntities.addAll(widgetLayoutDAO.findAll()); } } for (WidgetLayoutEntity layoutEntity : layoutEntities) { Resource resource = new ResourceImpl(Type.WidgetLayout); resource.setProperty(WIDGETLAYOUT_ID_PROPERTY_ID, layoutEntity.getId()); String clusterName = null; try { clusterName = getManagementController().getClusters().getClusterById(layoutEntity.getClusterId()).getClusterName(); } catch (AmbariException e) { throw new SystemException(e.getMessage()); } resource.setProperty(WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID, clusterName); resource.setProperty(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID, layoutEntity.getLayoutName()); resource.setProperty(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID, layoutEntity.getSectionName()); resource.setProperty(WIDGETLAYOUT_SCOPE_PROPERTY_ID, layoutEntity.getScope()); resource.setProperty(WIDGETLAYOUT_USERNAME_PROPERTY_ID, layoutEntity.getUserName()); resource.setProperty(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID, layoutEntity.getDisplayName()); List<HashMap> widgets = new ArrayList<HashMap>(); List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = layoutEntity.getListWidgetLayoutUserWidgetEntity(); for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : widgetLayoutUserWidgetEntityList) { WidgetEntity widgetEntity = widgetLayoutUserWidgetEntity.getWidget(); HashMap<String, Object> widgetInfoMap = new HashMap<String, Object>(); widgetInfoMap.put("WidgetInfo",WidgetResponse.coerce(widgetEntity)); widgets.add(widgetInfoMap); } resource.setProperty(WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgets); resources.add(resource); } return resources; } WidgetLayoutResourceProvider(AmbariManagementController managementController); @Override RequestStatus createResources(final Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
WidgetLayoutResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<Resource>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); List<WidgetEntity> widgetEntities = new ArrayList<WidgetEntity>(); List<WidgetLayoutEntity> layoutEntities = new ArrayList<WidgetLayoutEntity>(); for (Map<String, Object> propertyMap: propertyMaps) { String userName = getUserName(propertyMap); if (propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID) != null) { final Long id; try { id = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("WidgetLayout should have numerical id"); } final WidgetLayoutEntity entity = widgetLayoutDAO.findById(id); if (entity == null) { throw new NoSuchResourceException("WidgetLayout with id " + id + " does not exists"); } layoutEntities.add(entity); } else { layoutEntities.addAll(widgetLayoutDAO.findAll()); } } for (WidgetLayoutEntity layoutEntity : layoutEntities) { Resource resource = new ResourceImpl(Type.WidgetLayout); resource.setProperty(WIDGETLAYOUT_ID_PROPERTY_ID, layoutEntity.getId()); String clusterName = null; try { clusterName = getManagementController().getClusters().getClusterById(layoutEntity.getClusterId()).getClusterName(); } catch (AmbariException e) { throw new SystemException(e.getMessage()); } resource.setProperty(WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID, clusterName); resource.setProperty(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID, layoutEntity.getLayoutName()); resource.setProperty(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID, layoutEntity.getSectionName()); resource.setProperty(WIDGETLAYOUT_SCOPE_PROPERTY_ID, layoutEntity.getScope()); resource.setProperty(WIDGETLAYOUT_USERNAME_PROPERTY_ID, layoutEntity.getUserName()); resource.setProperty(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID, layoutEntity.getDisplayName()); List<HashMap> widgets = new ArrayList<HashMap>(); List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = layoutEntity.getListWidgetLayoutUserWidgetEntity(); for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : widgetLayoutUserWidgetEntityList) { WidgetEntity widgetEntity = widgetLayoutUserWidgetEntity.getWidget(); HashMap<String, Object> widgetInfoMap = new HashMap<String, Object>(); widgetInfoMap.put("WidgetInfo",WidgetResponse.coerce(widgetEntity)); widgets.add(widgetInfoMap); } resource.setProperty(WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgets); resources.add(resource); } return resources; } WidgetLayoutResourceProvider(AmbariManagementController managementController); @Override RequestStatus createResources(final Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static final String WIDGETLAYOUT_ID_PROPERTY_ID; static final String WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID; static final String WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID; static final String WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID; static final String WIDGETLAYOUT_SCOPE_PROPERTY_ID; static final String WIDGETLAYOUT_WIDGETS_PROPERTY_ID; static final String WIDGETLAYOUT_USERNAME_PROPERTY_ID; static final String WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID; @SuppressWarnings("serial")
  static Set<String> propertyIds; @SuppressWarnings("serial")
  static Map<Type, String> keyPropertyIds; }