/** Associate a type with the given resource model. */ public void associateTypeJndiResource(JNDIResourceModel resource, String type) { if (type == null || resource == null) { return; } if (StringUtils.equals(type, "javax.sql.DataSource") && !(resource instanceof DataSourceModel)) { DataSourceModel ds = GraphService.addTypeToModel(this.getGraphContext(), resource, DataSourceModel.class); } else if (StringUtils.equals(type, "javax.jms.Queue") && !(resource instanceof JmsDestinationModel)) { JmsDestinationModel jms = GraphService.addTypeToModel(this.getGraphContext(), resource, JmsDestinationModel.class); jms.setDestinationType(JmsDestinationType.QUEUE); } else if (StringUtils.equals(type, "javax.jms.QueueConnectionFactory") && !(resource instanceof JmsConnectionFactoryModel)) { JmsConnectionFactoryModel jms = GraphService.addTypeToModel( this.getGraphContext(), resource, JmsConnectionFactoryModel.class); jms.setConnectionFactoryType(JmsDestinationType.QUEUE); } else if (StringUtils.equals(type, "javax.jms.Topic") && !(resource instanceof JmsDestinationModel)) { JmsDestinationModel jms = GraphService.addTypeToModel(this.getGraphContext(), resource, JmsDestinationModel.class); jms.setDestinationType(JmsDestinationType.TOPIC); } else if (StringUtils.equals(type, "javax.jms.TopicConnectionFactory") && !(resource instanceof JmsConnectionFactoryModel)) { JmsConnectionFactoryModel jms = GraphService.addTypeToModel( this.getGraphContext(), resource, JmsConnectionFactoryModel.class); jms.setConnectionFactoryType(JmsDestinationType.TOPIC); } }
/** Validate that the expected Properties Models were found */ private void validatePropertiesModels(GraphContext context) throws Exception { GraphService<PropertiesModel> service = new GraphService<>(context, PropertiesModel.class); int numberFound = 0; for (PropertiesModel model : service.findAll()) { numberFound++; Properties props = model.getProperties(); Assert.assertEquals("value1", props.getProperty("example1")); Assert.assertEquals("anothervalue", props.getProperty("anotherproperty")); Assert.assertEquals("1234", props.getProperty("timetaken")); } Assert.assertEquals(1, numberFound); }
@Test public void testNestedCondition() throws IOException { try (GraphContext context = factory.create()) { ProjectModel pm = context.getFramed().addVertex(null, ProjectModel.class); pm.setName("Main Project"); FileModel inputPath = context.getFramed().addVertex(null, FileModel.class); inputPath.setFilePath("src/test/resources/"); Path outputPath = Paths.get( FileUtils.getTempDirectory().toString(), "windup_" + UUID.randomUUID().toString()); FileUtils.deleteDirectory(outputPath.toFile()); Files.createDirectories(outputPath); inputPath.setProjectModel(pm); pm.setRootFileModel(inputPath); WindupConfiguration windupConfiguration = new WindupConfiguration() .setRuleProviderFilter( new NotPredicate( new RuleProviderPhasePredicate( MigrationRulesPhase.class, ReportGenerationPhase.class))) .setGraphContext(context); windupConfiguration.setInputPath(Paths.get(inputPath.getFilePath())); windupConfiguration.setOutputDirectory(outputPath); processor.execute(windupConfiguration); GraphService<ClassificationModel> classificationService = new GraphService<>(context, ClassificationModel.class); Assert.assertEquals(1, provider.getXmlFileMatches().size()); List<ClassificationModel> classifications = Iterators.asList(classificationService.findAll()); for (ClassificationModel model : classifications) { String classification = model.getClassification(); String classificationString = classification.toString(); Assert.assertEquals("Spring File", classificationString); } Assert.assertEquals(1, classifications.size()); Iterator<FileModel> iterator = classifications.get(0).getFileModels().iterator(); Assert.assertNotNull(iterator.next()); Assert.assertNotNull(iterator.next()); Assert.assertFalse(iterator.hasNext()); } }
public void perform(GraphRewrite event, EvaluationContext context, FileModel payload) { GraphService<PropertiesModel> service = getPropertiesService(event.getGraphContext()); PropertiesModel properties = service.create(); properties.setFileResource(payload); try (InputStream is = payload.asInputStream()) { Properties props = new Properties(); props.load(is); for (Object key : props.keySet()) { String property = StringUtils.trim(key.toString()); String propertyValue = StringUtils.trim(props.get(key).toString()); properties.setProperty(property, propertyValue); } } catch (IOException e) { throw new WindupException( "Failed to load properties file: " + payload.getFilePath() + " due to: " + e.getMessage()); } }
@Override public void perform(GraphRewrite event, EvaluationContext context, XmlFileModel payload) { EnvironmentReferenceService envRefService = new EnvironmentReferenceService(event.getGraphContext()); XmlFileService xmlFileService = new XmlFileService(event.getGraphContext()); JNDIResourceService jndiResourceService = new JNDIResourceService(event.getGraphContext()); JmsDestinationService jmsDestinationService = new JmsDestinationService(event.getGraphContext()); GraphService<EjbSessionBeanModel> ejbSessionBeanService = new GraphService<>(event.getGraphContext(), EjbSessionBeanModel.class); GraphService<EjbMessageDrivenModel> mdbService = new GraphService<>(event.getGraphContext(), EjbMessageDrivenModel.class); ClassificationService classificationService = new ClassificationService(event.getGraphContext()); ClassificationModel classification = classificationService.attachClassification( context, payload, "WebSphere EJB Binding", "WebSphere Enterprise Java Bean Binding XML Descriptor"); classification.setEffort(1); TechnologyTagService technologyTagService = new TechnologyTagService(event.getGraphContext()); technologyTagService.addTagToFileModel(payload, "WebSphere EJB", TechnologyTagLevel.IMPORTANT); Document doc = xmlFileService.loadDocumentQuiet(context, payload); if (doc == null) { return; } VendorSpecificationExtensionService vendorSpecificationService = new VendorSpecificationExtensionService(event.getGraphContext()); // mark as vendor extension; create reference to ejb-jar.xml vendorSpecificationService.associateAsVendorExtension(payload, "ejb-jar.xml"); Set<ProjectModel> applications = ProjectTraversalCache.getApplicationsForProject( event.getGraphContext(), payload.getProjectModel()); // register beans to JNDI for (Element resourceRef : $(doc).find("ejbBindings").get()) { String href = $(resourceRef).child("enterpriseBean").attr("href"); String resourceId = StringUtils.substringAfterLast(href, "ejb-jar.xml#"); String jndiLocation = $(resourceRef).attr("jndiName"); // determine type: String type = $(resourceRef).child("enterpriseBean").attr("type"); LOG.info("Type: " + type); if (StringUtils.isNotBlank(jndiLocation) && StringUtils.isNotBlank(resourceId)) { JNDIResourceModel resource = jndiResourceService.createUnique(applications, jndiLocation); LOG.info("JNDI Name: " + jndiLocation + " to Resource: " + resourceId); // now, look up the resource which is resolved by DiscoverEjbConfigurationXmlRuleProvider for (EnvironmentReferenceModel ref : envRefService.findAllByProperty(EnvironmentReferenceModel.REFERENCE_ID, resourceId)) { envRefService.associateEnvironmentToJndi(resource, ref); } for (EjbSessionBeanModel ejb : ejbSessionBeanService.findAllByProperty(EjbSessionBeanModel.EJB_ID, resourceId)) { ejb.setGlobalJndiReference(resource); } } } // register beans to JNDI 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"); } // Bind MDBs to Destinations for (Element resourceRef : $(doc).find("messageDestinationRefBindings").get()) { String jndiLocation = $(resourceRef).attr("jndiName"); // get the parent, as that has the reference to the MDB... String mdbRef = $(resourceRef).siblings("enterpriseBean").attr("href"); String mdbId = StringUtils.substringAfterLast(mdbRef, "ejb-jar.xml#"); if (StringUtils.isNotBlank(mdbId)) { for (EjbMessageDrivenModel mdb : mdbService.findAllByProperty(EjbMessageDrivenModel.EJB_ID, mdbId)) { String destination = jndiLocation; if (StringUtils.isNotBlank(destination)) { JmsDestinationModel jndiRef = jmsDestinationService.createUnique(applications, destination); mdb.setDestination(jndiRef); } } } } }