@Test public void auto() { Model m = ModelFactory.createDefaultModel(); Bean2RDF writer = new Bean2RDF(m); RDF2Bean reader = new RDF2Bean(m); AutoIdMethod bean2 = new AutoIdMethod(); reader.init(bean2); writer.save(bean2); bean2 = new AutoIdMethod(); reader.init(bean2); writer.save(bean2); for (int i = 0; i < 20; i++) { AutoId bean = new AutoId(); reader.init(bean); assertEquals(i, bean.id); writer.save(bean); } Collection<AutoId> ids = reader.load(AutoId.class); assertEquals(20, ids.size()); AutoId bean = new AutoId(); reader.init(bean); assertEquals(20, bean.id); writer.n3(); }
@Test public void testDouble() { Model m = ModelFactory.createDefaultModel(); Bean2RDF writer = new Bean2RDF(m); RDF2Bean reader = new RDF2Bean(m); Quantity q = new Quantity(); q.setAmount(1.0002); q.setUnits("km"); writer.save(q); Quantity q2 = reader.load(Quantity.class, 1.0002); assertNotNull(q2); }
/** Writes the user entities to rdf */ private static OntModel writeUserEntries() { OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); try { thewebsemantic.Bean2RDF writer = new Bean2RDF(model); InitialContext ic = new InitialContext(); UserService userService = (UserService) ic.lookup("java:module/UserService"); List<User> users = userService.getAll(); for (User u : users) { writer.save(u); } } catch (Exception e) { e.printStackTrace(); } return model; }
@Test public void testDate() { Model m = ModelFactory.createDefaultModel(); Bean2RDF writer = new Bean2RDF(m); RDF2Bean reader = new RDF2Bean(m); Date d = new Date(); Event event = new Event(d); event.setLocation("Dallas"); event.setName("dinner"); writer.save(event); Event event2 = reader.load(Event.class, d); assertNotNull(event2); assertEquals(d, event2.id()); }
/** Writes the project entities to rdf */ private static OntModel writeProjectEntries() { OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); try { thewebsemantic.Bean2RDF writer = new Bean2RDF(model); InitialContext ic = new InitialContext(); TreeNodeService treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService"); List<Project> projects = treeNodeService.getAllProjects(); for (Project proj : projects) { writer.save(proj); } } catch (Exception e) { e.printStackTrace(); } return model; }
/** Write metadata entities from the beans to rdf model */ private static OntModel writeMetaDataModelEntries() { OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); thewebsemantic.Bean2RDF writer = new Bean2RDF(model); try { InitialContext ic = new InitialContext(); for (final Class clazz : MetaData.getAllClasses()) { if (ContinuousIntegrationTool.class.isAssignableFrom(clazz)) { ContinuousIntegrationToolService cits = (ContinuousIntegrationToolService) ic.lookup("java:module/ContinuousIntegrationToolService"); List<ContinuousIntegrationTool> continuousIntegrationTools = cits.getAll(); for (ContinuousIntegrationTool continuousIntegrationTool : continuousIntegrationTools) { writer.save(continuousIntegrationTool); } } else if (CustomerType.class.isAssignableFrom(clazz)) { CustomerTypeService cts = (CustomerTypeService) ic.lookup("java:module/CustomerTypeService"); List<CustomerType> customerTypes = cts.getAll(); for (CustomerType customerType : customerTypes) { writer.save(customerType); } } else if (IssueTrackingTool.class.isAssignableFrom(clazz)) { IssueTrackingToolService itts = (IssueTrackingToolService) ic.lookup("java:module/IssueTrackingToolService"); List<IssueTrackingTool> issueTrackingTools = itts.getAll(); for (IssueTrackingTool issueTrackingTool : issueTrackingTools) { writer.save(issueTrackingTool); } } else if (ProgrammingLanguage.class.isAssignableFrom(clazz)) { ProgrammingLanguageService pls = (ProgrammingLanguageService) ic.lookup("java:module/ProgrammingLanguageService"); List<ProgrammingLanguage> programmingLanguages = pls.getAll(); for (ProgrammingLanguage programmingLanguage : programmingLanguages) { writer.save(programmingLanguage); } } else if (ProjectType.class.isAssignableFrom(clazz)) { ProjectTypeService pts = (ProjectTypeService) ic.lookup("java:module/ProjectTypeService"); List<ProjectType> projectTypes = pts.getAll(); for (ProjectType projectType : projectTypes) { writer.save(projectType); } } else if (SoftwareLicense.class.isAssignableFrom(clazz)) { SoftwareLicenseService sls = (SoftwareLicenseService) ic.lookup("java:module/SoftwareLicenseService"); List<SoftwareLicense> softwareLicenses = sls.getAll(); for (SoftwareLicense softwareLicense : softwareLicenses) { writer.save(softwareLicense); } } else if (SoftwareType.class.isAssignableFrom(clazz)) { SoftwareTypeService sts = (SoftwareTypeService) ic.lookup("java:module/SoftwareTypeService"); List<SoftwareType> softwareTypes = sts.getAll(); for (SoftwareType softwareType : softwareTypes) { writer.save(softwareType); } } else if (SourceCodeManagementTool.class.isAssignableFrom(clazz)) { SourceCodeManagementToolService scmts = (SourceCodeManagementToolService) ic.lookup("java:module/SourceCodeManagementToolService"); List<SourceCodeManagementTool> sourceCodeManagementTools = scmts.getAll(); for (SourceCodeManagementTool sourceCodeManagementTool : sourceCodeManagementTools) { writer.save(sourceCodeManagementTool); } } else if (StaticAnalysisTool.class.isAssignableFrom(clazz)) { StaticAnalysisToolService sats = (StaticAnalysisToolService) ic.lookup("java:module/StaticAnalysisToolService"); List<StaticAnalysisTool> staticAnalysisTools = sats.getAll(); for (StaticAnalysisTool staticAnalysisTool : staticAnalysisTools) { writer.save(staticAnalysisTool); } } else if (TestManagementTool.class.isAssignableFrom(clazz)) { TestManagementToolService tmts = (TestManagementToolService) ic.lookup("java:module/TestManagementToolService"); List<TestManagementTool> testManagementTools = tmts.getAll(); for (TestManagementTool testManagementTool : testManagementTools) { writer.save(testManagementTool); } } else if (Topic.class.isAssignableFrom(clazz)) { TopicService ts = (TopicService) ic.lookup("java:module/TopicService"); List<Topic> topics = ts.getAll(); for (Topic topic : topics) { writer.save(topic); } } else if (SoftwareDevelopmentMethodology.class.isAssignableFrom(clazz)) { SoftwareDevelopmentMethodologyService sdms = (SoftwareDevelopmentMethodologyService) ic.lookup("java:module/SoftwareDevelopmentMethodologyService"); List<SoftwareDevelopmentMethodology> softwareDevelopmentMethodologies = sdms.getAll(); for (SoftwareDevelopmentMethodology softwareDevelopmentMethodology : softwareDevelopmentMethodologies) { writer.save(softwareDevelopmentMethodology); } } else if (QModelTagData.class.isAssignableFrom(clazz)) { QModelTagDataService qmtds = (QModelTagDataService) ic.lookup("java:module/QModelTagDataService"); List<QModelTagData> qmodelTagData = qmtds.getAll(); for (QModelTagData qmtd : qmodelTagData) { writer.save(qmtd); } } } } catch (Exception e) { e.printStackTrace(); } return model; }