@Override public void loadAS5Data(MigrationContext ctx) throws LoadMigrationException { // TBC: Maybe use FileUtils and list all files with that name? File file = Utils.createPath( super.getGlobalConfig().getAS5Config().getDir(), "server", super.getGlobalConfig().getAS5Config().getProfileName(), "deploy", "jbossweb.sar", "server.xml"); if (!file.canRead()) throw new LoadMigrationException( "Cannot find/open file: " + file.getAbsolutePath(), new FileNotFoundException()); try { Unmarshaller unmarshaller = JAXBContext.newInstance(ServerAS5Bean.class).createUnmarshaller(); ServerAS5Bean serverAS5 = (ServerAS5Bean) unmarshaller.unmarshal(file); MigrationData mData = new MigrationData(); for (ServiceBean s : serverAS5.getServices()) { mData.getConfigFragments().add(s.getEngine()); mData.getConfigFragments().addAll(s.getConnectorAS5s()); } ctx.getMigrationData().put(ServerMigrator.class, mData); } catch (JAXBException e) { throw new LoadMigrationException("Failed parsing logging config file: " + file.getPath(), e); } }
private Map<String, Map<String, ServiceBean>> buildServiceVersionHierarchy( ServiceBean[] serviceBeans) { Map<String, Map<String, ServiceBean>> hierarchy = new LinkedHashMap<String, Map<String, ServiceBean>>(); if (serviceBeans == null) { return hierarchy; } for (ServiceBean serviceBean : serviceBeans) { if (serviceBean != null) { String path = RegistryUtils.getParentPath(serviceBean.getPath()); String version = RegistryUtils.getResourceName(path); if (!version.replace("-SNAPSHOT", "").matches("^\\d+[.]\\d+[.]\\d+$")) { version = "SNAPSHOT"; serviceBean.setPath(serviceBean.getPath()); } else { serviceBean.setPath(RegistryUtils.getParentPath(path)); } Map<String, ServiceBean> versionMap; if (hierarchy.containsKey(serviceBean.getQName())) { versionMap = hierarchy.get(serviceBean.getQName()); } else { versionMap = new LinkedHashMap<String, ServiceBean>(); hierarchy.put(serviceBean.getQName(), versionMap); } versionMap.put(version, serviceBean); } } return hierarchy; }
private String buildImpactJSONTree(ServiceBean[] serviceBeans) { StringBuilder builder = new StringBuilder(); builder.append( "{ " + buildJSONforNoEdgeAttributes(UUID.randomUUID().toString(), "Services", null) + appendChildrenJSON()); int count = 0; Map<String, Map<String, ServiceBean>> serviceVersionHierarchy = buildServiceVersionHierarchy(serviceBeans); for (Map.Entry<String, Map<String, ServiceBean>> e : serviceVersionHierarchy.entrySet()) { Map<String, ServiceBean> versionMap = e.getValue(); count++; int countInner = 0; for (Map.Entry<String, ServiceBean> versionEntry : versionMap.entrySet()) { countInner++; String key = versionEntry.getKey(); ServiceBean serviceBean = versionEntry.getValue(); if (countInner == 1) { builder.append( "{" + buildJSONforNoEdgeAttributes( serviceBean.getId(), serviceBean.getQName(), getResourceURL(serviceBean.getPath())) + appendChildrenJSON() + "\n"); } String uuid = UUIDGenerator.generateUUID(); String servicePath; if (key.equals("SNAPSHOT")) { servicePath = serviceBean.getPath(); } else { String name = serviceBean.getQName(); name = name.substring(0, name.lastIndexOf("-") - 1).trim(); servicePath = serviceBean.getPath() + "/" + key + "/" + name; } builder.append( "{" + buildOpenJSONWithEdges( uuid, key, serviceBean.getId(), "", getResourceURL(servicePath)) + appendChildrenJSON() + "\n"); PolicyBean[] policyBeans = serviceBean.getPolicyBeans(); WSDLBean[] wsdlBeans = serviceBean.getWsdlBeans(); SchemaBean[] schemaBeans = serviceBean.getSchemaBeans(); if (policyBeans != null) { for (int j = 0; j < policyBeans.length; j++) { if (policyBeans[j] != null) { builder.append( "{" + buildJSONWithEdgeNoChildren( policyBeans[j].getId(), policyBeans[j].getQName(), uuid, "Policy", getResourceURL(policyBeans[j].getPath())) + "} \n"); if (j != (policyBeans.length - 1)) builder.append(","); builder.append("\n"); } } builder.append(buildCloseJSONForNameandChildren()); if (wsdlBeans != null || schemaBeans != null) { builder.append(", \n"); } } if (wsdlBeans != null) { for (int j = 0; j < wsdlBeans.length; j++) { if (wsdlBeans[j] != null) { builder.append( "{" + buildOpenJSONWithEdges( wsdlBeans[j].getId(), wsdlBeans[j].getQName(), uuid, "WSDL", getResourceURL(wsdlBeans[j].getPath())) + appendChildrenJSON() + " \n"); SchemaBean[] attachedSchemas = wsdlBeans[j].getAttachedSchemas(); if (attachedSchemas != null) { for (int k = 0; k < attachedSchemas.length; k++) { if (attachedSchemas[k] != null) { builder.append( "{" + buildJSONWithEdgeNoChildren( attachedSchemas[k].getId(), attachedSchemas[k].getQName(), wsdlBeans[j].getId(), "Schema", getResourceURL(attachedSchemas[k].getPath())) + "} \n"); if (j != (attachedSchemas.length - 1)) { builder.append(","); } builder.append("\n"); } } } builder.append("] \n"); builder.append("} \n"); if (j != (wsdlBeans.length - 1)) builder.append(","); builder.append("\n"); } } if (schemaBeans != null) { builder.append(", \n"); } } if (schemaBeans != null) { for (int j = 0; j < schemaBeans.length; j++) { if (schemaBeans[j] != null) { builder.append( "{" + buildJSONWithEdgeNoChildren( schemaBeans[j].getId(), schemaBeans[j].getQName(), uuid, "Schema", getResourceURL(schemaBeans[j].getPath())) + "} \n"); if (j != (schemaBeans.length - 1)) builder.append(","); builder.append("\n"); } } } builder.append("] \n"); builder.append("} \n"); if (countInner != (versionMap.size())) { builder.append(", "); } builder.append("\n"); } builder.append("] \n"); builder.append("} \n"); if (count != (serviceVersionHierarchy.size())) { builder.append(", "); } builder.append("\n"); } builder.append("] \n"); builder.append("} \n"); return builder.toString(); }