@Test void loadDuplicateNameService() { ServiceLoader loader = new ServiceLoader(); Bundle bundle = new Bundle(); Folder folder = new Folder(); folder.setId(TEST_FOLDER); folder.setName(TEST_FOLDER); folder.setPath(TEST_FOLDER); bundle.getFolders().put(TEST_FOLDER, folder); System.setProperty(ServiceAndPolicyLoaderUtil.HANDLE_DUPLICATE_NAMES, "true"); loader.load(bundle, createServiceXml(DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), true, false, false, false, false)); loader.load(bundle, createServiceXml(DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), true, true, false, false, false)); System.clearProperty(ServiceAndPolicyLoaderUtil.HANDLE_DUPLICATE_NAMES); assertFalse(bundle.getServices().isEmpty()); assertEquals(2, bundle.getServices().size()); Service service = bundle.getServices().get(TEST_FOLDER + "/service"); assertNotNull(service); Service duplicateService = bundle.getServices().get(TEST_FOLDER + "/service (2)"); assertNotNull(duplicateService); assertEquals("service", service.getName()); assertEquals("id", service.getId()); assertEquals("service (2)", duplicateService.getName()); assertEquals("soapId", duplicateService.getId()); assertTrue(service.getHttpMethods().containsAll(Arrays.asList("GET", "POST", "PUT", "DELETE"))); assertEquals(service.getParentFolder(), duplicateService.getParentFolder()); }
@Override public void load(Bundle bundle, Element element) { final Element service = getSingleChildElement(getSingleChildElement(element, RESOURCE), SERVICE); final Element serviceDetails = getSingleChildElement(service, SERVICE_DETAIL); final String id = serviceDetails.getAttribute(ATTRIBUTE_ID); final String folderId = serviceDetails.getAttribute(ATTRIBUTE_FOLDER_ID); Element nameElement = getSingleChildElement(serviceDetails, NAME); final String name = CharacterBlacklistUtil.filterAndReplace(nameElement.getTextContent()); Element servicePropertiesElement = getSingleChildElement(serviceDetails, PROPERTIES); Map<String, Object> allProperties = BuilderUtils.mapPropertiesElements(servicePropertiesElement, PROPERTIES); Map<String, Object> properties = new HashMap<>(); Service serviceEntity = new Service(); Folder parentFolder = getFolder(bundle, folderId); serviceEntity.setName(name); serviceEntity.setId(id); serviceEntity.setPath(getPath(parentFolder, name)); serviceEntity.setParentFolder(parentFolder); serviceEntity.setServiceDetailsElement(serviceDetails); populateServiceEntity(service, serviceEntity, allProperties, properties); boolean isSoapService = isNotBlank(serviceEntity.getSoapVersion()); Element serviceMappingsElement = getSingleChildElement(serviceEntity.getServiceDetailsElement(), SERVICE_MAPPINGS); Element httpMappingElement = getSingleChildElement(serviceMappingsElement, HTTP_MAPPING); if(isSoapService) { try { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } catch (BundleLoadException e) { } } else { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } Element verbsElement = getSingleChildElement(httpMappingElement, VERBS); NodeList verbs = verbsElement.getElementsByTagName(VERB); Set<String> httpMethods = new HashSet<>(); for (Node verb : nodeList(verbs)) { httpMethods.add(verb.getTextContent()); } serviceEntity.setHttpMethods(httpMethods); serviceEntity.setProperties(properties); Map<String, Service> bundleService = bundle.getServices(); if (bundleService.containsKey(serviceEntity.getPath())) { String duplicatePathName = handleDuplicatePathName(bundleService, serviceEntity); serviceEntity.setName(duplicatePathName.substring(duplicatePathName.lastIndexOf('/') + 1)); serviceEntity.setPath(duplicatePathName); } bundleService.put(serviceEntity.getPath(), serviceEntity); }
ServiceLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element service = getSingleChildElement(getSingleChildElement(element, RESOURCE), SERVICE); final Element serviceDetails = getSingleChildElement(service, SERVICE_DETAIL); final String id = serviceDetails.getAttribute(ATTRIBUTE_ID); final String folderId = serviceDetails.getAttribute(ATTRIBUTE_FOLDER_ID); Element nameElement = getSingleChildElement(serviceDetails, NAME); final String name = CharacterBlacklistUtil.filterAndReplace(nameElement.getTextContent()); Element servicePropertiesElement = getSingleChildElement(serviceDetails, PROPERTIES); Map<String, Object> allProperties = BuilderUtils.mapPropertiesElements(servicePropertiesElement, PROPERTIES); Map<String, Object> properties = new HashMap<>(); Service serviceEntity = new Service(); Folder parentFolder = getFolder(bundle, folderId); serviceEntity.setName(name); serviceEntity.setId(id); serviceEntity.setPath(getPath(parentFolder, name)); serviceEntity.setParentFolder(parentFolder); serviceEntity.setServiceDetailsElement(serviceDetails); populateServiceEntity(service, serviceEntity, allProperties, properties); boolean isSoapService = isNotBlank(serviceEntity.getSoapVersion()); Element serviceMappingsElement = getSingleChildElement(serviceEntity.getServiceDetailsElement(), SERVICE_MAPPINGS); Element httpMappingElement = getSingleChildElement(serviceMappingsElement, HTTP_MAPPING); if(isSoapService) { try { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } catch (BundleLoadException e) { } } else { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } Element verbsElement = getSingleChildElement(httpMappingElement, VERBS); NodeList verbs = verbsElement.getElementsByTagName(VERB); Set<String> httpMethods = new HashSet<>(); for (Node verb : nodeList(verbs)) { httpMethods.add(verb.getTextContent()); } serviceEntity.setHttpMethods(httpMethods); serviceEntity.setProperties(properties); Map<String, Service> bundleService = bundle.getServices(); if (bundleService.containsKey(serviceEntity.getPath())) { String duplicatePathName = handleDuplicatePathName(bundleService, serviceEntity); serviceEntity.setName(duplicatePathName.substring(duplicatePathName.lastIndexOf('/') + 1)); serviceEntity.setPath(duplicatePathName); } bundleService.put(serviceEntity.getPath(), serviceEntity); } }
ServiceLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element service = getSingleChildElement(getSingleChildElement(element, RESOURCE), SERVICE); final Element serviceDetails = getSingleChildElement(service, SERVICE_DETAIL); final String id = serviceDetails.getAttribute(ATTRIBUTE_ID); final String folderId = serviceDetails.getAttribute(ATTRIBUTE_FOLDER_ID); Element nameElement = getSingleChildElement(serviceDetails, NAME); final String name = CharacterBlacklistUtil.filterAndReplace(nameElement.getTextContent()); Element servicePropertiesElement = getSingleChildElement(serviceDetails, PROPERTIES); Map<String, Object> allProperties = BuilderUtils.mapPropertiesElements(servicePropertiesElement, PROPERTIES); Map<String, Object> properties = new HashMap<>(); Service serviceEntity = new Service(); Folder parentFolder = getFolder(bundle, folderId); serviceEntity.setName(name); serviceEntity.setId(id); serviceEntity.setPath(getPath(parentFolder, name)); serviceEntity.setParentFolder(parentFolder); serviceEntity.setServiceDetailsElement(serviceDetails); populateServiceEntity(service, serviceEntity, allProperties, properties); boolean isSoapService = isNotBlank(serviceEntity.getSoapVersion()); Element serviceMappingsElement = getSingleChildElement(serviceEntity.getServiceDetailsElement(), SERVICE_MAPPINGS); Element httpMappingElement = getSingleChildElement(serviceMappingsElement, HTTP_MAPPING); if(isSoapService) { try { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } catch (BundleLoadException e) { } } else { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } Element verbsElement = getSingleChildElement(httpMappingElement, VERBS); NodeList verbs = verbsElement.getElementsByTagName(VERB); Set<String> httpMethods = new HashSet<>(); for (Node verb : nodeList(verbs)) { httpMethods.add(verb.getTextContent()); } serviceEntity.setHttpMethods(httpMethods); serviceEntity.setProperties(properties); Map<String, Service> bundleService = bundle.getServices(); if (bundleService.containsKey(serviceEntity.getPath())) { String duplicatePathName = handleDuplicatePathName(bundleService, serviceEntity); serviceEntity.setName(duplicatePathName.substring(duplicatePathName.lastIndexOf('/') + 1)); serviceEntity.setPath(duplicatePathName); } bundleService.put(serviceEntity.getPath(), serviceEntity); }  }
ServiceLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element service = getSingleChildElement(getSingleChildElement(element, RESOURCE), SERVICE); final Element serviceDetails = getSingleChildElement(service, SERVICE_DETAIL); final String id = serviceDetails.getAttribute(ATTRIBUTE_ID); final String folderId = serviceDetails.getAttribute(ATTRIBUTE_FOLDER_ID); Element nameElement = getSingleChildElement(serviceDetails, NAME); final String name = CharacterBlacklistUtil.filterAndReplace(nameElement.getTextContent()); Element servicePropertiesElement = getSingleChildElement(serviceDetails, PROPERTIES); Map<String, Object> allProperties = BuilderUtils.mapPropertiesElements(servicePropertiesElement, PROPERTIES); Map<String, Object> properties = new HashMap<>(); Service serviceEntity = new Service(); Folder parentFolder = getFolder(bundle, folderId); serviceEntity.setName(name); serviceEntity.setId(id); serviceEntity.setPath(getPath(parentFolder, name)); serviceEntity.setParentFolder(parentFolder); serviceEntity.setServiceDetailsElement(serviceDetails); populateServiceEntity(service, serviceEntity, allProperties, properties); boolean isSoapService = isNotBlank(serviceEntity.getSoapVersion()); Element serviceMappingsElement = getSingleChildElement(serviceEntity.getServiceDetailsElement(), SERVICE_MAPPINGS); Element httpMappingElement = getSingleChildElement(serviceMappingsElement, HTTP_MAPPING); if(isSoapService) { try { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } catch (BundleLoadException e) { } } else { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } Element verbsElement = getSingleChildElement(httpMappingElement, VERBS); NodeList verbs = verbsElement.getElementsByTagName(VERB); Set<String> httpMethods = new HashSet<>(); for (Node verb : nodeList(verbs)) { httpMethods.add(verb.getTextContent()); } serviceEntity.setHttpMethods(httpMethods); serviceEntity.setProperties(properties); Map<String, Service> bundleService = bundle.getServices(); if (bundleService.containsKey(serviceEntity.getPath())) { String duplicatePathName = handleDuplicatePathName(bundleService, serviceEntity); serviceEntity.setName(duplicatePathName.substring(duplicatePathName.lastIndexOf('/') + 1)); serviceEntity.setPath(duplicatePathName); } bundleService.put(serviceEntity.getPath(), serviceEntity); }  @Override void load(Bundle bundle, Element element); @Override String getEntityType(); }
ServiceLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element service = getSingleChildElement(getSingleChildElement(element, RESOURCE), SERVICE); final Element serviceDetails = getSingleChildElement(service, SERVICE_DETAIL); final String id = serviceDetails.getAttribute(ATTRIBUTE_ID); final String folderId = serviceDetails.getAttribute(ATTRIBUTE_FOLDER_ID); Element nameElement = getSingleChildElement(serviceDetails, NAME); final String name = CharacterBlacklistUtil.filterAndReplace(nameElement.getTextContent()); Element servicePropertiesElement = getSingleChildElement(serviceDetails, PROPERTIES); Map<String, Object> allProperties = BuilderUtils.mapPropertiesElements(servicePropertiesElement, PROPERTIES); Map<String, Object> properties = new HashMap<>(); Service serviceEntity = new Service(); Folder parentFolder = getFolder(bundle, folderId); serviceEntity.setName(name); serviceEntity.setId(id); serviceEntity.setPath(getPath(parentFolder, name)); serviceEntity.setParentFolder(parentFolder); serviceEntity.setServiceDetailsElement(serviceDetails); populateServiceEntity(service, serviceEntity, allProperties, properties); boolean isSoapService = isNotBlank(serviceEntity.getSoapVersion()); Element serviceMappingsElement = getSingleChildElement(serviceEntity.getServiceDetailsElement(), SERVICE_MAPPINGS); Element httpMappingElement = getSingleChildElement(serviceMappingsElement, HTTP_MAPPING); if(isSoapService) { try { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } catch (BundleLoadException e) { } } else { Element urlPatternElement = getSingleChildElement(httpMappingElement, URL_PATTERN); serviceEntity.setUrl(urlPatternElement.getTextContent()); } Element verbsElement = getSingleChildElement(httpMappingElement, VERBS); NodeList verbs = verbsElement.getElementsByTagName(VERB); Set<String> httpMethods = new HashSet<>(); for (Node verb : nodeList(verbs)) { httpMethods.add(verb.getTextContent()); } serviceEntity.setHttpMethods(httpMethods); serviceEntity.setProperties(properties); Map<String, Service> bundleService = bundle.getServices(); if (bundleService.containsKey(serviceEntity.getPath())) { String duplicatePathName = handleDuplicatePathName(bundleService, serviceEntity); serviceEntity.setName(duplicatePathName.substring(duplicatePathName.lastIndexOf('/') + 1)); serviceEntity.setPath(duplicatePathName); } bundleService.put(serviceEntity.getPath(), serviceEntity); }  @Override void load(Bundle bundle, Element element); @Override String getEntityType();  }