/** * Loads and parses the provided XML file. This will quietly fail (not throwing an {@link Exception}) and return * null if it is unable to parse the provided {@link XmlFileModel}. A {@link ClassificationModel} will be created to * indicate that this file failed to parse. * * @return Returns either the parsed {@link Document} or null if the {@link Document} could not be parsed */ public Document loadDocumentQuiet(GraphRewrite event, EvaluationContext context, XmlFileModel model) { try { return loadDocument(event, context, model); } catch(Exception ex) { return null; } }
public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { Document doc = new XmlFileService(event.getGraphContext()).loadDocumentQuiet(payload); if (doc == null) { // failed to parse, skip return; } extractMetadata(event.getGraphContext(), payload, doc); }
/** * Gets the path used for the results of XSLT Transforms. */ public Path getTransformedXSLTPath(FileModel payload) { ReportService reportService = new ReportService(getGraphContext()); Path outputPath = reportService.getReportDirectory(); outputPath = outputPath.resolve(this.getRelativeTransformedXSLTPath(payload)); if (!Files.isDirectory(outputPath)) { try { Files.createDirectories(outputPath); } catch (IOException e) { throw new WindupException("Failed to create output directory at: " + outputPath + " due to: " + e.getMessage(), e); } } return outputPath; }
public void perform(GraphRewrite event, EvaluationContext context, NamespaceMetaModel payload) { for (XmlFileModel xml : payload.getXmlResources()) { if (!StringUtils.equals(xml.getRootTagName(), "persistence")) continue; try { Document doc = new XmlFileService(event.getGraphContext()).loadDocument(event, context, xml); extractMetadata(event.getGraphContext(), xml, doc); } catch (Exception ex) { xml.setParseError("Failed to parse JPA configuration: " + ex.getMessage()); } } }
public Iterator<DoctypeMetaModel> findByPublicIdAndSystemId(String publicId, String systemId) { FramedGraphQuery query = getGraphContext().getFramed().query(); if (StringUtils.isNotBlank(publicId)) { query.has(DoctypeMetaModel.PROPERTY_PUBLIC_ID, publicId); } if (StringUtils.isNotBlank(systemId)) { query.has(DoctypeMetaModel.PROPERTY_SYSTEM_ID, systemId); } return query.vertices(DoctypeMetaModel.class).iterator(); } }
public NamespaceMetaModel createNamespaceSchemaLocation(String namespaceURI, String schemaLocation) { Iterable<? extends NamespaceMetaModel> results = getGraphContext().getQuery(NamespaceMetaModel.class) .traverse(g -> g.has("namespaceURI", namespaceURI).has("schemaLocation", schemaLocation)) .toList(NamespaceMetaModel.class); if (results.iterator().hasNext()) { return results.iterator().next(); } // otherwise, create it. NamespaceMetaModel meta = getGraphContext().getFramed().addFramedVertex(NamespaceMetaModel.class); meta.setSchemaLocation(schemaLocation); meta.setURI(namespaceURI); return meta; }
/** * Gets the path used for the results of XSLT Transforms. */ public Path getTransformedXSLTPath() { ReportService reportService = new ReportService(getGraphContext()); Path outputPath = Paths.get(reportService.getReportDirectory()).resolve(TRANSFORMEDXML_DIR_NAME); if (!Files.isDirectory(outputPath)) { try { Files.createDirectories(outputPath); } catch (IOException e) { throw new WindupException("Failed to create output directory at: " + outputPath + " due to: " + e.getMessage(), e); } } return outputPath; } }
ClassificationService classificationService = new ClassificationService(getGraphContext()); try (InputStream is = model.asInputStream())
public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { XmlFileService xmlFileService = new XmlFileService(event.getGraphContext()); Document doc = xmlFileService.loadDocumentQuiet(payload); if (doc != null && isWebXml(payload, doc)) { addWebXmlMetadata(event.getGraphContext(), payload, doc); } }
public void perform(GraphRewrite event, EvaluationContext context, NamespaceMetaModel payload) { for (XmlFileModel xml : payload.getXmlResources()) { if (!StringUtils.equals(xml.getRootTagName(), "persistence")) continue; try { Document doc = new XmlFileService(event.getGraphContext()).loadDocument(event, context, xml); extractMetadata(event.getGraphContext(), xml, doc); } catch (Exception ex) { xml.setParseError("Failed to parse JPA configuration: " + ex.getMessage()); } } }
@SuppressWarnings("unchecked") public Iterator<DoctypeMetaModel> findByPublicIdAndSystemId(String publicId, String systemId) { Traversable<?, ?> query = getGraphContext().getFramed().traverse(g -> g.V()); if (StringUtils.isNotBlank(publicId)) { query.traverse(g -> g.has(DoctypeMetaModel.PROPERTY_PUBLIC_ID, publicId)); } if (StringUtils.isNotBlank(systemId)) { query.traverse(g -> g.has(DoctypeMetaModel.PROPERTY_SYSTEM_ID, systemId)); } return (Iterator<DoctypeMetaModel>)query.toList(DoctypeMetaModel.class).iterator(); } }
public NamespaceMetaModel createNamespaceSchemaLocation(String namespaceURI, String schemaLocation) { Iterable<NamespaceMetaModel> results = getGraphContext().getQuery().type(NamespaceMetaModel.class) .has("namespaceURI", namespaceURI).has("schemaLocation", schemaLocation) .vertices(NamespaceMetaModel.class); for (NamespaceMetaModel result : results) { return result; } // otherwise, create it. NamespaceMetaModel meta = getGraphContext().getFramed().addVertex(null, NamespaceMetaModel.class); meta.setSchemaLocation(schemaLocation); meta.setURI(namespaceURI); return meta; }
public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { XmlFileService xmlFileService = new XmlFileService(event.getGraphContext()); Document doc = xmlFileService.loadDocumentQuiet(event, context, payload); if (doc != null && isWebXml(payload, doc)) { addWebXmlMetadata(event, context, event.getGraphContext(), payload, doc); } }
public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { XmlFileService xmlFileService = new XmlFileService(event.getGraphContext()); Document doc = xmlFileService.loadDocumentQuiet(event, context, payload); if (doc != null && isWebXml(payload, doc)) { addWebXmlMetadata(event, context, event.getGraphContext(), payload, doc); } }
private void createDataSourceModel(GraphRewrite event, EvaluationContext context, XmlFileModel xmlFileModel) { GraphContext graphContext = event.getGraphContext(); DataSourceService dataSourceService = new DataSourceService(graphContext); // check the root XML node. Set<ProjectModel> applications = ProjectTraversalCache.getApplicationsForProject(event.getGraphContext(), xmlFileModel.getProjectModel()); Document doc = new XmlFileService(graphContext).loadDocumentQuiet(event, context, xmlFileModel); for (String tagName : Arrays.asList(SINGLE_DATASOURCE_TAG, SINGLE_DATASOURCE_XA_TAG)) { for (Element element : $(doc).find(tagName).get()) { DataSourceModel dataSourceModel = dataSourceService.create(); boolean isXa = tagName.equals(SINGLE_DATASOURCE_XA_TAG); dataSourceModel.setName(element.getAttribute("pool-name")); dataSourceModel.setJndiLocation(element.getAttribute("jndi-name")); dataSourceModel.setApplications(applications); dataSourceModel.setXa(isXa); } } } }
private void createDataSourceModel(GraphRewrite event, EvaluationContext context, XmlFileModel xmlFileModel) { GraphContext graphContext = event.getGraphContext(); DataSourceService dataSourceService = new DataSourceService(graphContext); // check the root XML node. Set<ProjectModel> applications = ProjectTraversalCache.getApplicationsForProject(event.getGraphContext(), xmlFileModel.getProjectModel()); Document doc = new XmlFileService(graphContext).loadDocumentQuiet(event, context, xmlFileModel); for (String tagName : Arrays.asList(SINGLE_DATASOURCE_TAG, SINGLE_DATASOURCE_XA_TAG)) { for (Element element : $(doc).find(tagName).get()) { DataSourceModel dataSourceModel = dataSourceService.create(); boolean isXa = tagName.equals(SINGLE_DATASOURCE_XA_TAG); dataSourceModel.setName(element.getAttribute("pool-name")); dataSourceModel.setJndiLocation(element.getAttribute("jndi-name")); dataSourceModel.setApplications(applications); dataSourceModel.setXa(isXa); } } } }
private void createHibernateConfigurationModel(GraphContext graphContext, XmlFileModel xmlFileModel, String versionInformation) { HibernateConfigurationFileService hibernateConfigurationFileService = new HibernateConfigurationFileService(graphContext); GraphService<HibernateSessionFactoryModel> hibernateSessionFactoryService = new GraphService<>(graphContext, HibernateSessionFactoryModel.class); TechnologyTagService technologyTagService = new TechnologyTagService(graphContext); // check the root XML node. HibernateConfigurationFileModel hibernateConfigurationModel = hibernateConfigurationFileService.addTypeToModel(xmlFileModel); technologyTagService.addTagToFileModel(hibernateConfigurationModel, TECH_TAG, TECH_TAG_LEVEL); if (StringUtils.isNotBlank(versionInformation)) { hibernateConfigurationModel.setSpecificationVersion(versionInformation); } Document doc = new XmlFileService(graphContext).loadDocumentQuiet(xmlFileModel); for (Element element : $(doc).find("session-factory").get()) { HibernateSessionFactoryModel sessionFactoryModel = hibernateSessionFactoryService.create(); hibernateConfigurationModel.addHibernateSessionFactory(sessionFactoryModel); Map<String, String> sessionFactoryProperties = new HashMap<>(); for (Element propElement : $(element).find("property")) { String propKey = $(propElement).attr("name"); String propValue = $(propElement).text().trim(); sessionFactoryProperties.put(propKey, propValue); } sessionFactoryModel.setSessionFactoryProperties(sessionFactoryProperties); } }
@Override public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { EnvironmentReferenceService envRefService = new EnvironmentReferenceService(event.getGraphContext()); JNDIResourceService jndiResourceService = new JNDIResourceService(event.getGraphContext()); XmlFileService xmlFileService = new XmlFileService(event.getGraphContext()); TechnologyTagService technologyTagService = new TechnologyTagService(event.getGraphContext()); Document doc = xmlFileService.loadDocumentQuiet(event, context, payload); VendorSpecificationExtensionService vendorSpecificationService = new VendorSpecificationExtensionService(event.getGraphContext()); // mark as vendor extension; create reference to web.xml vendorSpecificationService.associateAsVendorExtension(payload, "web.xml"); technologyTagService.addTagToFileModel(payload, "WebLogic Web XML", TechnologyTagLevel.IMPORTANT); Set<ProjectModel> applications = ProjectTraversalCache.getApplicationsForProject(event.getGraphContext(), payload.getProjectModel()); for (Element resourceRef : $(doc).find("resource-description").get()) { String jndiLocation = $(resourceRef).child("jndi-name").text(); String resourceName = $(resourceRef).child("res-ref-name").text(); if (StringUtils.isNotBlank(jndiLocation)) { JNDIResourceModel resource = jndiResourceService.createUnique(applications, jndiLocation); LOG.info("JNDI: " + jndiLocation + " Resource: " + resourceName); // now, look up the resource by name, and associate the type which is resolved by DiscoverWebXmlRuleProvider for (EnvironmentReferenceModel ref : envRefService.findAllByProperty(EnvironmentReferenceModel.NAME, resourceName)) { envRefService.associateEnvironmentToJndi(resource, ref); } } } }
@Override public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { EnvironmentReferenceService envRefService = new EnvironmentReferenceService(event.getGraphContext()); JNDIResourceService jndiResourceService = new JNDIResourceService(event.getGraphContext()); XmlFileService xmlFileService = new XmlFileService(event.getGraphContext()); TechnologyTagService technologyTagService = new TechnologyTagService(event.getGraphContext()); // Classification done by websphere-xml-06000 - see WINDUPRULE-164 Document doc = xmlFileService.loadDocumentQuiet(event, context, payload); VendorSpecificationExtensionService vendorSpecificationService = new VendorSpecificationExtensionService(event.getGraphContext()); // mark as vendor extension; create reference to web.xml vendorSpecificationService.associateAsVendorExtension(payload, "web.xml"); TechnologyTagModel technologyTag = technologyTagService.addTagToFileModel(payload, "WebSphere Web XML", TechnologyTagLevel.IMPORTANT); Set<ProjectModel> applications = ProjectTraversalCache.getApplicationsForProject(event.getGraphContext(), payload.getProjectModel()); for (Element resourceRef : $(doc).find("resRefBindings").get()) { processBinding(envRefService, jndiResourceService, applications, resourceRef, "bindingResourceRef"); } for (Element resourceRef : $(doc).find("ejbRefBindings").get()) { processBinding(envRefService, jndiResourceService, applications, resourceRef, "bindingEjbRef"); } for (Element resourceRef : $(doc).find("messageDestinationRefBindings").get()) { processBinding(envRefService, jndiResourceService, applications, resourceRef, "bindingMessageDestinationRef"); } }
@Override public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { EnvironmentReferenceService envRefService = new EnvironmentReferenceService(event.getGraphContext()); JNDIResourceService jndiResourceService = new JNDIResourceService(event.getGraphContext()); XmlFileService xmlFileService = new XmlFileService(event.getGraphContext()); TechnologyTagService technologyTagService = new TechnologyTagService(event.getGraphContext()); // Classification done by websphere-xml-06000 - see WINDUPRULE-164 Document doc = xmlFileService.loadDocumentQuiet(event, context, payload); VendorSpecificationExtensionService vendorSpecificationService = new VendorSpecificationExtensionService(event.getGraphContext()); // mark as vendor extension; create reference to web.xml vendorSpecificationService.associateAsVendorExtension(payload, "web.xml"); TechnologyTagModel technologyTag = technologyTagService.addTagToFileModel(payload, "WebSphere Web XML", TechnologyTagLevel.IMPORTANT); Set<ProjectModel> applications = ProjectTraversalCache.getApplicationsForProject(event.getGraphContext(), payload.getProjectModel()); for (Element resourceRef : $(doc).find("resRefBindings").get()) { processBinding(envRefService, jndiResourceService, applications, resourceRef, "bindingResourceRef"); } for (Element resourceRef : $(doc).find("ejbRefBindings").get()) { processBinding(envRefService, jndiResourceService, applications, resourceRef, "bindingEjbRef"); } for (Element resourceRef : $(doc).find("messageDestinationRefBindings").get()) { processBinding(envRefService, jndiResourceService, applications, resourceRef, "bindingMessageDestinationRef"); } }