aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormwakao2013-10-15 16:41:39 (EDT)
committerSamuel Padgett2013-10-16 09:35:01 (EDT)
commit27b8e6f01f5cea59ae72141d8acc6d950af64e65 (patch)
tree87f5071550a97d2d153061fe82896816061e49d2
parent57079a4d6293a11200150b52a1aa8da0493badcf (diff)
downloadorg.eclipse.lyo.server-27b8e6f01f5cea59ae72141d8acc6d950af64e65.zip
org.eclipse.lyo.server-27b8e6f01f5cea59ae72141d8acc6d950af64e65.tar.gz
org.eclipse.lyo.server-27b8e6f01f5cea59ae72141d8acc6d950af64e65.tar.bz2
Bug 419518: Add mapping support to the Excel adapterrefs/changes/11/17411/1
- Improve mapping capability between Excel cells to RDF properties - The mapping definitions can be configured by a Excel file Change-Id: I21adb43482646f1d9317a40dd6b515af0ff5cba7 Signed-off-by: mwakao <wakao@jp.ibm.com>
-rw-r--r--org.eclipse.lyo.samples.excel/.settings/org.eclipse.core.resources.prefs3
-rw-r--r--org.eclipse.lyo.samples.excel/config.xml16
-rw-r--r--org.eclipse.lyo.samples.excel/pom.xml30
-rw-r--r--org.eclipse.lyo.samples.excel/repository/projectA/data.xlsbin0 -> 16896 bytes
-rw-r--r--org.eclipse.lyo.samples.excel/repository/projectA/mapper.xlsbin0 -> 15360 bytes
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/OslcApplication.java4
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ExcelAdapter.java17
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/MapperEntry.java100
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/MapperTable.java126
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelGroup.java35
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelManager.java285
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelQuery.java267
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/common/ResourceAdapter.java8
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ExcelDao.java8
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/PropertyMappingConfig.java142
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/PropertyMappingInfo.java27
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ResourceFactory.java25
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/internal/ExcelDaoImpl.java515
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCompactService.java13
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCreatorService.java31
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestGeneratorService.java23
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestListService.java11
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/common/ConfigSingleton.java153
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/common/ICmConstants.java112
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CatalogService.java37
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CreationFactoryService.java44
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/DownloadService.java73
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/QueryService.java6
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ResourceService.java19
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ServiceProviderService.java149
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/SparqlQueryService.java11
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/webapp/index.html10
-rw-r--r--org.eclipse.lyo.samples.excel/src/main/webapp/sparql.html4
33 files changed, 1096 insertions, 1208 deletions
diff --git a/org.eclipse.lyo.samples.excel/.settings/org.eclipse.core.resources.prefs b/org.eclipse.lyo.samples.excel/.settings/org.eclipse.core.resources.prefs
deleted file mode 100644
index 795e332..0000000
--- a/org.eclipse.lyo.samples.excel/.settings/org.eclipse.core.resources.prefs
+++ /dev/null
@@ -1,3 +0,0 @@
-#Sun Jan 22 14:54:32 EST 2012
-eclipse.preferences.version=1
-encoding//src/main/java/org/eclipse/lyo/samples/excel/services/common/CreationFactoryService.java=UTF-8
diff --git a/org.eclipse.lyo.samples.excel/config.xml b/org.eclipse.lyo.samples.excel/config.xml
index e3a72ec..27ec097 100644
--- a/org.eclipse.lyo.samples.excel/config.xml
+++ b/org.eclipse.lyo.samples.excel/config.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2011 IBM Corporation.
+ Copyright (c) 2011,2013 IBM Corporation.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
@@ -19,9 +19,19 @@
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
+<!-- model -->
<entry key="repositoryLocation">repository</entry>
<entry key="modelGroupName">projectA/</entry>
-<entry key="mapperFileName">mapper.xml</entry>
-<entry key="generatedExcelFileName">generated.xls/</entry>
+<entry key="mapperFileName">mapper.xls</entry>
<entry key="baseUri">http://open-services.net/excel/</entry>
+<!-- namespaces and prefixes -->
+<entry key="namespace1">oslc_cm,http://open-services.net/ns/cm#</entry>
+<!-- back links -->
+<entry key="backlink1">http://open-services.net/ns/cm#relatedChangeRequest,http://open-services.net/ns/cm#relatedChangeRequest</entry>
+<!-- catalog services -->
+<entry key="publisherTitle">Excel Adapter Sample Provider</entry>
+<entry key="publisherIdentifier">org.eclipse.lyo.samples.excel</entry>
+<entry key="publisherIcon">oslc.png</entry>
+<entry key="serviceDomain">http://open-services.net/ns/cm#</entry>
+<entry key="queryCapability1">changerequest,http://open-services.net/ns/cm#ChangeRequest</entry>
</properties> \ No newline at end of file
diff --git a/org.eclipse.lyo.samples.excel/pom.xml b/org.eclipse.lyo.samples.excel/pom.xml
index 0d7278d..f27fab0 100644
--- a/org.eclipse.lyo.samples.excel/pom.xml
+++ b/org.eclipse.lyo.samples.excel/pom.xml
@@ -29,41 +29,39 @@
<packaging>war</packaging>
<repositories>
- <repository>
+ <repository>
+ <id>lyo-releases</id>
+ <url>https://repo.eclipse.org/content/repositories/lyo-releases/</url>
+ </repository>
+ <repository>
<id>jena</id>
<name>Jena repo</name>
<url>http://openjena.org/repo</url>
</repository>
- </repositories>
+ </repositories>
<dependencies>
-
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-common</artifactId>
<version>1.1.2-incubating</version>
</dependency>
-
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-server</artifactId>
<version>1.1.2-incubating</version>
</dependency>
-
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee_1.4_spec</artifactId>
<version>1.1</version>
</dependency>
-
-
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>compile</scope>
</dependency>
-
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
@@ -71,21 +69,12 @@
<version>10.4.1.3</version>
<scope>test</scope>
</dependency>
-
-
-
-
-
-
-
-
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.2</version>
<scope>compile</scope>
</dependency>
-
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@@ -133,6 +122,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.lyo.core.query</groupId>
+ <artifactId>oslc-query</artifactId>
+ <version>2.0.0</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/org.eclipse.lyo.samples.excel/repository/projectA/data.xls b/org.eclipse.lyo.samples.excel/repository/projectA/data.xls
new file mode 100644
index 0000000..4aa02f9
--- /dev/null
+++ b/org.eclipse.lyo.samples.excel/repository/projectA/data.xls
Binary files differ
diff --git a/org.eclipse.lyo.samples.excel/repository/projectA/mapper.xls b/org.eclipse.lyo.samples.excel/repository/projectA/mapper.xls
new file mode 100644
index 0000000..f6cac26
--- /dev/null
+++ b/org.eclipse.lyo.samples.excel/repository/projectA/mapper.xls
Binary files differ
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/OslcApplication.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/OslcApplication.java
index a8d1d9f..cc4fe4b 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/OslcApplication.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/OslcApplication.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -29,7 +29,6 @@ import org.eclipse.lyo.samples.excel.changerequest.ChangeRequestListService;
import org.eclipse.lyo.samples.excel.changerequest.ChangeRequestReader;
import org.eclipse.lyo.samples.excel.services.common.CatalogService;
import org.eclipse.lyo.samples.excel.services.common.CreationFactoryService;
-import org.eclipse.lyo.samples.excel.services.common.DownloadService;
import org.eclipse.lyo.samples.excel.services.common.QueryService;
import org.eclipse.lyo.samples.excel.services.common.ResourceService;
import org.eclipse.lyo.samples.excel.services.common.ServiceProviderService;
@@ -52,7 +51,6 @@ public class OslcApplication extends Application {
serviceClasses.add(ChangeRequestListService.class);
serviceClasses.add(ChangeRequestCompactService.class);
serviceClasses.add(ChangeRequestCreatorService.class);
- serviceClasses.add(DownloadService.class);
return serviceClasses;
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ExcelAdapter.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ExcelAdapter.java
index db94054..d53ebfd 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ExcelAdapter.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ExcelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -23,7 +23,6 @@ import java.util.List;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceSet;
-import org.eclipse.lyo.samples.excel.changerequest.ChangeRequestDto;
import com.hp.hpl.jena.query.ResultSet;
@@ -50,11 +49,6 @@ public class ExcelAdapter implements ResourceAdapter {
return uriList;
}
- public void generateDefaultContents(int count) {
- modelManager.generateDefaultContents(count);
- }
-
-
private String getUri(String context) {
Collection<ModelGroup> groups = modelManager.getModelGroups();
for(ModelGroup g: groups){
@@ -65,10 +59,10 @@ public class ExcelAdapter implements ResourceAdapter {
return null;
}
- public ResourceSet query(String context, String prefix, String select, String where, String orderBy, String searchTerms) {
+ public ResourceSet query(String uri, String context, String prefix, String select, String where, String orderBy, String searchTerms) {
modelManager.scanRepository();
- return new ModelQuery().query(getUri(context), modelManager, prefix, select, where, orderBy, searchTerms);
+ return new ModelQuery().query(uri, getUri(context), modelManager, prefix, select, where, orderBy, searchTerms);
}
public ResourceSet getResource(String resourceUri) {
@@ -83,11 +77,6 @@ public class ExcelAdapter implements ResourceAdapter {
return new ModelQuery().executeSparql(getUri(context), modelManager, queryExp);
}
@Override
- public void addChangeRequest(ChangeRequestDto dto) {
- modelManager.scanRepository();
- modelManager.addChangeRequest(dto);
- }
- @Override
public String getDefaultExcelAbsolutePath() {
modelManager.scanRepository();
return modelManager.getDefaultExcelAbsolutePath();
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/MapperEntry.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/MapperEntry.java
new file mode 100644
index 0000000..977306a
--- /dev/null
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/MapperEntry.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Masaki Wakao
+ * Yoshio Horiuchi
+ *******************************************************************************/
+package org.eclipse.lyo.samples.excel.adapter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class MapperEntry {
+ public class Property {
+ private String name;
+ private String type;
+ private String column;
+ private String reference;
+
+ public Property(String name) {
+ this.name = name;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+ public void setColumn(String column) {
+ this.column = column;
+ }
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+ public String getName() {
+ return name;
+ }
+ public String getType() {
+ return type;
+ }
+ public String getColumn() {
+ return column;
+ }
+ public String getReference() {
+ return reference;
+ }
+ }
+ private String name;
+ private String type;
+ private String line;
+ private String uri;
+ private Map<String, MapperEntry.Property> propMap = new HashMap<String, MapperEntry.Property>();
+ private List<String> propNameList = new ArrayList<String>();
+
+ public MapperEntry(String name) {
+ this.name = name;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+ public void setLine(String line) {
+ this.line = line;
+ }
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+ public String getName() {
+ return name;
+ }
+ public String getType() {
+ return type;
+ }
+ public String getLine() {
+ return line;
+ }
+ public String getUri() {
+ return uri;
+ }
+
+ public MapperEntry.Property addProperty(String name) {
+ MapperEntry.Property prop = new MapperEntry.Property(name);
+ propMap.put(name, prop);
+ propNameList.add(name);
+ return prop;
+ }
+ public List<String> getPropertyNameList() {
+ return propNameList;
+ }
+ public MapperEntry.Property getProperty(String name) {
+ return propMap.get(name);
+ }
+}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/MapperTable.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/MapperTable.java
new file mode 100644
index 0000000..5830e6e
--- /dev/null
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/MapperTable.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2011,2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Masaki Wakao
+ * Yoshio Horiuchi
+ *******************************************************************************/
+package org.eclipse.lyo.samples.excel.adapter;
+
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+
+public class MapperTable {
+
+ Map<String, MapperEntry> entryMap = new HashMap<String, MapperEntry>();
+ List<String> nameList = new ArrayList<String>();
+
+ public void initialize(String fileName) {
+ FileInputStream in = null;
+ Workbook wb = null;
+
+ try{
+ in = new FileInputStream(fileName);
+ wb = WorkbookFactory.create(in);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ in.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ String lastName = null;
+ Sheet sheet = wb.getSheetAt(0); //wb.getFirstVisibleTab() + 1);
+ int start = 2; // skip row 0 and 1
+ for (int j = start; j <= sheet.getLastRowNum(); j++) {
+ Row row = sheet.getRow(j);
+ if (row == null) {
+ continue;
+ }
+
+ /* 0, 1, 2, 3 */
+ /* name, type, line, uri */
+ String name = getCellValue(row, 0);
+ if (name != null) {
+ MapperEntry entry = new MapperEntry(name);
+ entry.setType(getCellValue(row, 1)); /* type */
+ entry.setLine(getCellValue(row, 2)); /* line */
+ entry.setUri(getCellValue(row, 3)); /* uri */
+ entryMap.put(name, entry);
+ nameList.add(name);
+ lastName = name;
+ System.out.println("entry " + j + " : name=" + entry.getName() +
+ ", type=" + entry.getType() + ", line=" + entry.getLine() +
+ ", uri=" + entry.getUri());
+ continue;
+ }
+
+ if (lastName != null) {
+ /* 4, 5, 6, 7 */
+ /* prop:name, prop:type, prop:col, prop:ref */
+ String propName = getCellValue(row, 4);
+ if (propName != null) {
+ MapperEntry entry = entryMap.get(lastName);
+ MapperEntry.Property prop = entry.addProperty(propName);
+ prop.setType(getCellValue(row, 5)); /* prop:type */
+ prop.setColumn(getCellValue(row, 6)); /* prop:col */
+ prop.setReference(getCellValue(row, 7)); /* prop:ref */
+ System.out.println("property : name=" + prop.getName() +
+ ", type=" + prop.getType() + ", column=" + prop.getColumn() +
+ ", reference=" + prop.getReference());
+ }
+ }
+ }
+ }
+ public List<String> getNameList() {
+ return nameList;
+ }
+ public MapperEntry getEntry(String name) {
+ return entryMap.get(name);
+ }
+
+ private String getCellValue(Row row, int index) {
+ if (row != null) {
+ return getCellValue(row.getCell(index));
+ }
+ return null;
+ }
+ private String getCellValue(Cell cell) {
+ String value = null;
+ if (cell != null) {
+ int type = cell.getCellType();
+ if (type == Cell.CELL_TYPE_STRING) {
+ value = cell.getStringCellValue();
+ } else if (type == Cell.CELL_TYPE_NUMERIC) {
+ double d = cell.getNumericCellValue();
+ if (d == Math.floor(d)) { // need to consider when d is negative
+ value = "" + (int) d;
+ } else {
+ value = "" + cell.getNumericCellValue();
+ }
+ }
+ }
+ return value;
+ }
+}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelGroup.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelGroup.java
index 9f7d0b2..0a125a8 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelGroup.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelGroup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -21,22 +21,19 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import org.eclipse.lyo.samples.excel.adapter.dao.PropertyMappingConfig;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
-
+import org.eclipse.lyo.samples.excel.common.ConfigSingleton;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.sparql.vocabulary.FOAF;
-import com.hp.hpl.jena.vocabulary.DC;
public class ModelGroup {
private String pathName;
private String name;
private String uri;
- private PropertyMappingConfig propertyMappingConfig = null;
- private long propertyMappingConfigLastModified;
+ private long mapperTableLastModified;
+
+ private MapperTable mapperTable = null;
private Map<String, ModelContainer> modelMap = new HashMap<String, ModelContainer>();
@@ -62,17 +59,19 @@ public class ModelGroup {
this.uri = uri;
}
- public long getPropertyMappingConfigLastModified() {
- return propertyMappingConfigLastModified;
+ public long getMapperTableLastModified() {
+ return mapperTableLastModified;
}
- public void setPropertyMappingConfigLastModified(long propertyMappingConfigLastModified) {
- this.propertyMappingConfigLastModified = propertyMappingConfigLastModified;
+ public void setMapperTableLastModified(long mapperTableLastModified) {
+ this.mapperTableLastModified = mapperTableLastModified;
}
- public void loadPropertyMappingConfig(String filename) {
- propertyMappingConfig = new PropertyMappingConfig(filename);
+
+ public void loadMapperTable(String fileName) {
+ mapperTable = new MapperTable();
+ mapperTable.initialize(fileName);
}
- public PropertyMappingConfig getPropertyMappingConfig() {
- return propertyMappingConfig;
+ public MapperTable getMapperTable() {
+ return mapperTable;
}
public Map<String, ModelContainer> getModelMap() {
@@ -83,9 +82,7 @@ public class ModelGroup {
boolean merge = false;
if (model == null) {
model = ModelFactory.createDefaultModel();
- model.setNsPrefix("oslc_cm", ICmConstants.OSLC_CM_NAMESPACE);
- model.setNsPrefix("foaf", FOAF.NS);
- model.setNsPrefix("dcterms", DC.getURI());
+ model.setNsPrefixes(ConfigSingleton.getInstance().getNsPrefixes());
merge = true;
} else {
Iterator<ModelContainer> i = modelMap.values().iterator();
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelManager.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelManager.java
index 33f99ae..6e791dc 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelManager.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -18,38 +18,21 @@
package org.eclipse.lyo.samples.excel.adapter;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.Collection;
-import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
-import java.util.Random;
import java.util.Set;
-import org.eclipse.lyo.rio.util.RandomTextGenerator;
import org.eclipse.lyo.samples.excel.adapter.dao.ExcelDao;
import org.eclipse.lyo.samples.excel.adapter.dao.ExcelDaoFactory;
-import org.eclipse.lyo.samples.excel.adapter.dao.PropertyMappingInfo;
-import org.eclipse.lyo.samples.excel.adapter.dao.ResourceFactory;
-import org.eclipse.lyo.samples.excel.changerequest.ChangeRequestDto;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
+import org.eclipse.lyo.samples.excel.common.ConfigSingleton;
-import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Property;
-import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.sparql.vocabulary.FOAF;
-import com.hp.hpl.jena.vocabulary.DC;
-import com.hp.hpl.jena.vocabulary.RDF;
public class ModelManager {
private static String repositoryLocationDefault;
@@ -59,22 +42,13 @@ public class ModelManager {
private static String baseUriDefault;
static {
- Properties prop = new Properties();
- try {
- prop.loadFromXML(new FileInputStream("config.xml"));
- repositoryLocationDefault = prop.getProperty("repositoryLocation");
- modelGroupNameDefault = prop.getProperty("modelGroupName");
- mapperFileNameDefault = prop.getProperty("mapperFileName");
- generatedExcelFileNameDefault = prop.getProperty("generatedExcelFileName");
- baseUriDefault = prop.getProperty("baseUri");
+ ConfigSingleton singleton = ConfigSingleton.getInstance();
+
+ repositoryLocationDefault = singleton.getRepositoryLocationDefault();
+ modelGroupNameDefault = singleton.getModelGroupNameDefault();
+ mapperFileNameDefault = singleton.getMapperFileNameDefault();
+ baseUriDefault = singleton.getBaseUriDefault();
- System.out.println("default repositoryLocation : " + repositoryLocationDefault);
- System.out.println("default modelGroupName : " + modelGroupNameDefault);
- System.out.println("default mapperFileName : " + mapperFileNameDefault);
- System.out.println("default generatedExcelFileName : " + generatedExcelFileNameDefault);
- System.out.println("default baseUri : " + baseUriDefault);
- } catch (Exception e) {
- }
}
private String repositoryLocation = repositoryLocationDefault;
private String mapperFileName = mapperFileNameDefault;
@@ -84,28 +58,6 @@ public class ModelManager {
private Map<String, ModelGroup> modelGroupMap = new HashMap<String, ModelGroup>();
- class ResourceFactoryImpl implements ResourceFactory {
- private Map<String, String> typeToRelationshipUri = new HashMap<String, String>();
- public void setRelationshipUri(String type, String relationshipUri) {
- typeToRelationshipUri.put(type, relationshipUri);
- }
- public Resource createResource(Model model, String resourceType, String value, String valueType) {
- String relationshipUri = typeToRelationshipUri.get(resourceType);
- if (relationshipUri == null) {
- return null;
- }
- Resource resource = null;
- try {
- resource = model.createResource(relationshipUri + URLEncoder.encode(value, "UTF-8"));
- resource.addProperty(RDF.type, model.createResource(resourceType));
- resource.addProperty(model.createProperty(valueType), value);
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return resource;
- }
- }
-
public void setRepositoryLocation(String repositryLocation) {
this.repositoryLocation = repositryLocation;
}
@@ -129,7 +81,12 @@ public class ModelManager {
File f = files[i];
if (f.isDirectory()) {
String name = f.getName();
- String uri = baseUri + name + "/";
+ String ename = name;
+ try {
+ ename = URLEncoder.encode(name, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ }
+ String uri = baseUri + ename + "/";
ModelGroup modelGroup = modelGroupMap.get(uri);
if (modelGroup == null) {
modelGroup = new ModelGroup();
@@ -182,10 +139,10 @@ public class ModelManager {
}
}
- if (modelGroup.getPropertyMappingConfigLastModified() <= mapperFile.lastModified()) {
- // reload mapper xml file
- modelGroup.loadPropertyMappingConfig(mapperFile.getAbsolutePath());
- modelGroup.setPropertyMappingConfigLastModified(mapperFile.lastModified());
+ if (modelGroup.getMapperTableLastModified() <= mapperFile.lastModified()) {
+ // reload mapper xls file
+ modelGroup.setMapperTableLastModified(mapperFile.lastModified());
+ modelGroup.loadMapperTable(mapperFile.getAbsolutePath());
// clear map, and reload all
modelGroup.getModelMap().clear();
}
@@ -203,7 +160,13 @@ public class ModelManager {
}
if (name != null && suffix != null && suffix.equalsIgnoreCase("xls")) {
boolean reload = true;
- String relationshipUri = modelGroup.getUri() + name + "/";
+ String ename = name;
+ try {
+ ename = URLEncoder.encode(name, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ String relationshipUri = modelGroup.getUri() + ename + "/";
String pathName = f.getAbsolutePath();
ModelContainer container = modelGroup.getModelMap().get(relationshipUri);
if (container == null) {
@@ -217,12 +180,8 @@ public class ModelManager {
reload = false;
}
if (reload) {
- ResourceFactoryImpl resourceFactory = new ResourceFactoryImpl();
- resourceFactory.setRelationshipUri(ICmConstants.OSLC_CM_CHANGEREQUEST, relationshipUri);
- resourceFactory.setRelationshipUri(FOAF.Person.getURI(), modelGroup.getUri() + "users/");
dao.setRelationshipUri(relationshipUri);
- dao.setResourceFactory(resourceFactory);
- dao.setPropertyMappingConfig(modelGroup.getPropertyMappingConfig());
+ dao.setMapperTable(modelGroup.getMapperTable());
Model model = dao.parseFile(pathName);
if (container.getModel() != null) {
container.getModel().close();
@@ -253,195 +212,5 @@ public class ModelManager {
String pathName = modelGroup.getPathName();
return pathName + "\\" + generatedExcelFileNameDefault;
- }
-
- public void addChangeRequest(ChangeRequestDto dto){
- ModelGroup modelGroup = getModelGroup(baseUri + modelGroupNameDefault);
- String pathName = modelGroup.getPathName();
-
- ResourceFactoryImpl resourceFactory = new ResourceFactoryImpl();
- resourceFactory.setRelationshipUri(ICmConstants.OSLC_CM_CHANGEREQUEST, modelGroup.getUri());
- resourceFactory.setRelationshipUri(FOAF.Person.getURI(), modelGroup.getUri() + "users/");
- dao.setRelationshipUri(modelGroup.getUri());
- dao.setResourceFactory(resourceFactory);
- dao.setPropertyMappingConfig(modelGroup.getPropertyMappingConfig());
-
- List<PropertyMappingInfo> mappingInfo = modelGroup.getPropertyMappingConfig().listPropertyInfo(null); //try default mapping
-
- Model model = ModelFactory.createDefaultModel();
- model.setNsPrefix("oslc_cm", ICmConstants.OSLC_CM_NAMESPACE);
- model.setNsPrefix("foaf", FOAF.NS);
-
- try{
- Resource changeRequest = null;
- for (int j = 0; j < mappingInfo.size(); j++) {
- PropertyMappingInfo info = mappingInfo.get(j);
- if (info.getResourceName().equalsIgnoreCase(ICmConstants.OSLC_CM_CHANGEREQUEST) &&
- info.getPropertyName().equalsIgnoreCase(DC.identifier.getURI())) {
- //identifier
- String value = Integer.toString(dao.getNewId(pathName + "\\" + generatedExcelFileNameDefault) + 1);
- if (value != null) {
- changeRequest = resourceFactory.createResource(model, info.getResourceName(), value, info.getPropertyName());
- break;
- }
- }
- }
- for (int j = 0; j < mappingInfo.size(); j++) {
- PropertyMappingInfo info = mappingInfo.get(j);
- Property property = model.createProperty(info.getPropertyName());
-
- if (info.getPropertyType().equalsIgnoreCase("http://open-services.net/ns/core#Resource") &&
- info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/contributor")) { // TODO add to cm constant def
- //contributor
- String value = "_UNKNOWN_USER_";
- PropertyMappingInfo detailInfo = info.getDetailInfo();
- String resourceClass = detailInfo.getResourceName();
- Resource resource = resourceFactory.createResource(model, resourceClass, value, detailInfo.getPropertyName());
- changeRequest.addProperty(property, resource);
-// }else if (info.getPropertyType().equalsIgnoreCase("http://open-services.net/ns/core#Resource") &&
-// info.getPropertyName().equalsIgnoreCase("http://open-services.net/ns/cm#relatedChangeRequest")) { // TODO add to cm constant def
-// //relatedChangeRequest
-// String value = String.valueOf(1); //TODO must change to refer existing resource
-// PropertyMappingInfo detailInfo = info.getDetailInfo();
-// String resourceClass = detailInfo.getResourceName();
-// Resource resource = resourceFactory.createResource(model, resourceClass, value, detailInfo.getPropertyName());
-// changeRequest.addProperty(property, resource);
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/title")) { // TODO add to cm constant def
- //title
- Literal literal = model.createLiteral(dto.getTitle());
- changeRequest.addLiteral(property, literal);
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/description")) { // TODO add to cm constant def
- //description
- Literal literal = model.createLiteral(dto.getDescription());
- changeRequest.addLiteral(property, literal);
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/created")) { // TODO add to cm constant def
- //created
- Calendar calendar = Calendar.getInstance();
- Date nowTime = calendar.getTime();
- Literal literal = model.createLiteral(nowTime.toString());
- changeRequest.addLiteral(property, literal);
- } else if (info.getPropertyName().equalsIgnoreCase("http://open-services.net/ns/cm#status")) { // TODO add to cm constant def
- //status
- Literal literal = model.createLiteral(dto.getStatus());
- changeRequest.addLiteral(property, literal);
- }
- }
-
- dao.write(pathName + "\\" + generatedExcelFileNameDefault, model, true);
-
-// try {
-// RDFWriter w = model.getWriter("RDF/XML-ABBREV");
-// w.setProperty("showXMLDeclaration", "true");
-// w.write(model, System.out, "");
-// } catch (Exception e){
-// e.printStackTrace();
-// }
-
- }catch(IOException e){
- e.printStackTrace();
- }
- }
-
-
-
- public void generateDefaultContents(int count) {
- ModelGroup modelGroup = getModelGroup(baseUri + modelGroupNameDefault);
- String pathName = modelGroup.getPathName();
-
- ResourceFactoryImpl resourceFactory = new ResourceFactoryImpl();
- resourceFactory.setRelationshipUri(ICmConstants.OSLC_CM_CHANGEREQUEST, modelGroup.getUri());
- resourceFactory.setRelationshipUri(FOAF.Person.getURI(), modelGroup.getUri() + "users/");
- dao.setRelationshipUri(modelGroup.getUri());
- dao.setResourceFactory(resourceFactory);
- dao.setPropertyMappingConfig(modelGroup.getPropertyMappingConfig());
-
- List<PropertyMappingInfo> mappingInfo = modelGroup.getPropertyMappingConfig().listPropertyInfo(null); //try default mapping
-
- Model model = ModelFactory.createDefaultModel();
- model.setNsPrefix("oslc_cm", ICmConstants.OSLC_CM_NAMESPACE);
- model.setNsPrefix("foaf", FOAF.NS);
-
- Random rnd = new Random(System.currentTimeMillis());
-
- try{
- RandomTextGenerator gen = new RandomTextGenerator();
-
- for(int i=1;i<=count;i++) {
- Resource changeRequest = null;
- for (int j = 0; j < mappingInfo.size(); j++) {
- PropertyMappingInfo info = mappingInfo.get(j);
- if (info.getResourceName().equalsIgnoreCase(ICmConstants.OSLC_CM_CHANGEREQUEST) &&
- info.getPropertyName().equalsIgnoreCase(DC.identifier.getURI())) {
- //identifier
- String value = String.valueOf(i);
- if (value != null) {
- changeRequest = resourceFactory.createResource(model, info.getResourceName(), value, info.getPropertyName());
- break;
- }
- }
- }
- if (changeRequest == null) {
- continue;
- }
- for (int j = 0; j < mappingInfo.size(); j++) {
- PropertyMappingInfo info = mappingInfo.get(j);
- Property property = model.createProperty(info.getPropertyName());
-
- if (info.getPropertyType().equalsIgnoreCase("http://open-services.net/ns/core#Resource") &&
- info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/contributor")) { // TODO add to cm constant def
- //contributor
- String value = "_UNKNOWN_USER_";
- PropertyMappingInfo detailInfo = info.getDetailInfo();
- String resourceClass = detailInfo.getResourceName();
- Resource resource = resourceFactory.createResource(model, resourceClass, value, detailInfo.getPropertyName());
- changeRequest.addProperty(property, resource);
- }else if (info.getPropertyType().equalsIgnoreCase("http://open-services.net/ns/core#Resource") &&
- info.getPropertyName().equalsIgnoreCase("http://open-services.net/ns/cm#relatedChangeRequest")) { // TODO add to cm constant def
- //relatedChangeRequest
- String value = String.valueOf(i);
- PropertyMappingInfo detailInfo = info.getDetailInfo();
- String resourceClass = detailInfo.getResourceName();
- Resource resource = resourceFactory.createResource(model, resourceClass, value, detailInfo.getPropertyName());
- changeRequest.addProperty(property, resource);
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/title")) { // TODO add to cm constant def
- //title
- int titleLen = rnd.nextInt(3) + 2;
- String title = gen.generateText(titleLen);
- Literal literal = model.createLiteral(title);
- changeRequest.addLiteral(property, literal);
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/description")) { // TODO add to cm constant def
- //description
- int descriptionLen = rnd.nextInt(50) + 50;
- String description = gen.generateText(descriptionLen);
- Literal literal = model.createLiteral(description);
- changeRequest.addLiteral(property, literal);
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/created")) { // TODO add to cm constant def
- //created
- Calendar calendar = Calendar.getInstance();
- Date nowTime = calendar.getTime();
- Literal literal = model.createLiteral(nowTime.toString());
- changeRequest.addLiteral(property, literal);
- } else if (info.getPropertyName().equalsIgnoreCase("http://open-services.net/ns/cm#status")) { // TODO add to cm constant def
- //status
- int statusIndex = rnd.nextInt(4);
- Literal literal = model.createLiteral(ICmConstants.OSLC_CM_STATUS_VALUES[statusIndex]);
- changeRequest.addLiteral(property, literal);
- }
- }
- }
-
- dao.write(pathName + "\\" + generatedExcelFileNameDefault, model, false);
-
-// try {
-// RDFWriter w = model.getWriter("RDF/XML-ABBREV");
-// w.setProperty("showXMLDeclaration", "true");
-// w.write(model, System.out, "");
-// } catch (Exception e){
-// e.printStackTrace();
-// }
-
- }catch(IOException e){
- e.printStackTrace();
- }
- }
+ }
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelQuery.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelQuery.java
index 49b5205..0f6dece 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelQuery.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/ModelQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -17,13 +17,27 @@
*******************************************************************************/
package org.eclipse.lyo.samples.excel.adapter;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.eclipse.lyo.core.query.NestedProperty;
+import org.eclipse.lyo.core.query.PName;
+import org.eclipse.lyo.core.query.ParseException;
+import org.eclipse.lyo.core.query.Property;
+import org.eclipse.lyo.core.query.QueryUtils;
+import org.eclipse.lyo.core.query.SelectClause;
import org.eclipse.lyo.rio.query.OslcWhereHelper.OslcWhereParseException;
import org.eclipse.lyo.rio.query.SimpleQueryBuilder;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceSet;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
+import org.eclipse.lyo.samples.excel.common.ConfigSingleton;
+import org.eclipse.lyo.samples.excel.services.common.ServiceProviderService;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
@@ -37,8 +51,7 @@ import com.hp.hpl.jena.rdf.model.RDFWriter;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
-import com.hp.hpl.jena.sparql.vocabulary.FOAF;
-import com.hp.hpl.jena.vocabulary.DC;
+import com.hp.hpl.jena.vocabulary.RDFS;
public class ModelQuery {
class ResourceSetImpl implements ResourceSet {
@@ -52,30 +65,145 @@ public class ModelQuery {
w.write(model, out, "");
}
}
+ class QueryResultResourceSet implements ResourceSet {
+ private String requestUri;
+ private List<Model> list = new ArrayList<Model>();
+ public void addRequestUri(String requestUri) {
+ this.requestUri = requestUri;
+ }
+ public void addModel(Model model) {
+ list.add(model);
+ }
+ private byte[] getModelByteArray(Model model) {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ RDFWriter w = model.getWriter("RDF/XML-ABBREV");
+ w.setProperty("showXMLDeclaration", "true");
+ w.write(model, os, "");
+ return os.toByteArray();
+ }
+ private int[] findResourcePos(byte[] b) {
+ int start = 0;
+ boolean openTag = false;
+ for (int i = 0; i < b.length; i++) {
+ if (openTag && b[i] == '>') {
+ start = i + 1;
+ break;
+ }
+ if (b[i] == 'R' &&
+ (i + 1 < b.length && b[i + 1] == 'D') &&
+ (i + 2 < b.length && b[i + 2] == 'F')) {
+ openTag = true;
+ }
+ }
+ int end = b.length - 1;
+ boolean closeTag = false;
+ for (int i = b.length - 1; i >= 0; i--) {
+ if (closeTag && b[i] == '<') {
+ end = i - 1;
+ break;
+ }
+ if (b[i] == 'F' &&
+ (i - 1 >= 0 && b[i - 1] == 'D') &&
+ (i - 2 >= 0 && b[i - 2] == 'R')) {
+ closeTag = true;
+ }
+ }
+ if (start < end) {
+ return new int[] { start, end };
+ } else {
+ return new int[] { 0, b.length - 1 };
+ }
+ }
+ public void outputAsXML(OutputStream out) {
+ byte[] close = new byte[0];
+ for (int i = 0; i < list.size(); i++) {
+ Model model = list.get(i);
+ try {
+ byte[] b = getModelByteArray(model); // one model, one resource
+ int[] pos = findResourcePos(b);
+ int start;
+ int end;
+ // write open tag
+ if (i == 0) {
+ start = 0;
+ end = pos[0] - 1;
+ out.write(b, start, end - start + 1);
+ out.write("\n".getBytes());
+ out.write(new String("<rdf:Description rdf:about=\"" + requestUri + "\">\n").getBytes());
+ }
+ // write resource contents
+ out.write(new String("<!-- " + i + " -->").getBytes());
+ start = pos[0];
+ end = pos[1];
+ out.write(new String("<rdfs:member>").getBytes());
+ out.write(b, start, end - start + 1);
+ out.write(new String("</rdfs:member>").getBytes());
+ // store close tag to a buffer, and append it later
+ if (i == 0) {
+ start = pos[1] + 1;
+ end = b.length - 1;
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ os.write(b, start, end - start + 1);
+ close = os.toByteArray();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ // write close tag
+ if(list.isEmpty()){
+ out.write(new String("<rdf:Description xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n").getBytes());
+ }
+ out.write(new String("</rdf:Description>\n").getBytes());
+ out.write(close);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
- public ResourceSet query(String uri, ModelManager modelManager, String prefix, String select, String where, String orderBy, String searchTerms) {
+ public ResourceSet query(String requestUri, String uri, ModelManager modelManager, String prefix, String select, String where, String orderBy, String searchTerms) {
ModelGroup modelGroup = modelManager.getModelGroup(uri);
Model model = modelGroup.getModel();
System.out.println("original model :");
printModel(model);
- if (prefix == null || prefix.length() == 0) {
- prefix = "dcterms=<" + DC.getURI()+ ">,foaf=<" + FOAF.getURI() + ">";
- }
SimpleQueryBuilder queryBuilder = new SimpleQueryBuilder();
try {
queryBuilder.parsePrefix(prefix);
- queryBuilder.addPrefix(ICmConstants.OSLC_CM_NAMESPACE, "oslc_cm");
+ for (Entry<String, String> e : ConfigSingleton.getInstance().getNsPrefixes().entrySet()) {
+ queryBuilder.addPrefix(e.getValue(), e.getKey());
+ }
queryBuilder.parseSelect(select);
- queryBuilder.parseWhere("uri", where); //$NON-NLS-1$
+ if (where != null && !where.isEmpty()) {
+ queryBuilder.parseWhere("uri", where); //$NON-NLS-1$
+ }
+ String targetResourceType = getQueryResourceType(requestUri);
+ if (targetResourceType != null) {
+ queryBuilder.appendWhere("?uri a <" + targetResourceType + "> .");
+ } else {
+ queryBuilder.appendWhere("?uri a ?type .");
+ }
queryBuilder.parseSelect(orderBy);
queryBuilder.parseSearchTerms(searchTerms);
} catch (OslcWhereParseException e) {
e.printStackTrace();
}
- String sparql = queryBuilder.getQueryString(ICmConstants.OSLC_CM_CHANGEREQUEST);
+ Map<String, String> prefixMap = null;
+ SelectClause selectClause = null;
+ try {
+ if (select != null) {
+ prefixMap = QueryUtils.parsePrefixes(prefix);
+ prefixMap.putAll(ConfigSingleton.getInstance().getNsPrefixes());
+ selectClause = QueryUtils.parseSelect(select, prefixMap);
+ }
+ } catch (ParseException e) {
+ }
+
+ String sparql = queryBuilder.getQueryString(null);
System.out.println("query:");
System.out.println(sparql);
@@ -83,16 +211,13 @@ public class ModelQuery {
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet result = qexec.execSelect();
-// Model retModel = ResultSetFormatter.toModel(result);
-// qexec.close();
-
- Model retModel = ModelFactory.createDefaultModel();
- retModel.setNsPrefix("oslc_cm", ICmConstants.OSLC_CM_NAMESPACE);
- retModel.setNsPrefix("foaf", FOAF.NS);
- retModel.setNsPrefix("dcterms", DC.getURI());
-
+ QueryResultResourceSet rs = new QueryResultResourceSet();
+ rs.addRequestUri(requestUri);
try {
while (result.hasNext()) {
+ Model retModel = ModelFactory.createDefaultModel();
+ retModel.setNsPrefixes(ConfigSingleton.getInstance().getNsPrefixes());
+ retModel.setNsPrefix("rdfs", RDFS.getURI());
QuerySolution qs = result.next();
Resource r = (Resource) qs.get("uri");
System.out.println(r);
@@ -102,15 +227,107 @@ public class ModelQuery {
Statement s = si.nextStatement();
System.out.println("stmt: " + s);
retModel.add(s);
+ //
+ if (selectClause != null) {
+ ArrayList<String> nameList = new ArrayList<String>();
+ nameList.add(s.getPredicate().getURI());
+ if (isNested(nameList, selectClause, prefixMap)) {
+ setStatements(retModel, s.getObject().asResource(), nameList, selectClause, prefixMap);
+ }
+ }
}
+ rs.addModel(retModel);
}
} finally {
qexec.close();
}
- System.out.println("return model:");
- printModel(retModel);
-
- return new ResourceSetImpl(retModel);
+
+ return rs;
+ }
+
+ private void setStatements(Model model, Resource resource, List<String> nameList, SelectClause selectClause, Map<String, String> prefixMap) {
+ System.out.println(nameList + " is nested property...");
+ StmtIterator si = resource.listProperties();
+ while (si.hasNext()) {
+ Statement s = si.nextStatement();
+ System.out.println("stmt: " + s);
+ model.add(s);
+ //
+ ArrayList<String> nextNameList = new ArrayList<String>(nameList);
+ nextNameList.add(s.getPredicate().getURI());
+ if (isNested(nextNameList, selectClause, prefixMap)) {
+ setStatements(model, s.getObject().asResource(), nextNameList, selectClause, prefixMap);
+ }
+ }
+ }
+
+ private boolean isNested(List<String> nameList, SelectClause sel, Map<String, String> prefixMap) {
+ List<Property> children = sel.children();
+ for (int i = 0; i < children.size(); i++) {
+ Property child = children.get(i);
+ if (isNested(nameList, child, prefixMap)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ private boolean isNested(List<String> nameList, Property p, Map<String, String> prefixMap) {
+ if (nameList.isEmpty()) {
+ return false;
+ }
+ if (p instanceof NestedProperty) {
+ String name = nameList.get(0);
+ if (p.isWildcard() || equalPName(p.identifier(), name, prefixMap)) {
+ if (nameList.size() == 1) {
+ return true;
+ }
+ ArrayList<String> nextNameList = new ArrayList<String>();
+ for (int i = 1; i < nameList.size(); i++) {
+ nextNameList.add(nameList.get(i));
+ }
+ List<Property> children = ((NestedProperty)p).children();
+ for (int i = 0; i < children.size(); i++) {
+ Property child = children.get(i);
+ if (isNested(nextNameList, child, prefixMap)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+ private String getNameUri(String name, Map<String, String> prefixMap) {
+ Set<String> keys = prefixMap.keySet();
+ Iterator<String> ite = keys.iterator();
+ String prefix = null;
+ while (ite.hasNext()) {
+ String key = ite.next();
+ if (name.startsWith(key + ":")) {
+ prefix = key;
+ }
+ }
+ if (prefix != null) {
+ String uri = prefixMap.get(prefix);
+ return name.replaceFirst(prefix + ":", uri);
+ }
+ return name;
+ }
+ private boolean equalPName(PName pname, String uri, Map<String, String> prefixMap) {
+ String pnameUri = getNameUri(pname.toString(), prefixMap);
+ return pnameUri.equals(uri);
+ }
+
+ /**
+ * should be sync with {@link ServiceProviderService#buildServicesResource(String, String)}
+ */
+ private String getQueryResourceType(String uri){
+ Map<String, String> queryCapabilities = ConfigSingleton.getInstance().getQueryCapabilities();
+ for(String uriLastSegment: queryCapabilities.keySet()){
+ if(uri.endsWith(uriLastSegment)){
+ return queryCapabilities.get(uriLastSegment);
+ }
+ }
+ return null;
}
public ResourceSet getResource(ModelManager modelManager, String resourceUri) {
@@ -121,9 +338,7 @@ public class ModelQuery {
Resource r = model.getResource(resourceUri);
if (r != null) {
Model retModel = ModelFactory.createDefaultModel();
- retModel.setNsPrefix("oslc_cm", ICmConstants.OSLC_CM_NAMESPACE);
- retModel.setNsPrefix("foaf", FOAF.NS);
- retModel.setNsPrefix("dcterms", DC.getURI());
+ retModel.setNsPrefixes(ConfigSingleton.getInstance().getNsPrefixes());
Resource o = retModel.createResource(r.getURI());
System.out.println(o);
StmtIterator si = r.listProperties();
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/common/ResourceAdapter.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/common/ResourceAdapter.java
index e4e76ff..d1a3ac0 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/common/ResourceAdapter.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/common/ResourceAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -19,18 +19,14 @@ package org.eclipse.lyo.samples.excel.adapter.common;
import java.util.List;
-import org.eclipse.lyo.samples.excel.changerequest.ChangeRequestDto;
-
import com.hp.hpl.jena.query.ResultSet;
public interface ResourceAdapter {
void setBaseUri(String uri);
void loadRepository();
- ResourceSet query(String context, String prefix, String select, String where, String orderBy, String searchTerms);
+ ResourceSet query(String uri, String context, String prefix, String select, String where, String orderBy, String searchTerms);
ResourceSet getResource(String resourceUri);
List<String> getContexts();
- void generateDefaultContents(int count);
ResultSet executeSparql(String context, String queryExp);
- void addChangeRequest(ChangeRequestDto dto);
String getDefaultExcelAbsolutePath();
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ExcelDao.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ExcelDao.java
index f0cf2a1..c8b9d40 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ExcelDao.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ExcelDao.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -17,15 +17,13 @@
*******************************************************************************/
package org.eclipse.lyo.samples.excel.adapter.dao;
-import java.io.IOException;
+import org.eclipse.lyo.samples.excel.adapter.MapperTable;
import com.hp.hpl.jena.rdf.model.Model;
public interface ExcelDao {
Model parseFile(String fileName);
void setRelationshipUri(String relationshipUri);
- void setResourceFactory(ResourceFactory resourceFactory);
- void setPropertyMappingConfig(PropertyMappingConfig config);
- void write(String fileName, Model model, boolean append) throws IOException;
+ void setMapperTable(MapperTable mapperTable);
int getNewId(String fileName);
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/PropertyMappingConfig.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/PropertyMappingConfig.java
deleted file mode 100644
index 1e13628..0000000
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/PropertyMappingConfig.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
- *
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *
- * Masaki Wakao
- * Yoshio Horiuchi
- * Kohji Ohsawa
- *******************************************************************************/
-package org.eclipse.lyo.samples.excel.adapter.dao;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class PropertyMappingConfig {
-
- private final static String ELEMENT_MAPPING = "mapping";
- private final static String ELEMENT_PROPERTY = "property";
- private final static String ATTR_FOR = "for";
- private final static String ATTR_INDEX = "index";
- private final static String ATTR_TYPE = "type";
- private final static String ATTR_NAME = "name";
- private final static String ATTR_OF = "of";
- private final static String ATTR_FORMAT_STRING = "formatString";
-
- private Document doc;
-
- private Map<String, Node> fileToMappingNode = new HashMap<String, Node>();
-
- public PropertyMappingConfig(String defFile) {
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- doc = db.parse(defFile);
- parse();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void parse() {
- NodeList nodeList = doc.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- if (node.getNodeName().equals(ELEMENT_MAPPING)) {
- String forValue = ((Element)node).getAttribute(ATTR_FOR);
- forValue.trim();
- if (forValue.length() == 0) {
- forValue = null; // default
- }
- fileToMappingNode.put(forValue, node);
- }
- }
- }
-
- public List<PropertyMappingInfo> listPropertyInfo(String forValue) {
- List<PropertyMappingInfo> list = new ArrayList<PropertyMappingInfo>();
- Node mappingNode = fileToMappingNode.get(forValue);
- if (mappingNode == null && forValue != null) {
- mappingNode = fileToMappingNode.get(null); // try default
- }
- if (mappingNode != null) {
- NodeList nodeList = mappingNode.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- PropertyMappingInfo info = getPropertyInfo(node);
- if (info != null) {
- list.add(info);
- }
- }
- }
- return list;
- }
-
- class MappingInfoImpl implements PropertyMappingInfo {
- private Element element;
- public MappingInfoImpl(Element element) {
- this.element = element;
- }
- public int getIndex() {
- try {
- String v = element.getAttribute(ATTR_INDEX);
- return Integer.parseInt(v);
- } catch (NumberFormatException e) {
- }
- return -1;
- }
- public String getPropertyType() {
- return element.getAttribute(ATTR_TYPE);
- }
- public String getPropertyName() {
- return element.getAttribute(ATTR_NAME);
- }
- public String getResourceName() {
- return element.getAttribute(ATTR_OF);
- }
- public String getFormatString() {
- return element.getAttribute(ATTR_FORMAT_STRING);
- }
- public PropertyMappingInfo getDetailInfo() {
- NodeList nodeList = element.getChildNodes();
- Node node = null;
- for (int i = 0; i < nodeList.getLength(); i++) {
- node = nodeList.item(i);
- if (node != null && node.getNodeType() == Node.ELEMENT_NODE &&
- node.getNodeName().equals(ELEMENT_PROPERTY)) {
- break;
- }
- node = null;
- }
- if (node != null) {
- return new MappingInfoImpl((Element)node);
- }
- return null;
- }
-
- }
- private PropertyMappingInfo getPropertyInfo(Node node) {
- if (node != null && node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(ELEMENT_PROPERTY)) {
- return new MappingInfoImpl((Element)node);
- }
- return null;
- }
-}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/PropertyMappingInfo.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/PropertyMappingInfo.java
deleted file mode 100644
index c00c1a4..0000000
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/PropertyMappingInfo.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
- *
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *
- * Masaki Wakao
- * Yoshio Horiuchi
- * Kohji Ohsawa
- *******************************************************************************/
-package org.eclipse.lyo.samples.excel.adapter.dao;
-
-public interface PropertyMappingInfo {
- int getIndex();
- String getPropertyType();
- String getPropertyName();
- String getResourceName();
- String getFormatString();
- PropertyMappingInfo getDetailInfo();
-}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ResourceFactory.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ResourceFactory.java
deleted file mode 100644
index df0fa78..0000000
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/ResourceFactory.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
- *
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *
- * Masaki Wakao
- * Yoshio Horiuchi
- * Kohji Ohsawa
- *******************************************************************************/
-package org.eclipse.lyo.samples.excel.adapter.dao;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.Resource;
-
-public interface ResourceFactory {
- Resource createResource(Model model, String resourceType, String value, String valueType);
-}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/internal/ExcelDaoImpl.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/internal/ExcelDaoImpl.java
index 0028790..b10dc50 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/internal/ExcelDaoImpl.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/adapter/dao/internal/ExcelDaoImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -17,74 +17,65 @@
*******************************************************************************/
package org.eclipse.lyo.samples.excel.adapter.dao.internal;
-import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
-import java.text.SimpleDateFormat;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Arrays;
import java.util.Date;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.commons.lang.time.FastDateFormat;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.apache.poi.ss.util.AreaReference;
+import org.apache.poi.ss.util.CellReference;
+import org.eclipse.lyo.samples.excel.adapter.MapperEntry;
+import org.eclipse.lyo.samples.excel.adapter.MapperTable;
import org.eclipse.lyo.samples.excel.adapter.dao.ExcelDao;
-import org.eclipse.lyo.samples.excel.adapter.dao.PropertyMappingConfig;
-import org.eclipse.lyo.samples.excel.adapter.dao.PropertyMappingInfo;
-import org.eclipse.lyo.samples.excel.adapter.dao.ResourceFactory;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
+import org.eclipse.lyo.samples.excel.common.ConfigSingleton;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
-import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.rdf.model.Statement;
-import com.hp.hpl.jena.sparql.vocabulary.FOAF;
-import com.hp.hpl.jena.vocabulary.DC;
+import com.hp.hpl.jena.vocabulary.RDF;
public class ExcelDaoImpl implements ExcelDao {
//TODO
private static final String DEFAULT_SHEET_NAME="defects";
- private final static Property IDENFIFIER = com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty("http://purl.org/dc/elements/1.1/", "identifier");
- private final static Property TITLE = com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty("http://purl.org/dc/elements/1.1/", "title");
- private final static Property DESCRIPTION = com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty("http://purl.org/dc/elements/1.1/", "description");
- private final static Property CREATED = com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty("http://purl.org/dc/elements/1.1/", "created");
- private final static Property CONTRIBUTER = com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty("http://purl.org/dc/elements/1.1/", "contributor");
- private final static Property STATUS = com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty("http://open-services.net/ns/cm#", "status");
- private final static Property RELATED_CHANGEREQUEST = com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty("http://open-services.net/ns/cm#", "relatedChangeRequest");
- private final static Property PERSON_NAME = com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty("http://xmlns.com/foaf/0.1/", "name");
-
+ private final static String DEFAULT_OUTPUT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZZ";
private String relationshipUri = null;
- private ResourceFactory resourceFactory = null;
- private PropertyMappingConfig config = null;
+ private MapperTable mapperTable = null;
public void setRelationshipUri(String relationshipUri) {
this.relationshipUri = relationshipUri;
}
- public void setResourceFactory(ResourceFactory resourceFactory) {
- this.resourceFactory = resourceFactory;
- }
- public void setPropertyMappingConfig(PropertyMappingConfig config) {
- this.config = config;
+ public void setMapperTable(MapperTable mapperTable) {
+ this.mapperTable = mapperTable;
}
+
public Model parseFile(String fileName) {
- if (relationshipUri == null || config == null) {
+ if (relationshipUri == null) {
return null;
}
- List<PropertyMappingInfo> mappingInfo = config.listPropertyInfo(new File(fileName).getName());
-
+
FileInputStream in = null;
Workbook wb = null;
@@ -102,211 +93,315 @@ public class ExcelDaoImpl implements ExcelDao {
}
Model model = ModelFactory.createDefaultModel();
- model.setNsPrefix("oslc_cm", ICmConstants.OSLC_CM_NAMESPACE);
- model.setNsPrefix("foaf", FOAF.NS);
-
- Sheet sheet = wb.getSheetAt(0);
- for (int j = sheet.getFirstRowNum(); j <= sheet.getLastRowNum(); j++) {
- Row row = sheet.getRow(j);
- if (row == null) {
+ model.setNsPrefixes(ConfigSingleton.getInstance().getNsPrefixes());
+
+ HashMap<Sheet, Object[]> sheetResourceMap = new HashMap<Sheet, Object[]>();
+
+ // Loop for Resources defined in Mapper file
+ for (String en : mapperTable.getNameList()) {
+ MapperEntry e = mapperTable.getEntry(en);
+ String type = e.getType();
+ String line = e.getLine();
+ String uri = e.getUri();
+
+ // parse line definition in Mapper file
+ String[] ls = line.split(",");
+ if(ls.length < 3){
+ System.err.println("line must has at least sheet, start row, and end row information");
+ continue;
+ }
+ String ssheet = ls[0].trim();
+ String sstart = ls[1].trim();
+ String send = ls[2].trim();
+ Sheet sheet = null;
+ try{
+ sheet = wb.getSheetAt(Integer.parseInt(ssheet));
+ }catch(NumberFormatException ex){
+ sheet = wb.getSheet(ssheet);
+ }
+ if(sheet==null){
+ System.err.println("target sheet is not found");
continue;
}
- Resource changeRequest = null;
- for (int i = 0; i < mappingInfo.size(); i++) {
- PropertyMappingInfo info = mappingInfo.get(i);
- if (info.getResourceName().equalsIgnoreCase(ICmConstants.OSLC_CM_CHANGEREQUEST) &&
- info.getPropertyName().equalsIgnoreCase(DC.identifier.getURI())) {
- String value = getCellValue(row, info);
- if (value != null) {
- changeRequest = resourceFactory.createResource(model, info.getResourceName(), value, info.getPropertyName());
- break;
- }
+ int start = Integer.parseInt(sstart);
+ int end = sheet.getLastRowNum();
+ if (!send.equals("*")) {
+ end = Integer.parseInt(send);
+ }
+ String cond_cellstring = null;
+ boolean exist = true;
+ if(ls.length > 3){
+ String scond = ls[3].trim();
+ if (scond.startsWith("exist")) {
+ cond_cellstring = scond.substring(6, scond.length() - 1).trim();
+ }else if(scond.startsWith("notexist")) {
+ exist = false;
+ cond_cellstring = scond.substring(9, scond.length() - 1).trim();
}
}
- if (changeRequest == null) {
- continue;
+
+ // map to find referenced resource later
+ Object[] resourceMap = sheetResourceMap.get(sheet);
+ if(resourceMap == null){
+ resourceMap = new Object[sheet.getLastRowNum() + 1];
+ Arrays.fill(resourceMap, null);
+ sheetResourceMap.put(sheet, resourceMap);
}
- for (int i = 0; i < mappingInfo.size(); i++) {
- PropertyMappingInfo info = mappingInfo.get(i);
- Property property = model.createProperty(info.getPropertyName());
- String value = getCellValue(row, info);
- if (value == null) {
+
+ // Loop of excel table rows to find the resource
+ for (int j = start; j <= end; j++) {
+ if (sheet.getRow(j) == null) {
continue;
}
- if (info.getPropertyType().equalsIgnoreCase("http://open-services.net/ns/core#Resource")) { // TODO add to cm constant def
- PropertyMappingInfo detailInfo = info.getDetailInfo();
- String resourceClass = detailInfo.getResourceName();
- Resource resource = resourceFactory.createResource(model, resourceClass, value, detailInfo.getPropertyName());
- changeRequest.addProperty(property, resource);
- } else {
- Literal literal = model.createLiteral(value);
- changeRequest.addLiteral(property, literal);
+ if (cond_cellstring != null) {
+ Cell cell = getCell(sheet, cond_cellstring, j);
+ String value = getCellValue(cell);
+ if (value == null && exist || value != null && !exist){
+ continue;
+ }
+ }
+ // generate URI for this resource
+ String[] uris = uri.split(",");
+ String format = uris[0].trim();
+ String uriString = format;
+ if (uris.length == 3) {
+ Cell cell = getCell(sheet, uris[1].trim(), j);
+ String value1 = getCellValue(cell);
+ cell = getCell(sheet, uris[2].trim(), j);
+ String value2 = getCellValue(cell);
+ uriString = String.format(format, value1, value2);
+ } else if (uris.length == 2) {
+ Cell cell = getCell(sheet, uris[1].trim(), j);
+ String value = getCellValue(cell);
+ uriString = String.format(format, value);
+ }
+
+ // create a Resource in RDF model with URI and resource type defined in Mapper file
+ Resource resource = null;
+ try {
+ resource = model.createResource(relationshipUri + URLEncoder.encode(uriString, "UTF-8"));
+
+ type = getNameUri(type.trim(), model);
+ resource.addProperty(RDF.type, model.createResource(type));
+ } catch (UnsupportedEncodingException e1) {
+ e1.printStackTrace();
+ }
+ if (resource == null) {
+ continue;
+ }
+
+ // Keep resource map for current row which will be used to generate reference URI later
+ Map<String, Resource> curResMap = (Map<String, Resource>) resourceMap[j];
+ if (curResMap == null) {
+ curResMap = new HashMap<String, Resource>();
+ resourceMap[j] = curResMap;
+ }
+ curResMap.put(en, resource);
+
+ // Loop for Properties for this resource defined in Mapper file
+ for (String propName: e.getPropertyNameList()) {
+ MapperEntry.Property prop = e.getProperty(propName);
+ if (prop == null) {
+ continue;
+ }
+ String propType = prop.getType();
+ if (propType == null) {
+ continue;
+ }
+ if (propType.equalsIgnoreCase("resource")) {
+ // assume that prop contains "reference" information in Mapper file
+ String reference = prop.getReference();
+ if (reference != null) {
+ processReference(model, resource, propName, reference, resourceMap, j);
+ }
+ } else {
+ // assume that prop contains "column" information in Mapper file
+ String[] tokens = prop.getColumn().trim().split(",");
+ String fmt = null;
+ String column = tokens[0];
+ if (tokens.length > 1) {
+ fmt = tokens[0];
+ column = tokens[1];
+ }
+ Cell cell = getCell(sheet, column, j);
+ if (cell != null) {
+ String value = getCellValue(cell);
+ if (value != null) {
+ if (fmt != null) {
+ value = String.format(fmt, value);
+ }
+ String qpname = propName.trim();
+ qpname = getNameUri(qpname, model);
+ Property property = model.createProperty(qpname);
+ Literal literal = model.createLiteral(value);
+ resource.addLiteral(property, literal);
+ }
+ }
+ }
}
}
}
return model;
}
- public void write(String fileName, Model model, boolean append) throws IOException {
- HSSFWorkbook workBook = new HSSFWorkbook();
- if(append){
- FileInputStream in = new FileInputStream(fileName);
- try {
- workBook = (HSSFWorkbook) WorkbookFactory.create(in);
- in.close();
- } catch (InvalidFormatException e) {
- e.printStackTrace();
+ private Cell getCell(Sheet sheet, String cellRowString, int defaultRowIndex) {
+ Cell cell = getNamedCell(sheet, cellRowString, defaultRowIndex);
+ if (cell != null) {
+ return cell;
+ }
+ int[] index = cellRowStringToIndex(cellRowString);
+ int rowIndex = (index.length > 1) ? index[1] : defaultRowIndex;
+ Row row = sheet.getRow(rowIndex);
+ if (row != null) {
+ return row.getCell(index[0]);
+ }
+ return null;
+ }
+
+ private Cell getNamedCell(Sheet sheet, String cellRowString, int defaultRowIndex) {
+ Name name = sheet.getWorkbook().getName(cellRowString);
+ if (name != null) {
+ AreaReference areaRef = new AreaReference(name.getRefersToFormula());
+ CellReference firstCell = areaRef.getFirstCell();
+ CellReference lastCell = areaRef.getLastCell();
+ int rowIndex = defaultRowIndex;
+ if (rowIndex < firstCell.getRow() || lastCell.getRow() < rowIndex) {
+ rowIndex = firstCell.getRow();
+ }
+ Row row = sheet.getRow(rowIndex);
+ if (row != null) {
+ return row.getCell(firstCell.getCol());
}
}
- HSSFSheet sheet = null;
- if(append){
- sheet = workBook.getSheet(DEFAULT_SHEET_NAME);
- }else{
- sheet = workBook.createSheet(DEFAULT_SHEET_NAME);
+ return null;
+ }
+
+ private int[] cellRowStringToIndex(String cellRowString) {
+ int index = -1;
+ for (int i = 0; i < cellRowString.length(); i++) {
+ char c = cellRowString.charAt(i);
+ if (Character.isDigit(c)) {
+ index = i;
+ break;
+ }
}
-
- int count = 0;
- if(append){
- count = getNewId(fileName);
+ if (index <= 0) {
+ // No digit, or digit only.
+ // The string only has a cell index in this case.
+ return new int[] { cellStringToIndex(cellRowString) };
}
-
- ResIterator resIter = model.listSubjects();
- while(resIter.hasNext()){
- HSSFRow row = null;
- Resource resource = (Resource)resIter.nextResource();
-
- List<PropertyMappingInfo> mappingInfo = config.listPropertyInfo(null); //try default mapping
- for (int j = 0; j < mappingInfo.size(); j++) {
- PropertyMappingInfo info = mappingInfo.get(j);
- if (info.getResourceName().equalsIgnoreCase(ICmConstants.OSLC_CM_CHANGEREQUEST) &&
- info.getPropertyName().equalsIgnoreCase(DC.identifier.getURI())) {
- //identifier
- Statement idenfifier = resource.getProperty(IDENFIFIER);
- if (idenfifier != null) {
- if(row == null){
- row = sheet.createRow(count++);
- }
- HSSFCell cell = row.createCell(info.getIndex());
- cell.setCellValue(idenfifier.getInt());
- }
-// }else if (info.getPropertyType().equalsIgnoreCase("http://open-services.net/ns/core#Resource") &&
-// info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/contributor")) { // TODO add to cm constant def
-// //contributor
-// Statement contributor = resource.getProperty(CONTRIBUTER);
-// if (contributor != null) {
-// if(row == null){
-// row = sheet.createRow(count++);
-// }
-//
-// PropertyMappingInfo detailInfo = info.getDetailInfo();
-// if(detailInfo.getPropertyType().equalsIgnoreCase("http://xmlns.com/foaf/0.1/Person") &&
-// detailInfo.getPropertyName().equalsIgnoreCase("http://xmlns.com/foaf/0.1/name")) { // TODO add to cm constant def
-//
-// Statement personName = contributor.getProperty(PERSON_NAME);
-// //Resource person = contributor.getProperty(property);
-// HSSFCell cell = row.createCell(info.getIndex());
-// cell.setCellValue(personName.getString());
-// }
-// }
-// }else if (info.getPropertyType().equalsIgnoreCase("http://open-services.net/ns/core#Resource") &&
-// info.getPropertyName().equalsIgnoreCase("http://open-services.net/ns/cm#relatedChangeRequest")) { // TODO add to cm constant def
-// //relatedChangeRequest
-// Statement relatedChangeRequest = resource.getProperty(RELATED_CHANGEREQUEST);
-// if (relatedChangeRequest != null) {
-// if(row == null){
-// row = sheet.createRow(count++);
-// }
-// HSSFCell cell = row.createCell(info.getIndex());
-// cell.setCellValue(relatedChangeRequest.getInt());
-// }
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/title")) { // TODO add to cm constant def
- //title
- Statement title = resource.getProperty(TITLE);
- if (title != null) {
- if(row == null){
- row = sheet.createRow(count++);
- }
- HSSFCell cell = row.createCell(info.getIndex());
- cell.setCellValue(title.getString());
- }
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/description")) { // TODO add to cm constant def
- //description
- Statement description = resource.getProperty(DESCRIPTION);
- if (description != null) {
- if(row == null){
- row = sheet.createRow(count++);
- }
- HSSFCell cell = row.createCell(info.getIndex());
- cell.setCellValue(description.getString());
- }
- } else if (info.getPropertyName().equalsIgnoreCase("http://purl.org/dc/elements/1.1/created")) { // TODO add to cm constant def
- //created
- Statement created = resource.getProperty(CREATED);
- if (created != null) {
- if(row == null){
- row = sheet.createRow(count++);
- }
- HSSFCell cell = row.createCell(info.getIndex());
- cell.setCellValue(created.getString());
- }
- } else if (info.getPropertyName().equalsIgnoreCase("http://open-services.net/ns/cm#status")) { // TODO add to cm constant def
- //status
- Statement status = resource.getProperty(STATUS);
- if (status != null) {
- if(row == null){
- row = sheet.createRow(count++);
- }
- HSSFCell cell = row.createCell(info.getIndex());
- cell.setCellValue(status.getString());
- }
- }
+ // The string has both cell and row indices.
+ String cellString = cellRowString.substring(0, index);
+ String rowString = cellRowString.substring(index);
+ return new int[] { cellStringToIndex(cellString), Integer.parseInt(rowString) };
+ }
+
+ private int cellStringToIndex(String cellString){
+ try {
+ return Integer.parseInt(cellString);
+ }catch(NumberFormatException ex){
+ return CellReference.convertColStringToIndex(cellString);
+ }
+ }
+
+ private void processReference(Model model, Resource resource, String propName, String referenceDef, Object[] resourceMaps, int currentRow) {
+ referenceDef = referenceDef.trim();
+ int suffixIndex;
+
+ // sameLine
+ suffixIndex = referenceDef.toLowerCase().indexOf("[sameline]");
+ if (suffixIndex > 0) {
+ String targetResourceName = referenceDef.substring(0, suffixIndex);
+ Map<String, Resource> resMap = (Map<String, Resource>) resourceMaps[currentRow];
+ addReferenceProperty(model, resource, resMap, propName, targetResourceName);
+ }
+
+ // mostRecent
+ suffixIndex = referenceDef.toLowerCase().indexOf("[mostrecent]");
+ if (suffixIndex > 0) {
+ String targetResourceName = referenceDef.substring(0, suffixIndex);
+ for (int i = currentRow; i >= 0; i--) { // mostrecent includes sameline
+ Map<String, Resource> resMap = (Map<String, Resource>) resourceMaps[i];
+ if(addReferenceProperty(model, resource, resMap, propName, targetResourceName))
+ break;
}
}
+ }
- OutputStream out = new FileOutputStream(fileName);
- workBook.write(out);
- out.close();
+ private boolean addReferenceProperty(Model model, Resource resource, Map<String, Resource> resourceMap, String propName, String target) {
+ if(resourceMap != null){
+ Resource targetResource = resourceMap.get(target);
+ if (targetResource != null) {
+ String qpname = propName.trim();
+ qpname = getNameUri(qpname, model);
+ Property property = model.createProperty(qpname);
+ resource.addProperty(property, targetResource);
+ String backLinkUri = ConfigSingleton.getInstance().getBacklinks().get(qpname);
+ if(backLinkUri != null){
+ Property backLinkProperty = model.createProperty(backLinkUri);
+ targetResource.addProperty(backLinkProperty, resource);
+ }
+ return true;
+ }
+ }
+ return false;
}
- private String getCellValue(Row row, PropertyMappingInfo info) {
- int index = info.getIndex();
- if (index != -1) {
- Cell cell = row.getCell(index);
- if (cell != null) {
- String value = null;
- try {
- String type = info.getPropertyType();
- if (type.equalsIgnoreCase(ICmConstants.XSD_DATATYPE_DATETIME)) {
- String formatString = info.getFormatString();
- if (formatString == null) {
- formatString = "yyyy-MM-dd'T'HH:mm:ssz";
- }
- Date date = cell.getDateCellValue();
- SimpleDateFormat f = new SimpleDateFormat(formatString);
- value = f.format(date);
- }
- } catch (Exception e) {
- }
- if (value == null) {
- int type = cell.getCellType();
- if (type == Cell.CELL_TYPE_STRING) {
- value = cell.getStringCellValue();
- } else if (type == Cell.CELL_TYPE_NUMERIC) {
- double d = cell.getNumericCellValue();
- if (d == Math.floor(d)) { // need to consider when d is negative
- value = "" + (int) d;
- } else {
- value = "" + cell.getNumericCellValue();
- }
+ private String getCellValue(Cell cell) {
+ if (cell != null) {
+ String value = null;
+ int type = cell.getCellType();
+ if (type == Cell.CELL_TYPE_STRING) {
+ value = cell.getStringCellValue();
+ } else if (type == Cell.CELL_TYPE_NUMERIC) {
+ if (DateUtil.isCellDateFormatted(cell)) {
+ Date date = cell.getDateCellValue();
+ value = FastDateFormat.getInstance(DEFAULT_OUTPUT_DATE_FORMAT).format(date);
+ } else {
+ double d = cell.getNumericCellValue();
+ if (d == Math.floor(d)) { // need to consider when d is negative
+ value = "" + (int) d;
+ } else {
+ value = "" + cell.getNumericCellValue();
}
}
- return value;
+ } else if (type == Cell.CELL_TYPE_FORMULA){
+ // get calculated value if the cell type is formula
+ Workbook wb = cell.getSheet().getWorkbook();
+ CreationHelper crateHelper = wb.getCreationHelper();
+ FormulaEvaluator evaluator = crateHelper.createFormulaEvaluator();
+ // get recursively if the value is still formula
+ value = getCellValue(evaluator.evaluateInCell(cell));
}
+ return value;
}
return null;
}
+ private String getNameUri(String name, Model model) {
+ Map<String, String> prefixMapping = model.getNsPrefixMap();
+ Set<String> keys = prefixMapping.keySet();
+ Iterator<String> ite = keys.iterator();
+ String prefix = null;
+ while (ite.hasNext()) {
+ String key = ite.next();
+ if (name.startsWith(key + ":")) {
+ prefix = key;
+ }
+ }
+ if (prefix != null) {
+ String uri = model.getNsPrefixURI(prefix);
+ return name.replaceFirst(prefix + ":", uri);
+ }
+ if (name.startsWith("dcterms:")) {
+ return name.replaceFirst("dcterms:", "http://purl.org/dc/terms/");
+ }
+ if (name.startsWith("dc:")) {
+ return name.replaceFirst("dc:", "http://purl.org/dc/terms/");
+ }
+ return name;
+ }
@Override
public int getNewId(String fileName) {
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCompactService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCompactService.java
index 84a4892..c1d32ec 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCompactService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCompactService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -31,12 +31,11 @@ import javax.ws.rs.core.UriInfo;
import org.eclipse.lyo.rio.core.IConstants;
import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
-@Path(ICmConstants.SERVICE_SERVICES + "/compact/changerequest")
+@Path(IConstants.SERVICE_SERVICES + "/compact-rendering")
public class ChangeRequestCompactService {
@GET
@@ -44,12 +43,11 @@ public class ChangeRequestCompactService {
String baseUrl = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES;
ResourceAdapter adapter = AdapterRegistry.getAdapter(baseUrl);
String query =
- "PREFIX dcterms:<http://purl.org/dc/elements/1.1/>\n" +
- "SELECT ?uri ?title ?identifier ?created\n" +
+ "PREFIX dcterms:<http://purl.org/dc/terms/>\n" +
+ "SELECT ?uri ?title ?identifier\n" +
"WHERE {\n" +
" ?uri dcterms:title ?title.\n" +
" ?uri dcterms:identifier ?identifier.\n" +
- " ?uri dcterms:created ?created.\n" +
" ?uri dcterms:identifier \"" + id + "\"\n" +
"}\n";
@@ -69,13 +67,11 @@ public class ChangeRequestCompactService {
String uri = "";
String title = "";
String id = "";
- String created = "";
while (resultSet.hasNext()) {
QuerySolution qs = resultSet.nextSolution();
uri = qs.get("uri").toString();
title = qs.get("title").toString();
id = qs.get("identifier").toString();
- created = qs.get("created").toString();
}
StringBuffer sb = new StringBuffer();
@@ -100,7 +96,6 @@ public class ChangeRequestCompactService {
sb.append("URI: " + uri + "<br/>");
sb.append("Title: " + title + "<br/>");
sb.append("Identifier: " + id + "<br/>");
- sb.append("Created:" + created + "<br/>");
sb.append("</body>");
sb.append("</html>");
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCreatorService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCreatorService.java
index a8ba461..f179191 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCreatorService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestCreatorService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -24,39 +24,16 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriInfo;
+import org.apache.commons.lang.NotImplementedException;
import org.eclipse.lyo.rio.core.IConstants;
-import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
-import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
-@Path(ICmConstants.SERVICE_SERVICES + "/{projectId}/creator")
+@Path(IConstants.SERVICE_SERVICES + "/{projectId}/creator")
public class ChangeRequestCreatorService {
@POST
//@Consumes ({"application/rdf+xml", "application/xml"})
//@Consumes ({"text/xml"})
public void doPost(@PathParam("projectId") String projectId, @Context UriInfo uriInfo, MultivaluedMap<String, String> formData) {
- String title = formData.getFirst("title");
- String description = formData.getFirst("description");
- String status = formData.getFirst("status");
-
- if(description == null){
- description = "";
- }
-
- try{
- ChangeRequestDto dto = new ChangeRequestDto();
- dto.setTitle(title);
- dto.setDescription(description);
- dto.setStatus(status);
-
- String baseUrl = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES;
- ResourceAdapter adapter = AdapterRegistry.getAdapter(baseUrl);
- adapter.addChangeRequest(dto);
- } catch( Exception e) {
- e.printStackTrace();
- }
-// String uri = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES + "/" + projectId + "/list";
-// return Response.seeOther(URI.create(uri)).build();
+ throw new NotImplementedException();
}
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestGeneratorService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestGeneratorService.java
index 323c2c9..e24331c 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestGeneratorService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestGeneratorService.java
@@ -17,8 +17,6 @@
*******************************************************************************/
package org.eclipse.lyo.samples.excel.changerequest;
-import java.net.URI;
-
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -27,32 +25,17 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import org.apache.commons.lang.NotImplementedException;
import org.eclipse.lyo.rio.core.IConstants;
-import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
-import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
-@Path(ICmConstants.SERVICE_SERVICES + "/{projectId}/generate/changerequest")
+@Path(IConstants.SERVICE_SERVICES + "/{projectId}/generate/changerequest")
public class ChangeRequestGeneratorService {
@POST
//@Consumes ({"application/rdf+xml", "application/xml"})
public Response doPost(@PathParam("projectId") String projectId, @Context UriInfo uriInfo, MultivaluedMap<String, String> formData) {
- int count = Integer.parseInt(formData.getFirst("count"));
-
- try{
- String baseUrl = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES;
- ResourceAdapter adapter = AdapterRegistry.getAdapter(baseUrl);
- adapter.loadRepository();
- adapter.generateDefaultContents(count);
-
- } catch( Exception e ) {
- e.printStackTrace();
- }
- // Return HTTP response with status code 201 Created
- String uri = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES + "/" + projectId + "/list";
- return Response.seeOther(URI.create(uri)).build();
+ throw new NotImplementedException();
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestListService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestListService.java
index 7a74728..472858a 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestListService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/changerequest/ChangeRequestListService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -31,12 +31,11 @@ import javax.ws.rs.core.UriInfo;
import org.eclipse.lyo.rio.core.IConstants;
import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
-@Path(ICmConstants.SERVICE_SERVICES + "/{projectId}/list")
+@Path(IConstants.SERVICE_SERVICES + "/{projectId}/list")
public class ChangeRequestListService {
@GET
@@ -45,7 +44,7 @@ public class ChangeRequestListService {
ResourceAdapter adapter = AdapterRegistry.getAdapter(baseUrl);
String query =
- "PREFIX dcterms:<http://purl.org/dc/elements/1.1/>\n" +
+ "PREFIX dcterms:<http://purl.org/dc/terms/>\n" +
"SELECT ?uri ?title ?identifier\n" +
"WHERE {\n" +
" ?uri dcterms:title ?title.\n" +
@@ -59,7 +58,7 @@ public class ChangeRequestListService {
return new StreamingOutput() {
public void write(OutputStream output) throws IOException, WebApplicationException {
- byte[] out = html.getBytes();
+ byte[] out = html.getBytes(IConstants.TEXT_ENCODING);
output.write(out);
}
};
@@ -80,7 +79,7 @@ public class ChangeRequestListService {
sb.append(" -->");
sb.append("<html>");
sb.append("<head>");
- sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">");
+ sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + IConstants.TEXT_ENCODING + "\">");
sb.append("<link rel=\"SHORTCUT ICON\" href=\"../oslc.png\">");
sb.append("<title>RIO OSLC CM Resource Listing</title>");
sb.append("<script type=\"text/javascript\" src=\"" + contextRoot + "/smallpreview.js\">");
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/common/ConfigSingleton.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/common/ConfigSingleton.java
new file mode 100644
index 0000000..3dc6391
--- /dev/null
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/common/ConfigSingleton.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Masaki Wakao
+ * Yoshio Horiuchi
+ *******************************************************************************/
+package org.eclipse.lyo.samples.excel.common;
+
+import java.io.FileInputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.lyo.rio.core.IConstants;
+
+public class ConfigSingleton {
+
+ private static ConfigSingleton theInstance = new ConfigSingleton();
+
+ private String repositoryLocationDefault;
+ private String modelGroupNameDefault;
+ private String mapperFileNameDefault;
+ private String baseUriDefault;
+ private Map<String, String> nsPrefixes = new HashMap<String, String>();
+ private Map<String, String> backlinks = new HashMap<String, String>();
+ private String publisherTitleDefault;
+ private String publisherIdentifierDefault;
+ private String publisherIconDefault;
+ private String serviceDomainDefault;
+ private Map<String, String> queryCapabilities = new HashMap<String, String>();
+
+ private ConfigSingleton() {
+ Properties prop = new Properties();
+ try {
+ prop.loadFromXML(new FileInputStream("config.xml"));
+ repositoryLocationDefault = prop.getProperty("repositoryLocation");
+ modelGroupNameDefault = prop.getProperty("modelGroupName");
+ mapperFileNameDefault = prop.getProperty("mapperFileName");
+ baseUriDefault = prop.getProperty("baseUri");
+ publisherTitleDefault = prop.getProperty("publisherTitle");
+ publisherIdentifierDefault = prop.getProperty("publisherIdentifier");
+ publisherIconDefault = prop.getProperty("publisherIcon");
+ serviceDomainDefault = prop.getProperty("serviceDomain");
+
+ System.out.println("default repositoryLocation : " + repositoryLocationDefault);
+ System.out.println("default modelGroupName : " + modelGroupNameDefault);
+ System.out.println("default mapperFileName : " + mapperFileNameDefault);
+ System.out.println("default baseUri : " + baseUriDefault);
+ System.out.println("default publisherTitle : " + publisherTitleDefault);
+ System.out.println("default publisherIdentifier : " + publisherIdentifierDefault);
+ System.out.println("default publisherIcon : " + publisherIconDefault);
+ System.out.println("default serviceDomain : " + serviceDomainDefault);
+
+ // prefix to namespace map
+ nsPrefixes.put(IConstants.DCTERMS_PREFIX, IConstants.DCTERMS_NAMESPACE);
+ for (int i = 1; ; i++) {
+ String value = prop.getProperty("namespace" + i);
+ if (value == null) {
+ break;
+ }
+ String[] tokens = value.split(",");
+ if (tokens.length > 1) {
+ nsPrefixes.put(tokens[0], tokens[1]);
+ System.out.println("namespace prefix = " + tokens[0] + ", uri = " + tokens[1]);
+ }
+ }
+
+ // backlink map
+ for (int i = 1; ; i++) {
+ String value = prop.getProperty("backlink" + i);
+ if (value == null) {
+ break;
+ }
+ String[] tokens = value.split(",");
+ if (tokens.length > 1) {
+ backlinks.put(tokens[0], tokens[1]);
+ System.out.println("backlink " + tokens[0] + ", " + tokens[1]);
+ }
+ }
+
+ // query capabilities map
+ for (int i = 1; ; i++) {
+ String value = prop.getProperty("queryCapability" + i);
+ if (value == null) {
+ break;
+ }
+ String[] tokens = value.split(",");
+ if (tokens.length > 1) {
+ queryCapabilities.put(tokens[0], tokens[1]);
+ System.out.println("queryCapability " + tokens[0] + ", " + tokens[1]);
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+
+ public static ConfigSingleton getInstance() {
+ return theInstance;
+ }
+
+ /*
+ * Model related properties
+ */
+ public String getRepositoryLocationDefault() {
+ return repositoryLocationDefault;
+ }
+ public String getModelGroupNameDefault() {
+ return modelGroupNameDefault;
+ }
+ public String getMapperFileNameDefault() {
+ return mapperFileNameDefault;
+ }
+ public String getBaseUriDefault() {
+ return baseUriDefault;
+ }
+ public Map<String, String> getBacklinks() {
+ return backlinks;
+ }
+ /*
+ * Namespace related properties
+ */
+ public Map<String, String> getNsPrefixes() {
+ return nsPrefixes;
+ }
+ /*
+ * Catalog related properties
+ */
+ public String getPublisherTitle() {
+ return publisherTitleDefault;
+ }
+ public String getPublisherIdentifier() {
+ return publisherIdentifierDefault;
+ }
+ public String getPublisherIcon() {
+ return publisherIconDefault;
+ }
+ public String getServiceDomainDefault() {
+ return serviceDomainDefault;
+ }
+ public Map<String, String> getQueryCapabilities() {
+ return queryCapabilities;
+ }
+}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/common/ICmConstants.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/common/ICmConstants.java
deleted file mode 100644
index ba79db5..0000000
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/common/ICmConstants.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
- *
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *
- * Masaki Wakao
- * Yoshio Horiuchi
- * Kohji Ohsawa
- *******************************************************************************/
-package org.eclipse.lyo.samples.excel.common;
-
-import org.eclipse.lyo.rio.core.IConstants;
-
-@SuppressWarnings("nls")
-public interface ICmConstants extends IConstants {
-
- // server constants
- public static final String SERVER_CONTEXT = "sori-cm";
- public static final int DEFAULT_MAX_RESULTS = 100;
-
- public static final String RIO_CM_PUBLISHER_TITLE = "Open Services for Lifecycle Collaboration in Change Management";
- public static final String RIO_CM_PUBLISHER_IDENTIFIER = "open-services.net/sori/cm";
- public static final String RIO_CM_ICON = "oslc.png";
-
- // service segments
- public static final String SERVICE_PROVIDER_CATALOG = "catalog";
- public static final String SERVICE_CHANGEREQUEST = "changerequest";
- public static final String SERVICE_FACTORY_CHANGEREQUEST = "factory/changerequest";
- public static final String SERVICE_SELECTOR_CHANGEREQUEST = "selector/changerequest";
- public static final String SERVICE_CREATOR_CHANGEREQUEST = "creator/changerequest";
-
- //RIO
- public static final String RIO_CM_NAMESPACE = "http://open-services.net/rio/cm/";
- public static final String RIO_CM_PREFIX = "rio_cm";
- public static final String RIO_CM_XMLS_DECL = "\txmlns:" + RIO_CM_PREFIX + "=\"" + RIO_CM_NAMESPACE + "\"\n";
-
- public static final String RIO_CM_SELECTION_RESOURCE_WIDTH = "300px";
- public static final String RIO_CM_SELECTION_RESOURCE_HEIGHT = "300px";
- public static final String RIO_CM_CREATION_RESOURCE_WIDTH = "300px";
- public static final String RIO_CM_CREATION_RESOURCE_HEIGHT = "250px";
-
- // OSLC CM
- public static final String OSLC_CM_NAMESPACE = "http://open-services.net/ns/cm#";
- public static final String OSLC_CM_PREFIX = "oslc_cm";
-
- public static final String OSLC_CM_TERM_CHANGEREQUEST = "ChangeRequest";
- public static final String OSLC_CM_CHANGEREQUEST = OSLC_CM_NAMESPACE + OSLC_CM_TERM_CHANGEREQUEST;
- public static final String OSLC_CM_PTERM_CHANGEREQUEST = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_CHANGEREQUEST;
-
- // OSLC CM Change Requirements Properties
- public static final String OSLC_CM_STATUS_SUBMITTED = "Submitted";
- public static final String OSLC_CM_STATUS_IN_PROGRESS = "In Progress";
- public static final String OSLC_CM_STATUS_DONE = "Done";
- public static final String OSLC_CM_STATUS_FIXED = "Fixed";
-
- public static final String[] OSLC_CM_STATUS_VALUES = {
- OSLC_CM_STATUS_SUBMITTED,
- OSLC_CM_STATUS_IN_PROGRESS,
- OSLC_CM_STATUS_DONE,
- OSLC_CM_STATUS_FIXED
- };
-
-
- public static final String OSLC_CM_TERM_STATUS = "status";
- public static final String OSLC_CM_PTERM_STATUS = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_STATUS ;
- public static final String OSLC_CM_STATUS = OSLC_CM_NAMESPACE + OSLC_CM_TERM_STATUS;
-
- public static final String OSLC_CM_TERM_CLOSED = "closed";
- public static final String OSLC_CM_PTERM_CLOSED = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_CLOSED ;
- public static final String OSLC_CM_CLOSED = OSLC_CM_NAMESPACE + OSLC_CM_TERM_CLOSED;
-
- public static final String OSLC_CM_TERM_INPROGRESS = "inprogress";
- public static final String OSLC_CM_PTERM_INPROGRESS = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_INPROGRESS ;
- public static final String OSLC_CM_INPROGRESS = OSLC_CM_NAMESPACE + OSLC_CM_TERM_INPROGRESS;
-
- public static final String OSLC_CM_TERM_FIXED = "fixed";
- public static final String OSLC_CM_PTERM_FIXED = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_FIXED ;
- public static final String OSLC_CM_FIXED = OSLC_CM_NAMESPACE + OSLC_CM_TERM_FIXED;
-
- public static final String OSLC_CM_TERM_APPROVED = "approved";
- public static final String OSLC_CM_PTERM_APPROVED = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_APPROVED;
- public static final String OSLC_CM_APPROVED = OSLC_CM_NAMESPACE + OSLC_CM_TERM_APPROVED;
-
- public static final String OSLC_CM_TERM_REVIEWED = "reviewed";
- public static final String OSLC_CM_PTERM_REVIEWED = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_REVIEWED;
- public static final String OSLC_CM_REVIEWED = OSLC_CM_NAMESPACE + OSLC_CM_TERM_REVIEWED;
-
- public static final String OSLC_CM_TERM_VERIFIED = "verified";
- public static final String OSLC_CM_PTERM_VERIFIED = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_VERIFIED ;
- public static final String OSLC_CM_VERIFIED = OSLC_CM_NAMESPACE + OSLC_CM_TERM_VERIFIED;
-
- public static final String OSLC_CM_TERM_RELATEDCHANGEREQUEST = "relatedChangeRequest";
- public static final String OSLC_CM_PTERM_RELATEDCHANGEREQUEST = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_RELATEDCHANGEREQUEST;
- public static final String OSLC_CM_RELATEDCHANGEREQUEST = OSLC_CM_NAMESPACE + OSLC_CM_TERM_RELATEDCHANGEREQUEST;
-
- public static final String OSLC_CM_TERM_AFFECTSPLANITEM = "affectsPlanItem";
- public static final String OSLC_CM_PTERM_AFFECTSPLANITEM = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_AFFECTSPLANITEM;
- public static final String OSLC_CM_AFFECTSPLANITEM = OSLC_CM_NAMESPACE + OSLC_CM_TERM_AFFECTSPLANITEM;
-
- public static final String OSLC_CM_TERM_AFFECTEDBYDEFECT = "affectdByDefect";
- public static final String OSLC_CM_PTERM_AFFECTEDBYDEFECT = OSLC_CM_PREFIX + ':' + OSLC_CM_TERM_AFFECTEDBYDEFECT;
- public static final String OSLC_CM_AFFECTEDBYDEFECT = OSLC_CM_NAMESPACE + OSLC_CM_TERM_AFFECTEDBYDEFECT;
-
-}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CatalogService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CatalogService.java
index b581f96..92843d3 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CatalogService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CatalogService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -36,7 +36,7 @@ import org.eclipse.lyo.rio.services.RioServiceException;
import org.eclipse.lyo.rio.util.XmlUtils;
import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
+import org.eclipse.lyo.samples.excel.common.ConfigSingleton;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -73,7 +73,7 @@ public class CatalogService {
rdf.setAttribute("xmlns:" + IConstants.DCTERMS_PREFIX, IConstants.DCTERMS_NAMESPACE); //$NON-NLS-1$
rdf.setAttribute("xmlns:" + IConstants.OSLC_PREFIX, IConstants.OSLC_NAMESPACE); //$NON-NLS-1$
- Element sp = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_SERVICEPROVIDERCATALOG);
+ Element sp = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_TYPE_PTERM_SERVICEPROVIDERCATALOG);
rdf.appendChild(sp);
sp.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, about);
@@ -92,8 +92,17 @@ public class CatalogService {
for (Entry<String, String> prefixMapping : entries) {
appendPrefixDefinition(sp, prefixMapping.getKey(), prefixMapping.getValue());
}
- // append OSLC CM prefix
- appendPrefixDefinition(sp, ICmConstants.OSLC_CM_NAMESPACE, ICmConstants.OSLC_CM_PREFIX);
+
+ // append custom prefixes
+ ConfigSingleton config = ConfigSingleton.getInstance();
+ Map<String, String> nsPrefixes = config.getNsPrefixes();
+ entries = nsPrefixes.entrySet();
+ for (Entry<String, String> nsMapping : entries) {
+ String ns = nsMapping.getValue();
+ if(!predefinedMappings.containsKey(ns)){
+ appendPrefixDefinition(sp, ns, nsMapping.getKey());
+ }
+ }
// service resource
ResourceAdapter adapter = AdapterRegistry.getAdapter(getBaseUrl() + IConstants.SERVICE_SERVICES);
@@ -101,9 +110,13 @@ public class CatalogService {
List<String> providers = adapter.getContexts();
for(String providerId: providers){
Element service = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_SERVICEPROVIDER);
- String svcUri = getBaseUrl() + IConstants.SERVICE_SERVICES + '/' + ICmConstants.SERVICE_PROVIDER_CATALOG + '/' + providerId; //$NON-NLS-1$
- //String svcUri = getBaseUrl() + IConstants.SERVICE_SERVICES + '/' + providerId; //$NON-NLS-1$
- service.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, svcUri);
+ String svcUri = getBaseUrl() + IConstants.SERVICE_SERVICES + "/catalog/" + providerId;
+ Element serviceProvider = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_TYPE_PTERM_SERVICEPROVIDER);
+ serviceProvider.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, svcUri);
+ Element ‚”itle = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
+ ‚”itle.setTextContent("OSLC Excel Adapter");
+ serviceProvider.appendChild(‚”itle);
+ service.appendChild(serviceProvider);
sp.appendChild(service);
}
@@ -145,15 +158,17 @@ public class CatalogService {
Element elm = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
oslcPub.appendChild(elm);
- elm.setTextContent(ICmConstants.RIO_CM_PUBLISHER_TITLE);
+
+ ConfigSingleton config = ConfigSingleton.getInstance();
+ elm.setTextContent(config.getPublisherTitle());
elm = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_IDENTIFIER);
oslcPub.appendChild(elm);
- elm.setTextContent(ICmConstants.RIO_CM_PUBLISHER_IDENTIFIER);
+ elm.setTextContent(config.getPublisherIdentifier());
elm = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_ICON);
oslcPub.appendChild(elm);
- String iconUrl = getBaseUrl() + ICmConstants.RIO_CM_ICON;
+ String iconUrl = getBaseUrl() + config.getPublisherIcon();
elm.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, iconUrl);
}
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CreationFactoryService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CreationFactoryService.java
index c8a74d9..031b3cc 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CreationFactoryService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/CreationFactoryService.java
@@ -17,8 +17,6 @@
*******************************************************************************/
package org.eclipse.lyo.samples.excel.services.common;
-import java.net.URI;
-
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -26,53 +24,17 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import org.apache.commons.lang.NotImplementedException;
import org.eclipse.lyo.rio.core.IConstants;
-import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
-import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.Property;
-import com.hp.hpl.jena.rdf.model.ResIterator;
-import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.rdf.model.ResourceFactory;
-import com.hp.hpl.jena.rdf.model.Statement;
-import com.hp.hpl.jena.rdf.model.StmtIterator;
-@Path(ICmConstants.SERVICE_SERVICES + "/{projectId}/factory/changerequest")
+@Path(IConstants.SERVICE_SERVICES + "/{projectId}/factory/changerequest")
public class CreationFactoryService {
@POST
//@Consumes ({"application/rdf+xml", "application/xml"})
public Response doPost(@PathParam("projectId") String projectId, @Context UriInfo uriInfo, Model changeRequest) {
-
- ResIterator resIter = changeRequest.listSubjects();
- while(resIter.hasNext()){
- Resource resource = (Resource)resIter.nextResource();
- Property TITLE = ResourceFactory.createProperty("http://purl.org/dc/terms/", "title");
- Property STATUS = ResourceFactory.createProperty("http://open-services.net/ns/cm#", "status");
- Property CLOSED = ResourceFactory.createProperty("http://open-services.net/ns/cm#", "closed");
- System.out.println(resource);
- Statement title = resource.getProperty(TITLE);
- System.out.println(title.getObject());
- Statement status = resource.getProperty(STATUS);
- System.out.println(status.getObject());
- Statement closed = resource.getProperty(CLOSED);
- System.out.println(closed.getBoolean());
-
- String baseUrl = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES;
- ResourceAdapter adapter = AdapterRegistry.getAdapter(baseUrl);
-
-
- StmtIterator stmtIter = resource.listProperties();
- while(stmtIter.hasNext()){
- Statement statement = stmtIter.nextStatement();
-
- }
- }
-
- // Return HTTP response with status code 201 Created
- String uri = projectId + "/defects/";
- return Response.created(URI.create(uri)).build();
+ throw new NotImplementedException();
}
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/DownloadService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/DownloadService.java
deleted file mode 100644
index 0cf5820..0000000
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/DownloadService.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
- *
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *
- * Masaki Wakao
- * Yoshio Horiuchi
- * Kohji Ohsawa
- *******************************************************************************/
-package org.eclipse.lyo.samples.excel.services.common;
-
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.StreamingOutput;
-import javax.ws.rs.core.UriInfo;
-
-import org.eclipse.lyo.rio.core.IConstants;
-import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
-import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
-
-@Path(IConstants.SERVICE_SERVICES + "/{projectId}/download.xls/")
-public class DownloadService {
-
- @GET
- @Produces("application/octet-stream")
- public StreamingOutput getQueryResult(
- @Context UriInfo uriInfo,
- @PathParam("projectId") String projectId
- ){
- try{
- String baseUrl = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES;
- ResourceAdapter adapter = AdapterRegistry.getAdapter(baseUrl);
- String fileName = adapter.getDefaultExcelAbsolutePath();
-
- File file = new File(fileName);
-
- final byte[] bbuf = new byte[1024];
- final DataInputStream in = new DataInputStream(new FileInputStream(file));
-
- return new StreamingOutput() {
- public void write(OutputStream output) throws IOException, WebApplicationException {
- int length = 0;
- while ((in != null) && ((length = in.read(bbuf)) != -1)){
- output.write(bbuf, 0, length);
- }
- }
- };
- }catch (FileNotFoundException e){
- e.printStackTrace();
- }
- return null;
- }
-
-}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/QueryService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/QueryService.java
index 94cea86..7110de4 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/QueryService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/QueryService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -32,7 +32,7 @@ import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceSet;
-@Path(IConstants.SERVICE_SERVICES + "/{projectId}/query/changerequest")
+@Path(IConstants.SERVICE_SERVICES + "/{projectId}/query/{type}")
public class QueryService {
@GET
@@ -59,7 +59,7 @@ public class QueryService {
String baseUrl = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES;
ResourceAdapter adapter = AdapterRegistry.getAdapter(baseUrl);
// Model model = adapter.query(projectId, oslcPrefix, select);
- ResourceSet resultSet = adapter.query(projectId, oslcPrefix, select, oslcWhere, null, null);
+ ResourceSet resultSet = adapter.query(uriInfo.getAbsolutePath().toString(), projectId, oslcPrefix, select, oslcWhere, null, null);
return new ResourceSetWriter(resultSet);
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ResourceService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ResourceService.java
index 763efee..d9aedfa 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ResourceService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ResourceService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -21,7 +21,6 @@ import java.io.IOException;
import java.io.OutputStream;
import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
@@ -34,9 +33,6 @@ import org.eclipse.lyo.rio.core.IConstants;
import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceSet;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
-
-import com.hp.hpl.jena.rdf.model.Model;
//@Path(IConstants.SERVICE_SERVICES + "/{path:.+}")
@Path(IConstants.SERVICE_SERVICES + "/{projectId}/{excelfilename}/{id}")
@@ -53,15 +49,6 @@ public class ResourceService {
return new ResourceSetWriter(resultSet);
}
- @PUT
- //@Produces ({"application/rdf+xml", "application/xml"})
- public StreamingOutput updateResource (@Context UriInfo uriInfo, Model changeRequest){
- String baseUrl = uriInfo.getBaseUri().toString() + IConstants.SERVICE_SERVICES;
- ResourceAdapter adapter = AdapterRegistry.getAdapter(baseUrl);
- ResourceSet resultSet = adapter.getResource(uriInfo.getAbsolutePath().toString());
- return new ResourceSetWriter(resultSet);
- }
-
@GET
@Produces ({"application/x-oslc-compact+xml"})
public StreamingOutput doGet(@PathParam("projectId") String projectId, @PathParam("id") String id, @Context UriInfo uriInfo) {
@@ -69,8 +56,8 @@ public class ResourceService {
String shortTitle = "ChangeRequest " + id;
String resourceUri = uriInfo.getAbsolutePath().toString();
- String smUrl = uriInfo.getBaseUri() + "services/compact/" + ICmConstants.SERVICE_CHANGEREQUEST + "?uri=" + uriInfo.getAbsolutePath().toString() + "&amp;type=small&amp;projectId=" + projectId + "&amp;id=" + id;
- String lgUrl = uriInfo.getBaseUri() + "services/compact/" + ICmConstants.SERVICE_CHANGEREQUEST + "?uri=" + uriInfo.getAbsolutePath().toString() + "&amp;type=large&amp;projectId=" + projectId + "&amp;id=" + id;
+ String smUrl = uriInfo.getBaseUri() + "services/compact-rendering?uri=" + uriInfo.getAbsolutePath().toString() + "&amp;type=small&amp;projectId=" + projectId + "&amp;id=" + id;
+ String lgUrl = uriInfo.getBaseUri() + "services/compact-rendering?uri=" + uriInfo.getAbsolutePath().toString() + "&amp;type=large&amp;projectId=" + projectId + "&amp;id=" + id;
StringBuffer sb = new StringBuffer();
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ServiceProviderService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ServiceProviderService.java
index adb551c..85eff5e 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ServiceProviderService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/ServiceProviderService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -34,19 +34,12 @@ import org.eclipse.lyo.rio.core.IConstants;
import org.eclipse.lyo.rio.services.RioServiceException;
import org.eclipse.lyo.rio.store.RioStore;
import org.eclipse.lyo.rio.util.XmlUtils;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
+import org.eclipse.lyo.samples.excel.common.ConfigSingleton;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-@Path(IConstants.SERVICE_SERVICES + "/" + ICmConstants.SERVICE_PROVIDER_CATALOG + "/{projectId}")
+@Path(IConstants.SERVICE_SERVICES + "/catalog/{projectId}")
public class ServiceProviderService {
- //TODO
- public static final String OSLC_PTERM_SERVICE2 = IConstants.OSLC_PREFIX + ":Service";
- public static final String OSLC_PTERM_CREATIONFACTORY2 = IConstants.OSLC_PREFIX + ":CreationFactory";
- public static final String OSLC_PTERM_UI_DIALOG2 = IConstants.OSLC_PREFIX + ":Dialog";
- public static final String OSLC_PTERM_QUERYCAPABILITY2 = IConstants.OSLC_PREFIX + ":QueryCapability";
- public static final String OSLC_PTERM_PREFIXDEFINITION2 = IConstants.OSLC_PREFIX + ":PrefixDefinition";
-
private static final long serialVersionUID = 1889321991789915986L;
private String baseUrl;
@@ -80,7 +73,7 @@ public class ServiceProviderService {
rdf.setAttribute("xmlns:" + IConstants.DCTERMS_PREFIX, IConstants.DCTERMS_NAMESPACE); //$NON-NLS-1$
rdf.setAttribute("xmlns:" + IConstants.OSLC_PREFIX, IConstants.OSLC_NAMESPACE); //$NON-NLS-1$
- Element sp = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_SERVICEPROVIDER);
+ Element sp = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_TYPE_PTERM_SERVICEPROVIDER);
rdf.appendChild(sp);
sp.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, about);
@@ -99,37 +92,35 @@ public class ServiceProviderService {
for (Entry<String, String> prefixMapping : entries) {
appendPrefixDefinition(sp, prefixMapping.getKey(), prefixMapping.getValue());
}
- // append OSLC CM prefix
- appendPrefixDefinition(sp, ICmConstants.OSLC_CM_NAMESPACE, ICmConstants.OSLC_CM_PREFIX);
+ // append custom prefixes
+ ConfigSingleton config = ConfigSingleton.getInstance();
+ Map<String, String> nsPrefixes = config.getNsPrefixes();
+ entries = nsPrefixes.entrySet();
+ for (Entry<String, String> nsMapping : entries) {
+ String ns = nsMapping.getValue();
+ if(!predefinedMappings.containsKey(ns)){
+ appendPrefixDefinition(sp, ns, nsMapping.getKey());
+ }
+ }
Element service1 = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_SERVICE);
sp.appendChild(service1);
// add default generic services
- Element service2 = doc.createElementNS(IConstants.OSLC_NAMESPACE, OSLC_PTERM_SERVICE2);
+ Element service2 = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_TYPE_PTERM_SERVICE);
service1.appendChild(service2);
Element domain = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_DOMAIN);
- domain.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, ICmConstants.OSLC_CM_NAMESPACE);
+ domain.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, config.getServiceDomainDefault());
service2.appendChild(domain);
- String resShapeUrl = this.getBaseUrl() + "shapes?type=ChangeRequest"; //$NON-NLS-1$
- appendCreationFactory(service2, "CM Change Request Factory", "CM Factory", context + "/factory/changerequest",
- ICmConstants.OSLC_CM_CHANGEREQUEST, resShapeUrl, IConstants.OSLC_DEFAULT);
-
- resShapeUrl = null;
- appendQueryCapability(service2, "CM Change Request Query", "CM Query", context + "/query/changerequest",
- ICmConstants.OSLC_CM_CHANGEREQUEST, resShapeUrl, IConstants.OSLC_DEFAULT);
-/*
- appendUiDialog(service2, IConstants.OSLC_PTERM_UI_SELECTION1, "CM Resource Selector", "Picker",
- context + "/selector/changerequest", ICmConstants.OSLC_CM_CHANGEREQUEST,
- ICmConstants.SORI_CM_SELECTION_RESOURCE_WIDTH, ICmConstants.SORI_CM_SELECTION_RESOURCE_HEIGHT,
- IConstants.OSLC_DEFAULT);
-*/
- appendUiDialog(service2, IConstants.OSLC_TYPE_PTERM_CREATIONDIALOG, "CM Resource Creator", "Creator",
- context + "/creator", ICmConstants.OSLC_CM_CHANGEREQUEST,
- ICmConstants.RIO_CM_CREATION_RESOURCE_WIDTH, ICmConstants.RIO_CM_CREATION_RESOURCE_WIDTH,
- IConstants.OSLC_DEFAULT);
+ String resShapeUrl = null;
+ Map<String, String>queryCapabilities = config.getQueryCapabilities();
+ for(String uriLastSegment: queryCapabilities.keySet()){
+ String title = "Query for " + uriLastSegment;
+ appendQueryCapability(service2, title, title, context + "/query/" + uriLastSegment,
+ queryCapabilities.get(uriLastSegment), resShapeUrl, IConstants.OSLC_DEFAULT);
+ }
return XmlUtils.prettyPrint(doc);
} catch (Exception e) {
@@ -137,85 +128,6 @@ public class ServiceProviderService {
}
}
-
-
- private void appendCreationFactory(Element elm, String title, String label, String url,
- String rdfType, String shapeUrl, String usage ) {
-
- Document doc = elm.getOwnerDocument();
- Element cf1 = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_CREATIONFACTORY);
- elm.appendChild(cf1);
- Element cf2 = doc.createElementNS(IConstants.OSLC_NAMESPACE, OSLC_PTERM_CREATIONFACTORY2);
- cf1.appendChild(cf2);
-
- Element elmTitle = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
- cf2.appendChild(elmTitle);
- elmTitle.setTextContent(title);
-
- Element elmLabel = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_LABEL);
- cf2.appendChild(elmLabel);
- elmLabel.setTextContent(label);
-
- Element elmCreation = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_CREATION);
- cf2.appendChild(elmCreation);
- elmCreation.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, url);
-
- Element elmResType = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_RESOURCETYPE);
- cf2.appendChild(elmResType);
- elmResType.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, rdfType);
-
- if( shapeUrl != null ) {
- Element elmShape = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_RESOURCESHAPE);
- cf2.appendChild(elmShape);
- elmShape.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, shapeUrl);
- }
-
- if( usage != null ) {
- Element elmUsage = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_USAGE);
- cf2.appendChild(elmUsage);
- elmUsage.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, usage);
- }
- }
-
- private void appendUiDialog(Element elm, String dlgType, String title, String label, String url, String rdfType,
- String width, String height, String usage) {
-
- Document doc = elm.getOwnerDocument();
- Element ui1 = doc.createElementNS(IConstants.OSLC_NAMESPACE, dlgType);
- elm.appendChild(ui1);
- Element dlg = doc.createElementNS(IConstants.OSLC_NAMESPACE, OSLC_PTERM_UI_DIALOG2);
- ui1.appendChild(dlg);
-
- Element e = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
- dlg.appendChild(e);
- e.setTextContent(title);
-
- e = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_LABEL);
- dlg.appendChild(e);
- e.setTextContent(label);
-
- e = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_DIALOG);
- dlg.appendChild(e);
- e.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE,url);
-
- e = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_HINTHEIGHT);
- dlg.appendChild(e);
- e.setTextContent(height);
-
- e = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_HINTWIDTH);
- dlg.appendChild(e);
- e.setTextContent(width);
-
- e = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_RESOURCETYPE);
- dlg.appendChild(e);
- e.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE,rdfType);
-
- if( usage != null ) {
- e = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_USAGE);
- dlg.appendChild(e);
- e.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE,usage);
- }
- }
private void appendQueryCapability(Element elm, String title, String label, String url, String rdfType,
String shapeUrl, String usage) {
@@ -223,7 +135,7 @@ public class ServiceProviderService {
Document doc = elm.getOwnerDocument();
Element qc1 = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_QUERYCAPABILITY);
elm.appendChild(qc1);
- Element qc2 = doc.createElementNS(IConstants.OSLC_NAMESPACE, OSLC_PTERM_QUERYCAPABILITY2);
+ Element qc2 = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_TYPE_PTERM_QUERYCAPABILITY);
qc1.appendChild(qc2);
Element elmTitle = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
@@ -238,6 +150,10 @@ public class ServiceProviderService {
qc2.appendChild(elmQueryBase);
elmQueryBase.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, url);
+ Element resourceType = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_RESOURCETYPE);
+ resourceType.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, rdfType);
+ qc2.appendChild(resourceType);
+
if( shapeUrl != null ) {
Element elmShape = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_RESOURCESHAPE);
qc2.appendChild(elmShape);
@@ -256,7 +172,7 @@ public class ServiceProviderService {
Document doc = sp.getOwnerDocument();
Element pd1 = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_PREFIXDEFINITION);
sp.appendChild(pd1);
- Element pd2 = doc.createElementNS(IConstants.OSLC_NAMESPACE, OSLC_PTERM_PREFIXDEFINITION2);
+ Element pd2 = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_TYPE_PTERM_PREFIXDEFINITION);
pd1.appendChild(pd2);
Element elmPrefix = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_PREFIX);
@@ -278,15 +194,16 @@ public class ServiceProviderService {
Element elm = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
oslcPub.appendChild(elm);
- elm.setTextContent(ICmConstants.RIO_CM_PUBLISHER_TITLE);
+ ConfigSingleton config = ConfigSingleton.getInstance();
+ elm.setTextContent(config.getPublisherTitle());
elm = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_IDENTIFIER);
oslcPub.appendChild(elm);
- elm.setTextContent(ICmConstants.RIO_CM_PUBLISHER_IDENTIFIER);
+ elm.setTextContent(config.getPublisherIdentifier());
elm = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_ICON);
oslcPub.appendChild(elm);
- String iconUrl = getBaseUrl() + '/' + ICmConstants.RIO_CM_ICON;
+ String iconUrl = getBaseUrl() + config.getPublisherIcon();
elm.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, iconUrl);
}
diff --git a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/SparqlQueryService.java b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/SparqlQueryService.java
index 3340e36..26b494a 100644
--- a/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/SparqlQueryService.java
+++ b/org.eclipse.lyo.samples.excel/src/main/java/org/eclipse/lyo/samples/excel/services/common/SparqlQueryService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation.
+ * Copyright (c) 2011,2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -36,19 +36,18 @@ import javax.ws.rs.core.UriInfo;
import org.eclipse.lyo.rio.core.IConstants;
import org.eclipse.lyo.samples.excel.adapter.common.AdapterRegistry;
import org.eclipse.lyo.samples.excel.adapter.common.ResourceAdapter;
-import org.eclipse.lyo.samples.excel.common.ICmConstants;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
-@Path(ICmConstants.SERVICE_SERVICES + "/{projectId}/sparql")
+@Path(IConstants.SERVICE_SERVICES + "/{projectId}/sparql")
public class SparqlQueryService {
@POST
public StreamingOutput doPost(@PathParam("projectId") String projectId, @Context UriInfo uriInfo, MultivaluedMap<String, String> formData){
String queryExp = null;
try{
- queryExp = URLDecoder.decode( formData.getFirst("queryExp"), "utf-8" );
+ queryExp = URLDecoder.decode( formData.getFirst("queryExp"), IConstants.TEXT_ENCODING );
}catch(UnsupportedEncodingException e){
e.printStackTrace();
}
@@ -60,7 +59,7 @@ public class SparqlQueryService {
return new StreamingOutput() {
public void write(OutputStream output) throws IOException, WebApplicationException {
- byte[] out = html.getBytes();
+ byte[] out = html.getBytes(IConstants.TEXT_ENCODING);
output.write(out);
}
};
@@ -81,7 +80,7 @@ public class SparqlQueryService {
sb.append(" -->");
sb.append("<html>");
sb.append("<head>");
- sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">");
+ sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + IConstants.TEXT_ENCODING + "\">");
sb.append("<link rel=\"SHORTCUT ICON\" href=\"oslc.png\">");
sb.append("<title>RDF Store SPARQL</title>");
sb.append("</head>");
diff --git a/org.eclipse.lyo.samples.excel/src/main/webapp/index.html b/org.eclipse.lyo.samples.excel/src/main/webapp/index.html
index 2b269b2..45367cb 100644
--- a/org.eclipse.lyo.samples.excel/src/main/webapp/index.html
+++ b/org.eclipse.lyo.samples.excel/src/main/webapp/index.html
@@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
- Copyright (c) 2011 IBM Corporation.
+ Copyright (c) 2011,2013 IBM Corporation.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v. 1.0
which accompanies this distribution, and is available at
@@ -31,17 +31,11 @@ function dialog(url,width,height) {
<blockquote>
<p><a href="rest/catalog">Catalog</a> (OSLC Catalog document)</p>
<p><a href="rest/services/catalog/projectA">Service Provider</a> (OSLC ServiceProvider document)</p>
-<p><a href="javascript: dialog('changerequest_creator.html',450,250)">UI Change Request Creator</a> (Delegated UI resource creator)</p>
</blockquote>
<p><b>Server Admin Tasks and Utilities:</b></p>
<blockquote>
-<p><form action="rest/services/projectA/generate/changerequest" method="post">
-<input value="Generate" type="submit">&nbsp;<input type="text" name="count" value="30" size=3/>Resources
-</form>
-<p/>
<p><a href="sparql.html">SPARQL</a> (Free form SPARQL of RDF Store)</p>
-<p><a href="rest/services/projectA/list">Listing of Change Requests</a> (listing of all stored change request resources)</p>
-<p><a href="rest/services/projectA/download.xls">Download Excel File</a> (Downloading a generated Excel file)</p>
+<p><a href="rest/services/projectA/list">Listing of Resources</a> (listing of all stored resources)</p>
</blockquote>
</body>
</html> \ No newline at end of file
diff --git a/org.eclipse.lyo.samples.excel/src/main/webapp/sparql.html b/org.eclipse.lyo.samples.excel/src/main/webapp/sparql.html
index c4e9e7c..c74a501 100644
--- a/org.eclipse.lyo.samples.excel/src/main/webapp/sparql.html
+++ b/org.eclipse.lyo.samples.excel/src/main/webapp/sparql.html
@@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
- Copyright (c) 2011 IBM Corporation.
+ Copyright (c) 2011,2013 IBM Corporation.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v. 1.0
which accompanies this distribution, and is available at
@@ -22,7 +22,7 @@
<h3>SPARQL</h3>
<form action="rest/services/projectA/sparql" method="post">
<textarea rows="15" cols="100" name="queryExp">
-PREFIX dcterms:<http://purl.org/dc/elements/1.1/>
+PREFIX dcterms:<http://purl.org/dc/terms/>
SELECT ?title ?uri
WHERE {
?uri dcterms:title ?title.