@Test public void testToResource() throws Exception { ViewInstanceResourceProvider provider = new ViewInstanceResourceProvider(); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(ViewInstanceResourceProvider.PROPERTIES_PROPERTY_ID); propertyIds.add(ViewInstanceResourceProvider.CLUSTER_HANDLE_PROPERTY_ID); ViewInstanceEntity viewInstanceEntity = createNiceMock(ViewInstanceEntity.class); ViewEntity viewEntity = createNiceMock(ViewEntity.class); expect(viewInstanceEntity.getViewEntity()).andReturn(viewEntity).anyTimes(); Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put("par1", "val1"); propertyMap.put("par2", "val2"); expect(viewInstanceEntity.getPropertyMap()).andReturn(propertyMap); expect(viewInstanceEntity.getData()).andReturn(Collections.<ViewInstanceDataEntity>emptyList()).anyTimes(); expect(viewregistry.checkAdmin()).andReturn(true); expect(viewregistry.checkAdmin()).andReturn(false); expect(viewInstanceEntity.getClusterHandle()).andReturn(1L); replay(viewregistry, viewEntity, viewInstanceEntity); Resource resource = provider.toResource(viewInstanceEntity, propertyIds); Map<String, Map<String, Object>> properties = resource.getPropertiesMap(); assertEquals(2, properties.size()); Map<String, Object> props = properties.get("ViewInstanceInfo"); assertNotNull(props); assertEquals(1, props.size()); assertEquals(1L, props.get("cluster_handle")); props = properties.get("ViewInstanceInfo/properties"); assertNotNull(props); assertEquals(2, props.size()); assertEquals("val1", props.get("par1")); assertEquals("val2", props.get("par2")); resource = provider.toResource(viewInstanceEntity, propertyIds); properties = resource.getPropertiesMap(); props = properties.get("ViewInstanceInfo/properties"); assertNull(props); verify(viewregistry, viewEntity, viewInstanceEntity); }
protected Resource toResource(ViewInstanceEntity viewInstanceEntity, Set<String> requestedIds) { Resource resource = new ResourceImpl(Resource.Type.ViewInstance); ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); setResourceProperty(resource, VIEW_NAME_PROPERTY_ID, viewName, requestedIds); setResourceProperty(resource, VIEW_VERSION_PROPERTY_ID, version, requestedIds); setResourceProperty(resource, INSTANCE_NAME_PROPERTY_ID, name, requestedIds); setResourceProperty(resource, LABEL_PROPERTY_ID, viewInstanceEntity.getLabel(), requestedIds); setResourceProperty(resource, DESCRIPTION_PROPERTY_ID, viewInstanceEntity.getDescription(), requestedIds); setResourceProperty(resource, VISIBLE_PROPERTY_ID, viewInstanceEntity.isVisible(), requestedIds); setResourceProperty(resource, STATIC_PROPERTY_ID, viewInstanceEntity.isXmlDriven(), requestedIds); setResourceProperty(resource, CLUSTER_HANDLE_PROPERTY_ID, viewInstanceEntity.getClusterHandle(), requestedIds); setResourceProperty(resource, CLUSTER_TYPE_PROPERTY_ID, viewInstanceEntity.getClusterType(), requestedIds); ViewURLEntity viewUrl = viewInstanceEntity.getViewUrl(); if(viewUrl != null) { setResourceProperty(resource, SHORT_URL_PROPERTY_ID, viewUrl.getUrlSuffix(), requestedIds); setResourceProperty(resource, SHORT_URL_NAME_PROPERTY_ID, viewUrl.getUrlName(), requestedIds); } if (ViewRegistry.getInstance().checkAdmin()) { setResourceProperty(resource, PROPERTIES_PROPERTY_ID, viewInstanceEntity.getPropertyMap(), requestedIds); } Map<String, String> applicationData = new HashMap<String, String>(); String currentUserName = viewInstanceEntity.getCurrentUserName(); for (ViewInstanceDataEntity viewInstanceDataEntity : viewInstanceEntity.getData()) { if (currentUserName.equals(viewInstanceDataEntity.getUser())) { applicationData.put(viewInstanceDataEntity.getName(), viewInstanceDataEntity.getValue()); } } setResourceProperty(resource, DATA_PROPERTY_ID, applicationData, requestedIds); String contextPath = ViewInstanceEntity.getContextPath(viewName, version, name); setResourceProperty(resource, CONTEXT_PATH_PROPERTY_ID,contextPath, requestedIds); setResourceProperty(resource, ICON_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon()), requestedIds); setResourceProperty(resource, ICON64_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon64()), requestedIds); if (viewEntity.hasValidator()) { if (isPropertyRequested(VALIDATION_RESULT_PROPERTY_ID, requestedIds) || isPropertyRequested(PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, requestedIds)) { InstanceValidationResultImpl result = viewInstanceEntity.getValidationResult(viewEntity, Validator.ValidationContext.EXISTING); setResourceProperty(resource, VALIDATION_RESULT_PROPERTY_ID, ValidationResultImpl.create(result), requestedIds); setResourceProperty(resource, PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, result.getPropertyResults(), requestedIds); } } return resource; }
ViewInstanceResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewInstanceEntity viewInstanceEntity, Set<String> requestedIds) { Resource resource = new ResourceImpl(Resource.Type.ViewInstance); ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); setResourceProperty(resource, VIEW_NAME_PROPERTY_ID, viewName, requestedIds); setResourceProperty(resource, VIEW_VERSION_PROPERTY_ID, version, requestedIds); setResourceProperty(resource, INSTANCE_NAME_PROPERTY_ID, name, requestedIds); setResourceProperty(resource, LABEL_PROPERTY_ID, viewInstanceEntity.getLabel(), requestedIds); setResourceProperty(resource, DESCRIPTION_PROPERTY_ID, viewInstanceEntity.getDescription(), requestedIds); setResourceProperty(resource, VISIBLE_PROPERTY_ID, viewInstanceEntity.isVisible(), requestedIds); setResourceProperty(resource, STATIC_PROPERTY_ID, viewInstanceEntity.isXmlDriven(), requestedIds); setResourceProperty(resource, CLUSTER_HANDLE_PROPERTY_ID, viewInstanceEntity.getClusterHandle(), requestedIds); setResourceProperty(resource, CLUSTER_TYPE_PROPERTY_ID, viewInstanceEntity.getClusterType(), requestedIds); ViewURLEntity viewUrl = viewInstanceEntity.getViewUrl(); if(viewUrl != null) { setResourceProperty(resource, SHORT_URL_PROPERTY_ID, viewUrl.getUrlSuffix(), requestedIds); setResourceProperty(resource, SHORT_URL_NAME_PROPERTY_ID, viewUrl.getUrlName(), requestedIds); } if (ViewRegistry.getInstance().checkAdmin()) { setResourceProperty(resource, PROPERTIES_PROPERTY_ID, viewInstanceEntity.getPropertyMap(), requestedIds); } Map<String, String> applicationData = new HashMap<String, String>(); String currentUserName = viewInstanceEntity.getCurrentUserName(); for (ViewInstanceDataEntity viewInstanceDataEntity : viewInstanceEntity.getData()) { if (currentUserName.equals(viewInstanceDataEntity.getUser())) { applicationData.put(viewInstanceDataEntity.getName(), viewInstanceDataEntity.getValue()); } } setResourceProperty(resource, DATA_PROPERTY_ID, applicationData, requestedIds); String contextPath = ViewInstanceEntity.getContextPath(viewName, version, name); setResourceProperty(resource, CONTEXT_PATH_PROPERTY_ID,contextPath, requestedIds); setResourceProperty(resource, ICON_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon()), requestedIds); setResourceProperty(resource, ICON64_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon64()), requestedIds); if (viewEntity.hasValidator()) { if (isPropertyRequested(VALIDATION_RESULT_PROPERTY_ID, requestedIds) || isPropertyRequested(PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, requestedIds)) { InstanceValidationResultImpl result = viewInstanceEntity.getValidationResult(viewEntity, Validator.ValidationContext.EXISTING); setResourceProperty(resource, VALIDATION_RESULT_PROPERTY_ID, ValidationResultImpl.create(result), requestedIds); setResourceProperty(resource, PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, result.getPropertyResults(), requestedIds); } } return resource; } }
ViewInstanceResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewInstanceEntity viewInstanceEntity, Set<String> requestedIds) { Resource resource = new ResourceImpl(Resource.Type.ViewInstance); ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); setResourceProperty(resource, VIEW_NAME_PROPERTY_ID, viewName, requestedIds); setResourceProperty(resource, VIEW_VERSION_PROPERTY_ID, version, requestedIds); setResourceProperty(resource, INSTANCE_NAME_PROPERTY_ID, name, requestedIds); setResourceProperty(resource, LABEL_PROPERTY_ID, viewInstanceEntity.getLabel(), requestedIds); setResourceProperty(resource, DESCRIPTION_PROPERTY_ID, viewInstanceEntity.getDescription(), requestedIds); setResourceProperty(resource, VISIBLE_PROPERTY_ID, viewInstanceEntity.isVisible(), requestedIds); setResourceProperty(resource, STATIC_PROPERTY_ID, viewInstanceEntity.isXmlDriven(), requestedIds); setResourceProperty(resource, CLUSTER_HANDLE_PROPERTY_ID, viewInstanceEntity.getClusterHandle(), requestedIds); setResourceProperty(resource, CLUSTER_TYPE_PROPERTY_ID, viewInstanceEntity.getClusterType(), requestedIds); ViewURLEntity viewUrl = viewInstanceEntity.getViewUrl(); if(viewUrl != null) { setResourceProperty(resource, SHORT_URL_PROPERTY_ID, viewUrl.getUrlSuffix(), requestedIds); setResourceProperty(resource, SHORT_URL_NAME_PROPERTY_ID, viewUrl.getUrlName(), requestedIds); } if (ViewRegistry.getInstance().checkAdmin()) { setResourceProperty(resource, PROPERTIES_PROPERTY_ID, viewInstanceEntity.getPropertyMap(), requestedIds); } Map<String, String> applicationData = new HashMap<String, String>(); String currentUserName = viewInstanceEntity.getCurrentUserName(); for (ViewInstanceDataEntity viewInstanceDataEntity : viewInstanceEntity.getData()) { if (currentUserName.equals(viewInstanceDataEntity.getUser())) { applicationData.put(viewInstanceDataEntity.getName(), viewInstanceDataEntity.getValue()); } } setResourceProperty(resource, DATA_PROPERTY_ID, applicationData, requestedIds); String contextPath = ViewInstanceEntity.getContextPath(viewName, version, name); setResourceProperty(resource, CONTEXT_PATH_PROPERTY_ID,contextPath, requestedIds); setResourceProperty(resource, ICON_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon()), requestedIds); setResourceProperty(resource, ICON64_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon64()), requestedIds); if (viewEntity.hasValidator()) { if (isPropertyRequested(VALIDATION_RESULT_PROPERTY_ID, requestedIds) || isPropertyRequested(PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, requestedIds)) { InstanceValidationResultImpl result = viewInstanceEntity.getValidationResult(viewEntity, Validator.ValidationContext.EXISTING); setResourceProperty(resource, VALIDATION_RESULT_PROPERTY_ID, ValidationResultImpl.create(result), requestedIds); setResourceProperty(resource, PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, result.getPropertyResults(), requestedIds); } } return resource; } ViewInstanceResourceProvider(); }
ViewInstanceResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewInstanceEntity viewInstanceEntity, Set<String> requestedIds) { Resource resource = new ResourceImpl(Resource.Type.ViewInstance); ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); setResourceProperty(resource, VIEW_NAME_PROPERTY_ID, viewName, requestedIds); setResourceProperty(resource, VIEW_VERSION_PROPERTY_ID, version, requestedIds); setResourceProperty(resource, INSTANCE_NAME_PROPERTY_ID, name, requestedIds); setResourceProperty(resource, LABEL_PROPERTY_ID, viewInstanceEntity.getLabel(), requestedIds); setResourceProperty(resource, DESCRIPTION_PROPERTY_ID, viewInstanceEntity.getDescription(), requestedIds); setResourceProperty(resource, VISIBLE_PROPERTY_ID, viewInstanceEntity.isVisible(), requestedIds); setResourceProperty(resource, STATIC_PROPERTY_ID, viewInstanceEntity.isXmlDriven(), requestedIds); setResourceProperty(resource, CLUSTER_HANDLE_PROPERTY_ID, viewInstanceEntity.getClusterHandle(), requestedIds); setResourceProperty(resource, CLUSTER_TYPE_PROPERTY_ID, viewInstanceEntity.getClusterType(), requestedIds); ViewURLEntity viewUrl = viewInstanceEntity.getViewUrl(); if(viewUrl != null) { setResourceProperty(resource, SHORT_URL_PROPERTY_ID, viewUrl.getUrlSuffix(), requestedIds); setResourceProperty(resource, SHORT_URL_NAME_PROPERTY_ID, viewUrl.getUrlName(), requestedIds); } if (ViewRegistry.getInstance().checkAdmin()) { setResourceProperty(resource, PROPERTIES_PROPERTY_ID, viewInstanceEntity.getPropertyMap(), requestedIds); } Map<String, String> applicationData = new HashMap<String, String>(); String currentUserName = viewInstanceEntity.getCurrentUserName(); for (ViewInstanceDataEntity viewInstanceDataEntity : viewInstanceEntity.getData()) { if (currentUserName.equals(viewInstanceDataEntity.getUser())) { applicationData.put(viewInstanceDataEntity.getName(), viewInstanceDataEntity.getValue()); } } setResourceProperty(resource, DATA_PROPERTY_ID, applicationData, requestedIds); String contextPath = ViewInstanceEntity.getContextPath(viewName, version, name); setResourceProperty(resource, CONTEXT_PATH_PROPERTY_ID,contextPath, requestedIds); setResourceProperty(resource, ICON_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon()), requestedIds); setResourceProperty(resource, ICON64_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon64()), requestedIds); if (viewEntity.hasValidator()) { if (isPropertyRequested(VALIDATION_RESULT_PROPERTY_ID, requestedIds) || isPropertyRequested(PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, requestedIds)) { InstanceValidationResultImpl result = viewInstanceEntity.getValidationResult(viewEntity, Validator.ValidationContext.EXISTING); setResourceProperty(resource, VALIDATION_RESULT_PROPERTY_ID, ValidationResultImpl.create(result), requestedIds); setResourceProperty(resource, PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, result.getPropertyResults(), requestedIds); } } return resource; } ViewInstanceResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); }
ViewInstanceResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewInstanceEntity viewInstanceEntity, Set<String> requestedIds) { Resource resource = new ResourceImpl(Resource.Type.ViewInstance); ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); setResourceProperty(resource, VIEW_NAME_PROPERTY_ID, viewName, requestedIds); setResourceProperty(resource, VIEW_VERSION_PROPERTY_ID, version, requestedIds); setResourceProperty(resource, INSTANCE_NAME_PROPERTY_ID, name, requestedIds); setResourceProperty(resource, LABEL_PROPERTY_ID, viewInstanceEntity.getLabel(), requestedIds); setResourceProperty(resource, DESCRIPTION_PROPERTY_ID, viewInstanceEntity.getDescription(), requestedIds); setResourceProperty(resource, VISIBLE_PROPERTY_ID, viewInstanceEntity.isVisible(), requestedIds); setResourceProperty(resource, STATIC_PROPERTY_ID, viewInstanceEntity.isXmlDriven(), requestedIds); setResourceProperty(resource, CLUSTER_HANDLE_PROPERTY_ID, viewInstanceEntity.getClusterHandle(), requestedIds); setResourceProperty(resource, CLUSTER_TYPE_PROPERTY_ID, viewInstanceEntity.getClusterType(), requestedIds); ViewURLEntity viewUrl = viewInstanceEntity.getViewUrl(); if(viewUrl != null) { setResourceProperty(resource, SHORT_URL_PROPERTY_ID, viewUrl.getUrlSuffix(), requestedIds); setResourceProperty(resource, SHORT_URL_NAME_PROPERTY_ID, viewUrl.getUrlName(), requestedIds); } if (ViewRegistry.getInstance().checkAdmin()) { setResourceProperty(resource, PROPERTIES_PROPERTY_ID, viewInstanceEntity.getPropertyMap(), requestedIds); } Map<String, String> applicationData = new HashMap<String, String>(); String currentUserName = viewInstanceEntity.getCurrentUserName(); for (ViewInstanceDataEntity viewInstanceDataEntity : viewInstanceEntity.getData()) { if (currentUserName.equals(viewInstanceDataEntity.getUser())) { applicationData.put(viewInstanceDataEntity.getName(), viewInstanceDataEntity.getValue()); } } setResourceProperty(resource, DATA_PROPERTY_ID, applicationData, requestedIds); String contextPath = ViewInstanceEntity.getContextPath(viewName, version, name); setResourceProperty(resource, CONTEXT_PATH_PROPERTY_ID,contextPath, requestedIds); setResourceProperty(resource, ICON_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon()), requestedIds); setResourceProperty(resource, ICON64_PATH_ID, getIconPath(contextPath, viewInstanceEntity.getIcon64()), requestedIds); if (viewEntity.hasValidator()) { if (isPropertyRequested(VALIDATION_RESULT_PROPERTY_ID, requestedIds) || isPropertyRequested(PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, requestedIds)) { InstanceValidationResultImpl result = viewInstanceEntity.getValidationResult(viewEntity, Validator.ValidationContext.EXISTING); setResourceProperty(resource, VALIDATION_RESULT_PROPERTY_ID, ValidationResultImpl.create(result), requestedIds); setResourceProperty(resource, PROPERTY_VALIDATION_RESULTS_PROPERTY_ID, result.getPropertyResults(), requestedIds); } } return resource; } ViewInstanceResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); static final String VIEW_NAME_PROPERTY_ID; static final String VIEW_VERSION_PROPERTY_ID; static final String INSTANCE_NAME_PROPERTY_ID; static final String LABEL_PROPERTY_ID; static final String DESCRIPTION_PROPERTY_ID; static final String VISIBLE_PROPERTY_ID; static final String ICON_PATH_ID; static final String ICON64_PATH_ID; static final String PROPERTIES_PROPERTY_ID; static final String DATA_PROPERTY_ID; static final String CONTEXT_PATH_PROPERTY_ID; static final String STATIC_PROPERTY_ID; static final String CLUSTER_HANDLE_PROPERTY_ID; static final String CLUSTER_TYPE_PROPERTY_ID; static final String SHORT_URL_PROPERTY_ID; static final String SHORT_URL_NAME_PROPERTY_ID; static final String VALIDATION_RESULT_PROPERTY_ID; static final String PROPERTY_VALIDATION_RESULTS_PROPERTY_ID; }