List of usage examples for java.util Map replace
default V replace(K key, V value)
From source file:org.wso2.carbon.apimgt.core.impl.APIPublisherImplTestCase.java
@Test(description = "Test add api with production endpoint") public void testUpdateApiEndpointOfUriTemplate() throws APIManagementException { /**// ww w . j a v a 2s. c o m * this test method verify the API Add with correct API object get invoked correctly */ Endpoint endpoint1 = new Endpoint.Builder().id(UUID.randomUUID().toString()) .endpointConfig("http://localhost").name("endpoint1") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Endpoint endpoint2 = new Endpoint.Builder().id(UUID.randomUUID().toString()) .endpointConfig("http://localhost").name("endpoint2") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Map<String, Endpoint> endpointMap = new HashMap<>(); endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, endpoint1); endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, endpoint2); Map<String, UriTemplate> uriTemplateMap = SampleTestObjectCreator.getMockUriTemplates(); uriTemplateMap.forEach((s, uriTemplate) -> uriTemplateMap.replace(s, new UriTemplate.UriTemplateBuilder(uriTemplate).endpoint(endpointMap).build())); API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id(UUID.randomUUID().toString()) .endpoint(Collections.emptyMap()).uriTemplates(uriTemplateMap); apiBuilder.apiPermission(""); apiBuilder.permissionMap(null); apiBuilder.policies(Collections.emptySet()); apiBuilder.apiPolicy(null); ApiDAO apiDAO = Mockito.mock(ApiDAO.class); Mockito.when(apiDAO.getAPI(apiBuilder.getId())).thenReturn(apiBuilder.build()); GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class); APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class); APIGateway gateway = Mockito.mock(APIGateway.class); PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class); Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY)); APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO); Mockito.when(apiDAO.getEndpoint(endpoint1.getId())).thenReturn(endpoint1); Mockito.when(apiDAO.getEndpoint(endpoint2.getId())).thenReturn(endpoint2); Mockito.when(apiDAO.getEndpoint(endpoint1.getName())).thenReturn(endpoint1); Mockito.when(apiDAO.getEndpointByName(endpoint2.getName())).thenReturn(endpoint2); apiPublisher.updateAPI(apiBuilder); Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(apiBuilder.getId(), apiBuilder.build()); }
From source file:org.wso2.carbon.apimgt.core.impl.APIPublisherImpl.java
private void validateEndpoints(Map<String, Endpoint> endpointMap, boolean apiUpdate) throws APIManagementException { if (endpointMap != null) { for (Map.Entry<String, Endpoint> entry : endpointMap.entrySet()) { if (APIMgtConstants.API_SPECIFIC_ENDPOINT.equals(entry.getValue().getApplicableLevel())) { Endpoint.Builder endpointBuilder = new Endpoint.Builder(entry.getValue()); if (StringUtils.isEmpty(endpointBuilder.getId())) { endpointBuilder.id(UUID.randomUUID().toString()); }/* w w w. j ava2s. co m*/ if (StringUtils.isEmpty(endpointBuilder.getApplicableLevel())) { endpointBuilder.applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT); } Endpoint endpoint = endpointBuilder.build(); try { Endpoint existingEndpoint = getApiDAO().getEndpoint(endpoint.getId()); if (existingEndpoint == null) { if (getApiDAO().getEndpointByName(endpoint.getName()) != null) { String msg = "Endpoint Already Exist By Name : " + endpoint.getName(); throw new APIManagementException(msg, ExceptionCodes.ENDPOINT_ALREADY_EXISTS); } else { endpointMap.replace(entry.getKey(), endpointBuilder.build()); } } else { if (apiUpdate && !existingEndpoint.getName().equals(endpoint.getName())) { if (getApiDAO().getEndpointByName(endpoint.getName()) != null) { String msg = "Endpoint Already Exist By Name : " + endpoint.getName(); throw new APIManagementException(msg, ExceptionCodes.ENDPOINT_ALREADY_EXISTS); } else { endpointMap.replace(entry.getKey(), endpointBuilder.build()); } } } } catch (APIMgtDAOException e) { String msg = "Couldn't find Endpoint By Name : " + endpoint.getName(); log.error(msg, e); throw new APIManagementException(msg, e, ExceptionCodes.APIMGT_DAO_EXCEPTION); } } else { endpointMap.replace(entry.getKey(), getEndpoint(entry.getValue().getId())); } } } }
From source file:org.wso2.carbon.apimgt.core.impl.APIPublisherImplTestCase.java
@Test(description = "Test add api with Api Specific Endpoint", expectedExceptions = { APIManagementException.class }) public void testAddResourceLevelEndpointWhileResourceEndpointAlreadyExists() throws APIManagementException, LifecycleException { /**//from w w w. j a v a 2s . com * this test method verify the API Add with correct API object get invoked correctly */ ApiDAO apiDAO = Mockito.mock(ApiDAO.class); GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class); APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class); Endpoint globalEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("testEndpoint") .applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build(); Endpoint apiEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("apiEndpoint") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Endpoint resourceEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("resourceEndpoint") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Map<String, Endpoint> endpointMap = new HashMap(); endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, globalEndpoint); endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, apiEndpoint); Map<String, Endpoint> resourceEndpoints = new HashMap(); resourceEndpoints.put(APIMgtConstants.SANDBOX_ENDPOINT, resourceEndpoint); Map<String, UriTemplate> uriTemplateMap = SampleTestObjectCreator.getMockUriTemplates(); uriTemplateMap.forEach((k, v) -> { UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(v); uriTemplateBuilder.endpoint(resourceEndpoints); uriTemplateMap.replace(k, uriTemplateBuilder.build()); }); API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap) .uriTemplates(uriTemplateMap); Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)) .thenReturn(new LifecycleState()); APIGateway gateway = Mockito.mock(APIGateway.class); APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway); Mockito.when(apiDAO.getEndpoint(globalEndpoint.getId())).thenReturn(globalEndpoint); Mockito.when(apiDAO.getEndpointByName(apiEndpoint.getName())).thenReturn(null); Mockito.when(apiDAO.getEndpointByName(resourceEndpoint.getName())).thenReturn(resourceEndpoint); Mockito.when(apiDAO.isAPINameExists(apiBuilder.getName(), USER)).thenReturn(false); apiPublisher.addAPI(apiBuilder); Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build()); Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(apiEndpoint.getName()); Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(resourceEndpoint.getName()); }
From source file:org.wso2.carbon.apimgt.core.impl.APIPublisherImplTestCase.java
@Test(description = "Test add api with Api Specific Endpoint", expectedExceptions = { APIManagementException.class }) public void testAddResourceLevelEndpointWhileResourceEndpointAlreadyExistsWhileDatabaseFailure() throws APIManagementException, LifecycleException { /**// www. j a v a 2 s . c o m * this test method verify the API Add with correct API object get invoked correctly */ ApiDAO apiDAO = Mockito.mock(ApiDAO.class); GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class); APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class); Endpoint globalEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("testEndpoint") .applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build(); Endpoint apiEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("apiEndpoint") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Endpoint resourceEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("resourceEndpoint") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Map<String, Endpoint> endpointMap = new HashMap(); endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, globalEndpoint); endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, apiEndpoint); Map<String, Endpoint> resourceEndpoints = new HashMap(); resourceEndpoints.put(APIMgtConstants.SANDBOX_ENDPOINT, resourceEndpoint); Map<String, UriTemplate> uriTemplateMap = SampleTestObjectCreator.getMockUriTemplates(); uriTemplateMap.forEach((k, v) -> { UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(v); uriTemplateBuilder.endpoint(resourceEndpoints); uriTemplateMap.replace(k, uriTemplateBuilder.build()); }); API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap) .uriTemplates(uriTemplateMap); Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)) .thenReturn(new LifecycleState()); APIGateway gateway = Mockito.mock(APIGateway.class); APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway); Mockito.when(apiDAO.getEndpoint(globalEndpoint.getId())).thenReturn(globalEndpoint); Mockito.when(apiDAO.getEndpointByName(apiEndpoint.getName())).thenReturn(null); Mockito.when(apiDAO.getEndpointByName(resourceEndpoint.getName())).thenThrow(APIMgtDAOException.class); Mockito.when(apiDAO.isAPINameExists(apiBuilder.getName(), USER)).thenReturn(false); apiPublisher.addAPI(apiBuilder); Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build()); Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(apiEndpoint.getName()); Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(resourceEndpoint.getName()); }
From source file:org.wso2.carbon.apimgt.core.impl.APIPublisherImplTestCase.java
@Test(description = "Test add api with Api Specific Endpoint") public void testAddResourceLevelEndpoint() throws APIManagementException, LifecycleException { /**//from w w w. j a v a2 s . c o m * this test method verify the API Add with correct API object get invoked correctly */ ApiDAO apiDAO = Mockito.mock(ApiDAO.class); GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class); APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class); Endpoint globalEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("testEndpoint") .applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build(); Endpoint apiEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("apiEndpoint") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Endpoint resourceEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("resourceEndpoint") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Map<String, Endpoint> endpointMap = new HashMap(); endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, globalEndpoint); endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, apiEndpoint); Map<String, Endpoint> resourceEndpoints = new HashMap(); resourceEndpoints.put(APIMgtConstants.SANDBOX_ENDPOINT, resourceEndpoint); Map<String, UriTemplate> uriTemplateMap = SampleTestObjectCreator.getMockUriTemplates(); uriTemplateMap.forEach((k, v) -> { UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(v); uriTemplateBuilder.endpoint(resourceEndpoints); uriTemplateMap.replace(k, uriTemplateBuilder.build()); }); API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap) .uriTemplates(uriTemplateMap); Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)) .thenReturn(new LifecycleState()); APIGateway gateway = Mockito.mock(APIGateway.class); PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class); Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY)); Mockito.when( policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)) .thenReturn(new SubscriptionPolicy(GOLD_TIER)); Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER)); Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER)); APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO); Mockito.when(apiDAO.getEndpoint(globalEndpoint.getId())).thenReturn(globalEndpoint); Mockito.when(apiDAO.getEndpointByName(apiEndpoint.getName())).thenReturn(null); Mockito.when(apiDAO.getEndpointByName(resourceEndpoint.getName())).thenReturn(null); Mockito.when(apiDAO.isAPINameExists(apiBuilder.getName(), USER)).thenReturn(false); apiPublisher.addAPI(apiBuilder); Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build()); Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(apiEndpoint.getName()); Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(resourceEndpoint.getName()); }
From source file:org.wso2.carbon.apimgt.core.impl.APIPublisherImplTestCase.java
@Test(description = "Test add api with Api Specific Endpoint") public void testResourceProductionAndSandboxEndpoint() throws APIManagementException, LifecycleException { /**/*w ww . java2 s . c om*/ * this test method verify the API Add with correct API object get invoked correctly */ ApiDAO apiDAO = Mockito.mock(ApiDAO.class); GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class); APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class); Endpoint globalEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("testEndpoint") .applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build(); Endpoint apiEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("apiEndpoint") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Endpoint resourceEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("resourceEndpoint") .applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Endpoint resourceEndpoint1 = new Endpoint.Builder().id(UUID.randomUUID().toString()) .name("resourceEndpoint1").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build(); Map<String, Endpoint> endpointMap = new HashMap(); endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, globalEndpoint); endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, apiEndpoint); Map<String, Endpoint> resourceEndpoints = new HashMap(); resourceEndpoints.put(APIMgtConstants.SANDBOX_ENDPOINT, resourceEndpoint); resourceEndpoints.put(APIMgtConstants.PRODUCTION_ENDPOINT, resourceEndpoint1); Map<String, UriTemplate> uriTemplateMap = SampleTestObjectCreator.getMockUriTemplates(); uriTemplateMap.forEach((k, v) -> { UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(v); uriTemplateBuilder.endpoint(resourceEndpoints); uriTemplateMap.replace(k, uriTemplateBuilder.build()); }); API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap) .uriTemplates(uriTemplateMap); Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)) .thenReturn(new LifecycleState()); APIGateway gateway = Mockito.mock(APIGateway.class); PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class); Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY)); Mockito.when( policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)) .thenReturn(new SubscriptionPolicy(GOLD_TIER)); Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER)); Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER)); APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO); Mockito.when(apiDAO.getEndpoint(globalEndpoint.getId())).thenReturn(globalEndpoint); Mockito.when(apiDAO.getEndpointByName(apiEndpoint.getName())).thenReturn(null); Mockito.when(apiDAO.getEndpointByName(resourceEndpoint.getName())).thenReturn(null); Mockito.when(apiDAO.isAPINameExists(apiBuilder.getName(), USER)).thenReturn(false); apiPublisher.addAPI(apiBuilder); Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build()); Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(apiEndpoint.getName()); Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(resourceEndpoint.getName()); }
From source file:com.evolveum.midpoint.model.impl.lens.projector.focus.InboundProcessor.java
private <F extends FocusType, V extends PrismValue, D extends ItemDefinition> void collectMappingsForTargets( final LensContext<F> context, LensProjectionContext projectionCtx, MappingType inboundMappingType, QName accountAttributeName, Item<V, D> oldAccountProperty, ItemDelta<V, D> attributeAPrioriDelta, PrismObject<F> focusNew, VariableProducer<V> variableProducer, Map<ItemDefinition, List<MappingImpl<?, ?>>> mappingsToTarget, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, ConfigurationException, SecurityViolationException, CommunicationException { if (oldAccountProperty != null && oldAccountProperty.hasRaw()) { throw new SystemException("Property " + oldAccountProperty + " has raw parsing state, such property cannot be used in inbound expressions"); }//from w w w . ja va 2 s .co m ResourceType resource = projectionCtx.getResource(); MappingImpl.Builder<V, D> builder = mappingFactory.createMappingBuilder(inboundMappingType, "inbound expression for " + accountAttributeName + " in " + resource); if (!builder.isApplicableToChannel(context.getChannel())) { return; } PrismObject<ShadowType> accountNew = projectionCtx.getObjectNew(); ExpressionVariables variables = new ExpressionVariables(); variables.addVariableDefinition(ExpressionConstants.VAR_USER, focusNew); variables.addVariableDefinition(ExpressionConstants.VAR_FOCUS, focusNew); variables.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, accountNew); variables.addVariableDefinition(ExpressionConstants.VAR_SHADOW, accountNew); variables.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, resource); variables.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, context.getSystemConfiguration()); variables.addVariableDefinition(ExpressionConstants.VAR_OPERATION, context.getFocusContext().getOperation().getValue()); Source<V, D> defaultSource = new Source<>(oldAccountProperty, attributeAPrioriDelta, null, ExpressionConstants.VAR_INPUT); defaultSource.recompute(); builder = builder.defaultSource(defaultSource).targetContext(LensUtil.getFocusDefinition(context)) .variables(variables).variableResolver(variableProducer) .valuePolicyResolver(createStringPolicyResolver(context, task, result)) .originType(OriginType.INBOUND).originObject(resource); if (!context.getFocusContext().isDelete()) { Collection<V> originalValues = ExpressionUtil.computeTargetValues(inboundMappingType.getTarget(), focusNew, variables, mappingFactory.getObjectResolver(), "resolving range", task, result); builder.originalTargetValues(originalValues); } MappingImpl<V, D> mapping = builder.build(); if (checkWeakSkip(mapping, focusNew)) { LOGGER.trace("Skipping because of mapping is weak and focus property has already a value"); return; } ItemPath targetFocusItemPath = mapping.getOutputPath(); if (ItemPath.isNullOrEmpty(targetFocusItemPath)) { throw new ConfigurationException("Empty target path in " + mapping.getContextDescription()); } boolean isAssignment = new ItemPath(FocusType.F_ASSIGNMENT).equivalent(targetFocusItemPath); Item targetFocusItem = null; if (focusNew != null) { targetFocusItem = focusNew.findItem(targetFocusItemPath); } PrismObjectDefinition<F> focusDefinition = context.getFocusContext().getObjectDefinition(); ItemDefinition targetItemDef = focusDefinition.findItemDefinition(targetFocusItemPath); if (targetItemDef == null) { throw new SchemaException("No definition for focus property " + targetFocusItemPath + ", cannot process inbound expression in " + resource); } List<MappingImpl<V, D>> existingMapping = (List) mappingsToTarget.get(targetItemDef); if (CollectionUtils.isEmpty(existingMapping)) { mappingsToTarget.put(targetItemDef, Arrays.asList(mapping)); } else { List<MappingImpl<V, D>> clone = new ArrayList<>(existingMapping); clone.add(mapping); mappingsToTarget.replace(targetItemDef, (List) clone); } }
From source file:sg.ncl.MainController.java
@RequestMapping("/admin/data") public String adminDataManagement(Model model, HttpSession session) { if (!validateIfAdmin(session)) { return NO_PERMISSION_PAGE; }/*from w w w. j a v a 2 s. c o m*/ //------------------------------------ // get list of datasets //------------------------------------ HttpEntity<String> request = createHttpEntityHeaderOnly(); ResponseEntity response = restTemplate.exchange(properties.getData(), HttpMethod.GET, request, String.class); String responseBody = response.getBody().toString(); List<Dataset> datasetsList = new ArrayList<>(); JSONArray dataJsonArray = new JSONArray(responseBody); for (int i = 0; i < dataJsonArray.length(); i++) { JSONObject dataInfoObject = dataJsonArray.getJSONObject(i); Dataset dataset = extractDataInfo(dataInfoObject.toString()); datasetsList.add(dataset); } response = restTemplate.exchange(properties.getDownloadStat(), HttpMethod.GET, request, String.class); responseBody = response.getBody().toString(); Map<Integer, Long> dataDownloadStats = new HashMap<>(); JSONArray statJsonArray1 = new JSONArray(responseBody); for (int i = 0; i < statJsonArray1.length(); i++) { JSONObject statInfoObject = statJsonArray1.getJSONObject(i); dataDownloadStats.put(statInfoObject.getInt(DATA_ID), statInfoObject.getLong(COUNT)); } response = restTemplate.exchange(properties.getPublicDownloadStat(), HttpMethod.GET, request, String.class); responseBody = response.getBody().toString(); JSONArray statJsonArray2 = new JSONArray(responseBody); for (int i = 0; i < statJsonArray2.length(); i++) { JSONObject statInfoObject = statJsonArray2.getJSONObject(i); int key = statInfoObject.getInt(DATA_ID); if (dataDownloadStats.containsKey(key)) { Long count = dataDownloadStats.get(key) + statInfoObject.getLong(COUNT); dataDownloadStats.replace(key, count); } else { dataDownloadStats.put(statInfoObject.getInt(DATA_ID), statInfoObject.getLong(COUNT)); } } model.addAttribute("dataList", datasetsList); model.addAttribute("downloadStats", dataDownloadStats); return "data_dashboard"; }