You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by jb...@apache.org on 2015/11/23 17:32:29 UTC
[20/54] [abbrv] incubator-unomi git commit: Major changes : - Rename
all packages to org.apache.*
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/rest/src/main/java/org/jahia/unomi/geonames/rest/GeonamesEndPoint.java
----------------------------------------------------------------------
diff --git a/extensions/geonames/rest/src/main/java/org/jahia/unomi/geonames/rest/GeonamesEndPoint.java b/extensions/geonames/rest/src/main/java/org/jahia/unomi/geonames/rest/GeonamesEndPoint.java
deleted file mode 100644
index bde8cfc..0000000
--- a/extensions/geonames/rest/src/main/java/org/jahia/unomi/geonames/rest/GeonamesEndPoint.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jahia.unomi.geonames.rest;
-
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing;
-import org.jahia.unomi.geonames.services.GeonameEntry;
-import org.jahia.unomi.geonames.services.GeonamesService;
-import org.oasis_open.contextserver.api.PartialList;
-
-import javax.jws.WebMethod;
-import javax.jws.WebService;
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.PathSegment;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-@WebService
-@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
-@CrossOriginResourceSharing(
- allowAllOrigins = true,
- allowCredentials = true
-)
-public class GeonamesEndPoint {
-
- private GeonamesService geonamesService;
-
- public GeonamesEndPoint() {
- System.out.println("Initializing geonames service endpoint...");
- }
-
- @WebMethod(exclude = true)
- public void setGeonamesService(GeonamesService geonamesService) {
- this.geonamesService = geonamesService;
- }
-
- @GET
- @Path("/reverseGeoCode/{latlon}")
- public List<GeonameEntry> reverseGeoCode(@PathParam("latlon") String latlon, @HeaderParam("Accept-Language") String language) {
- String[] s = latlon.split(",");
- List<GeonameEntry> entries = geonamesService.reverseGeoCode(s[0], s[1]);
- translate(entries, new Locale(language));
- return entries;
- }
-
- @GET
- @Path("/entries/{items:.*}")
- public PartialList<GeonameEntry> getChildrenEntries(@PathParam("items") List<PathSegment> items, @HeaderParam("Accept-Language") String language) {
- List<String> l = new ArrayList<>();
- for (PathSegment item : items) {
- l.add(item.getPath());
- }
- PartialList<GeonameEntry> list = geonamesService.getChildrenEntries(l, 0, 999);
- translate(list.getList(), new Locale(language));
- return list;
- }
-
- @GET
- @Path("/cities/{items:.*}")
- public PartialList<GeonameEntry> getChildrenCities(@PathParam("items") List<PathSegment> items, @HeaderParam("Accept-Language") String language) {
- List<String> l = new ArrayList<>();
- for (PathSegment item : items) {
- l.add(item.getPath());
- }
- PartialList<GeonameEntry> list = geonamesService.getChildrenCities(l, 0, 999);
- translate(list.getList(), new Locale(language));
- return list;
- }
-
- @GET
- @Path("/hierarchy/{id}")
- public List<GeonameEntry> getHierarchy(@PathParam("id") String id, @HeaderParam("Accept-Language") String language) {
- List<GeonameEntry> list = geonamesService.getHierarchy(id);
- translate(list, new Locale(language));
- return list;
- }
-
- @GET
- @Path("/capitals/{id}")
- public List<GeonameEntry> getCapitalEntries(@PathParam("id") String id, @HeaderParam("Accept-Language") String language) {
- List<GeonameEntry> list = geonamesService.getCapitalEntries(id);
- translate(list, new Locale(language));
- return list;
- }
-
- private void translate(List<GeonameEntry> l, Locale locale) {
- for (GeonameEntry entry : l) {
- if (GeonamesService.COUNTRY_FEATURE_CODES.contains(entry.getFeatureCode())) {
- String name = new Locale("", entry.getCountryCode()).getDisplayCountry(locale);
- if (!StringUtils.isEmpty(name) && !name.equals(entry.getCountryCode())) {
- entry.setName(name);
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/extensions/geonames/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/geonames/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 55b41c1..590fef7 100644
--- a/extensions/geonames/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/extensions/geonames/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -30,7 +30,7 @@
</cxf:bus>
<bean id="cors-filter" class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter"/>
- <bean id="jacksonMapper" class="org.oasis_open.contextserver.persistence.spi.CustomObjectMapper"/>
+ <bean id="jacksonMapper" class="org.apache.unomi.persistence.spi.CustomObjectMapper"/>
<bean id="jaxb-provider" class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider">
<argument index="0" ref="jacksonMapper" type="com.fasterxml.jackson.databind.ObjectMapper "/>
<argument index="1" type="com.fasterxml.jackson.jaxrs.cfg.Annotations[]">
@@ -65,9 +65,9 @@
</jaxrs:serviceBeans>
</jaxrs:server>
- <reference id="geonamesService" interface="org.jahia.unomi.geonames.services.GeonamesService"/>
+ <reference id="geonamesService" interface="org.apache.unomi.geonames.services.GeonamesService"/>
- <bean id="geonamesServiceEndPoint" class="org.jahia.unomi.geonames.rest.GeonamesEndPoint">
+ <bean id="geonamesServiceEndPoint" class="org.apache.unomi.geonames.rest.GeonamesEndPoint">
<property name="geonamesService" ref="geonamesService"/>
</bean>
</blueprint>
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonameEntry.java
----------------------------------------------------------------------
diff --git a/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonameEntry.java b/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonameEntry.java
new file mode 100644
index 0000000..014a699
--- /dev/null
+++ b/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonameEntry.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.geonames.services;
+
+import org.apache.unomi.api.Item;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class GeonameEntry extends Item {
+ public static final String ITEM_TYPE = "geonameEntry";
+ public static final String INDEX_NAME = "geonames";
+ private static final long serialVersionUID = 1L;
+ protected String name;
+ protected String asciiname;
+ protected List<String> alternatenames;
+
+ protected Map<String, Double> location;
+
+ protected String featureClass;
+ protected String featureCode;
+ protected String countryCode;
+ protected List<String> cc2;
+ protected String admin1Code;
+ protected String admin2Code;
+ protected String admin3Code;
+ protected String admin4Code;
+ protected Integer population;
+ protected Integer elevation;
+ protected String dem;
+ protected String timezone;
+ protected Date modificationDate;
+
+ public GeonameEntry() {
+ }
+
+ public GeonameEntry(String geonameId, String name, String asciiname, Double lat, Double lon, String featureClass, String featureCode, String countryCode, List<String> cc2, String admin1Code, String admin2Code, String admin3Code, String admin4Code, Integer population, Integer elevation, String dem, String timezone, Date modificationDate) {
+ super(geonameId);
+ this.name = name;
+ this.asciiname = asciiname;
+// this.alternatenames = alternatenames;
+ this.location = new HashMap<>();
+ this.location.put("lat",lat);
+ this.location.put("lon",lon);
+ this.featureClass = featureClass;
+ this.featureCode = featureCode;
+ this.countryCode = countryCode;
+ this.cc2 = cc2;
+ this.admin1Code = admin1Code;
+ this.admin2Code = admin2Code;
+ this.admin3Code = admin3Code;
+ this.admin4Code = admin4Code;
+ this.population = population;
+ this.elevation = elevation;
+ this.dem = dem;
+ this.timezone = timezone;
+ this.modificationDate = modificationDate;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAsciiname() {
+ return asciiname;
+ }
+
+ public void setAsciiname(String asciiname) {
+ this.asciiname = asciiname;
+ }
+
+// public List<String> getAlternatenames() {
+// return alternatenames;
+// }
+//
+// public void setAlternatenames(List<String> alternatenames) {
+// this.alternatenames = alternatenames;
+// }
+
+ public Map<String, Double> getLocation() {
+ return location;
+ }
+
+ public void setLocation(Map<String, Double> location) {
+ this.location = location;
+ }
+
+ public String getFeatureClass() {
+ return featureClass;
+ }
+
+ public void setFeatureClass(String featureClass) {
+ this.featureClass = featureClass;
+ }
+
+ public String getFeatureCode() {
+ return featureCode;
+ }
+
+ public void setFeatureCode(String featureCode) {
+ this.featureCode = featureCode;
+ }
+
+ public String getCountryCode() {
+ return countryCode;
+ }
+
+ public void setCountryCode(String countryCode) {
+ this.countryCode = countryCode;
+ }
+
+ public List<String> getCc2() {
+ return cc2;
+ }
+
+ public void setCc2(List<String> cc2) {
+ this.cc2 = cc2;
+ }
+
+ public String getAdmin1Code() {
+ return admin1Code;
+ }
+
+ public void setAdmin1Code(String admin1Code) {
+ this.admin1Code = admin1Code;
+ }
+
+ public String getAdmin2Code() {
+ return admin2Code;
+ }
+
+ public void setAdmin2Code(String admin2Code) {
+ this.admin2Code = admin2Code;
+ }
+
+ public String getAdmin3Code() {
+ return admin3Code;
+ }
+
+ public void setAdmin3Code(String admin3Code) {
+ this.admin3Code = admin3Code;
+ }
+
+ public String getAdmin4Code() {
+ return admin4Code;
+ }
+
+ public void setAdmin4Code(String admin4Code) {
+ this.admin4Code = admin4Code;
+ }
+
+ public Integer getPopulation() {
+ return population;
+ }
+
+ public void setPopulation(Integer population) {
+ this.population = population;
+ }
+
+ public Integer getElevation() {
+ return elevation;
+ }
+
+ public void setElevation(Integer elevation) {
+ this.elevation = elevation;
+ }
+
+ public String getDem() {
+ return dem;
+ }
+
+ public void setDem(String dem) {
+ this.dem = dem;
+ }
+
+ public String getTimezone() {
+ return timezone;
+ }
+
+ public void setTimezone(String timezone) {
+ this.timezone = timezone;
+ }
+
+ public Date getModificationDate() {
+ return modificationDate;
+ }
+
+ public void setModificationDate(Date modificationDate) {
+ this.modificationDate = modificationDate;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonamesService.java
----------------------------------------------------------------------
diff --git a/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonamesService.java b/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonamesService.java
new file mode 100644
index 0000000..c3158fe
--- /dev/null
+++ b/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonamesService.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.geonames.services;
+
+import org.apache.unomi.api.PartialList;
+
+import java.util.Arrays;
+import java.util.List;
+
+public interface GeonamesService {
+ List<String> FEATURES_CLASSES = Arrays.asList("A", "P");
+ List<String> COUNTRY_FEATURE_CODES = Arrays.asList("PCL", "PCLD", "PCLF", "PCL", "PCLI", "PCLIX", "PCLS");
+ List<String> ADM1_FEATURE_CODES = Arrays.asList("ADM1");
+ List<String> ADM2_FEATURE_CODES = Arrays.asList("ADM2");
+ List<String> CITIES_FEATURE_CODES = Arrays.asList("PPL", "PPLA", "PPLA2", "PPLA3", "PPLA4", "PPLC", "PPLCH", "PPLF", "PPLG", "PPLL", "PPLR", "PPLR");
+ List<List<String>> ORDERED_FEATURES = Arrays.asList(COUNTRY_FEATURE_CODES, ADM1_FEATURE_CODES, ADM2_FEATURE_CODES, CITIES_FEATURE_CODES);
+
+ void importDatabase();
+
+ List<GeonameEntry> reverseGeoCode(String lat, String lon);
+
+ List<GeonameEntry> getHierarchy(String id);
+
+ PartialList<GeonameEntry> getChildrenEntries(List<String> items, int offset, int size);
+
+ PartialList<GeonameEntry> getChildrenCities(List<String> items, int offset, int size);
+
+ List<GeonameEntry> getCapitalEntries(String itemId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonamesServiceImpl.java
----------------------------------------------------------------------
diff --git a/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonamesServiceImpl.java b/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonamesServiceImpl.java
new file mode 100644
index 0000000..e89a630
--- /dev/null
+++ b/extensions/geonames/services/src/main/java/org/apache/unomi/geonames/services/GeonamesServiceImpl.java
@@ -0,0 +1,302 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.geonames.services;
+
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.conditions.Condition;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.persistence.spi.PersistenceService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class GeonamesServiceImpl implements GeonamesService {
+ public static final String GEOCODING_MAX_DISTANCE = "100km";
+ private static final Logger logger = LoggerFactory.getLogger(GeonamesServiceImpl.class.getName());
+ private DefinitionsService definitionsService;
+ private PersistenceService persistenceService;
+
+ private String pathToGeonamesDatabase;
+ private Boolean forceDbImport;
+
+ public void setForceDbImport(Boolean forceDbImport) {
+ this.forceDbImport = forceDbImport;
+ }
+
+ public void setDefinitionsService(DefinitionsService definitionsService) {
+ this.definitionsService = definitionsService;
+ }
+
+ public void setPersistenceService(PersistenceService persistenceService) {
+ this.persistenceService = persistenceService;
+ }
+
+ public void setPathToGeonamesDatabase(String pathToGeonamesDatabase) {
+ this.pathToGeonamesDatabase = pathToGeonamesDatabase;
+ }
+
+ public void start() {
+ importDatabase();
+ }
+
+ public void stop() {
+ }
+
+ public void importDatabase() {
+ if (!persistenceService.createIndex("geonames")) {
+ if (forceDbImport) {
+ persistenceService.removeIndex("geonames");
+ persistenceService.createIndex("geonames");
+ logger.info("Geonames index removed and recreated");
+ } else if (persistenceService.getAllItemsCount(GeonameEntry.ITEM_TYPE) > 0) {
+ return;
+ }
+ } else {
+ logger.info("Geonames index created");
+ }
+
+ if (pathToGeonamesDatabase == null) {
+ logger.info("No geonames DB provided");
+ return;
+ }
+ final File f = new File(pathToGeonamesDatabase);
+ if (f.exists()) {
+ Timer t = new Timer();
+ t.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(f));
+ ZipEntry zipEntry = zipInputStream.getNextEntry();
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(zipInputStream, "UTF-8"));
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ String line;
+ logger.info("Starting to import geonames database ...");
+ while ((line = reader.readLine()) != null) {
+ String[] values = line.split("\t");
+
+ if (FEATURES_CLASSES.contains(values[6])) {
+ GeonameEntry geonameEntry = new GeonameEntry(values[0], values[1], values[2],
+ StringUtils.isEmpty(values[4]) ? null : Double.parseDouble(values[4]),
+ StringUtils.isEmpty(values[5]) ? null : Double.parseDouble(values[5]),
+ values[6], values[7], values[8],
+ Arrays.asList(values[9].split(",")),
+ values[10], values[11], values[12], values[13],
+ StringUtils.isEmpty(values[14]) ? null : Integer.parseInt(values[14]),
+ StringUtils.isEmpty(values[15]) ? null : Integer.parseInt(values[15]),
+ values[16], values[17],
+ sdf.parse(values[18]));
+
+ persistenceService.save(geonameEntry);
+ }
+ }
+ logger.info("Geonames database imported");
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ }, 5000);
+ }
+ }
+
+ public List<GeonameEntry> getHierarchy(String itemId) {
+ return getHierarchy(persistenceService.load(itemId, GeonameEntry.class));
+ }
+
+ public List<GeonameEntry> getHierarchy(GeonameEntry entry) {
+ List<GeonameEntry> entries = new ArrayList<>();
+ entries.add(entry);
+
+ List<Condition> l = new ArrayList<>();
+ Condition andCondition = new Condition();
+ andCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
+ andCondition.setParameter("operator", "and");
+ andCondition.setParameter("subConditions", l);
+
+ Condition featureCodeCondition = new Condition();
+ featureCodeCondition.setConditionType(definitionsService.getConditionType("sessionPropertyCondition"));
+ featureCodeCondition.setParameter("propertyName", "featureCode");
+ featureCodeCondition.setParameter("comparisonOperator", "in");
+ l.add(featureCodeCondition);
+
+ PartialList<GeonameEntry> country = buildHierarchy(andCondition, featureCodeCondition, "countryCode", entry.getCountryCode(), COUNTRY_FEATURE_CODES, 0, 1);
+
+ if (!StringUtils.isEmpty(entry.getAdmin1Code())) {
+ PartialList<GeonameEntry> adm1 = buildHierarchy(andCondition, featureCodeCondition, "admin1Code", entry.getAdmin1Code(), ADM1_FEATURE_CODES, 0, 1);
+
+ if (!StringUtils.isEmpty(entry.getAdmin2Code())) {
+ PartialList<GeonameEntry> adm2 = buildHierarchy(andCondition, featureCodeCondition, "admin2Code", entry.getAdmin2Code(), ADM2_FEATURE_CODES, 0, 1);
+
+ if (!adm2.getList().isEmpty()) {
+ entries.add(adm2.get(0));
+ }
+ }
+ if (!adm1.getList().isEmpty()) {
+ entries.add(adm1.get(0));
+ }
+
+ }
+
+ if (!country.getList().isEmpty()) {
+ entries.add(country.get(0));
+ }
+ return entries;
+ }
+
+ private PartialList<GeonameEntry> buildHierarchy(Condition andCondition, Condition featureCodeCondition, String featurePropertyName, String featureValue, List<String> featuresCode, int offset, int size) {
+ featureCodeCondition.setParameter("propertyValues", featuresCode);
+
+ List<Condition> l = (List<Condition>) andCondition.getParameter("subConditions");
+ Condition condition = getPropertyCondition(featurePropertyName, "propertyValue", featureValue, "equals");
+ l.add(condition);
+
+ return persistenceService.query(andCondition, null, GeonameEntry.class, offset, size);
+ }
+
+ public List<GeonameEntry> reverseGeoCode(String lat, String lon) {
+ List<Condition> l = new ArrayList<Condition>();
+ Condition andCondition = new Condition();
+ andCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
+ andCondition.setParameter("operator", "and");
+ andCondition.setParameter("subConditions", l);
+
+
+ Condition geoLocation = new Condition();
+ geoLocation.setConditionType(definitionsService.getConditionType("geoLocationByPointSessionCondition"));
+ geoLocation.setParameter("type", "circle");
+ geoLocation.setParameter("circleLatitude", Double.parseDouble(lat));
+ geoLocation.setParameter("circleLongitude", Double.parseDouble(lon));
+ geoLocation.setParameter("distance", GEOCODING_MAX_DISTANCE);
+ l.add(geoLocation);
+
+ l.add(getPropertyCondition("featureCode", "propertyValues", CITIES_FEATURE_CODES, "in"));
+
+ PartialList<GeonameEntry> list = persistenceService.query(andCondition, "geo:location:" + lat + ":" + lon, GeonameEntry.class, 0, 1);
+ if (!list.getList().isEmpty()) {
+ return getHierarchy(list.getList().get(0));
+ }
+ return Collections.emptyList();
+ }
+
+
+ public PartialList<GeonameEntry> getChildrenEntries(List<String> items, int offset, int size) {
+ Condition andCondition = getItemsInChildrenQuery(items, CITIES_FEATURE_CODES);
+ Condition featureCodeCondition = ((List<Condition>) andCondition.getParameter("subConditions")).get(0);
+ int level = items.size();
+
+ featureCodeCondition.setParameter("propertyValues", ORDERED_FEATURES.get(level));
+ PartialList<GeonameEntry> r = persistenceService.query(andCondition, null, GeonameEntry.class, offset, size);
+ while (r.size() == 0 && level < ORDERED_FEATURES.size() - 1) {
+ level++;
+ featureCodeCondition.setParameter("propertyValues", ORDERED_FEATURES.get(level));
+ r = persistenceService.query(andCondition, null, GeonameEntry.class, offset, size);
+ }
+ return r;
+ }
+
+ public PartialList<GeonameEntry> getChildrenCities(List<String> items, int offset, int size) {
+ return persistenceService.query(getItemsInChildrenQuery(items, CITIES_FEATURE_CODES), null, GeonameEntry.class, offset, size);
+ }
+
+ private Condition getItemsInChildrenQuery(List<String> items, List<String> featureCodes) {
+ List<Condition> l = new ArrayList<Condition>();
+ Condition andCondition = new Condition();
+ andCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
+ andCondition.setParameter("operator", "and");
+ andCondition.setParameter("subConditions", l);
+
+ Condition featureCodeCondition = getPropertyCondition("featureCode", "propertyValues", featureCodes, "in");
+ l.add(featureCodeCondition);
+
+ if (items.size() > 0) {
+ l.add(getPropertyCondition("countryCode", "propertyValue", items.get(0), "equals"));
+ }
+ if (items.size() > 1) {
+ l.add(getPropertyCondition("admin1Code", "propertyValue", items.get(1), "equals"));
+ }
+ if (items.size() > 2) {
+ l.add(getPropertyCondition("admin2Code", "propertyValue", items.get(2), "equals"));
+ }
+ return andCondition;
+ }
+
+ public List<GeonameEntry> getCapitalEntries(String itemId) {
+ GeonameEntry entry = persistenceService.load(itemId, GeonameEntry.class);
+ List<String> featureCodes;
+
+ List<Condition> l = new ArrayList<Condition>();
+ Condition andCondition = new Condition();
+ andCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
+ andCondition.setParameter("operator", "and");
+ andCondition.setParameter("subConditions", l);
+
+ l.add(getPropertyCondition("countryCode", "propertyValue", entry.getCountryCode(), "equals"));
+
+ if (COUNTRY_FEATURE_CODES.contains(entry.getFeatureCode())) {
+ featureCodes = Arrays.asList("PPLC");
+ } else if (ADM1_FEATURE_CODES.contains(entry.getFeatureCode())) {
+ featureCodes = Arrays.asList("PPLA", "PPLC");
+ l.add(getPropertyCondition("admin1Code", "propertyValue", entry.getAdmin1Code(), "equals"));
+ } else if (ADM2_FEATURE_CODES.contains(entry.getFeatureCode())) {
+ featureCodes = Arrays.asList("PPLA2", "PPLA", "PPLC");
+ l.add(getPropertyCondition("admin1Code", "propertyValue", entry.getAdmin1Code(), "equals"));
+ l.add(getPropertyCondition("admin2Code", "propertyValue", entry.getAdmin2Code(), "equals"));
+ } else {
+ return Collections.emptyList();
+ }
+
+ Condition featureCodeCondition = new Condition();
+ featureCodeCondition.setConditionType(definitionsService.getConditionType("sessionPropertyCondition"));
+ featureCodeCondition.setParameter("propertyName", "featureCode");
+ featureCodeCondition.setParameter("propertyValues", featureCodes);
+ featureCodeCondition.setParameter("comparisonOperator", "in");
+ l.add(featureCodeCondition);
+ List<GeonameEntry> entries = persistenceService.query(andCondition, null, GeonameEntry.class);
+ if (entries.size() == 0) {
+ featureCodeCondition.setParameter("propertyValues", CITIES_FEATURE_CODES);
+ entries = persistenceService.query(andCondition, "population:desc", GeonameEntry.class, 0, 1).getList();
+ }
+ if (entries.size() > 0) {
+ return getHierarchy(entries.get(0));
+ }
+ return Collections.emptyList();
+ }
+
+ private Condition getPropertyCondition(String name, String propertyValueField, Object value, String operator) {
+ Condition condition = new Condition();
+ condition.setConditionType(definitionsService.getConditionType("sessionPropertyCondition"));
+ condition.setParameter("propertyName", name);
+ condition.setParameter(propertyValueField, value);
+ condition.setParameter("comparisonOperator", operator);
+ return condition;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonameEntry.java
----------------------------------------------------------------------
diff --git a/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonameEntry.java b/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonameEntry.java
deleted file mode 100644
index cd2fa3b..0000000
--- a/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonameEntry.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jahia.unomi.geonames.services;
-
-import org.oasis_open.contextserver.api.Item;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class GeonameEntry extends Item {
- public static final String ITEM_TYPE = "geonameEntry";
- public static final String INDEX_NAME = "geonames";
- private static final long serialVersionUID = 1L;
- protected String name;
- protected String asciiname;
- protected List<String> alternatenames;
-
- protected Map<String, Double> location;
-
- protected String featureClass;
- protected String featureCode;
- protected String countryCode;
- protected List<String> cc2;
- protected String admin1Code;
- protected String admin2Code;
- protected String admin3Code;
- protected String admin4Code;
- protected Integer population;
- protected Integer elevation;
- protected String dem;
- protected String timezone;
- protected Date modificationDate;
-
- public GeonameEntry() {
- }
-
- public GeonameEntry(String geonameId, String name, String asciiname, Double lat, Double lon, String featureClass, String featureCode, String countryCode, List<String> cc2, String admin1Code, String admin2Code, String admin3Code, String admin4Code, Integer population, Integer elevation, String dem, String timezone, Date modificationDate) {
- super(geonameId);
- this.name = name;
- this.asciiname = asciiname;
-// this.alternatenames = alternatenames;
- this.location = new HashMap<>();
- this.location.put("lat",lat);
- this.location.put("lon",lon);
- this.featureClass = featureClass;
- this.featureCode = featureCode;
- this.countryCode = countryCode;
- this.cc2 = cc2;
- this.admin1Code = admin1Code;
- this.admin2Code = admin2Code;
- this.admin3Code = admin3Code;
- this.admin4Code = admin4Code;
- this.population = population;
- this.elevation = elevation;
- this.dem = dem;
- this.timezone = timezone;
- this.modificationDate = modificationDate;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getAsciiname() {
- return asciiname;
- }
-
- public void setAsciiname(String asciiname) {
- this.asciiname = asciiname;
- }
-
-// public List<String> getAlternatenames() {
-// return alternatenames;
-// }
-//
-// public void setAlternatenames(List<String> alternatenames) {
-// this.alternatenames = alternatenames;
-// }
-
- public Map<String, Double> getLocation() {
- return location;
- }
-
- public void setLocation(Map<String, Double> location) {
- this.location = location;
- }
-
- public String getFeatureClass() {
- return featureClass;
- }
-
- public void setFeatureClass(String featureClass) {
- this.featureClass = featureClass;
- }
-
- public String getFeatureCode() {
- return featureCode;
- }
-
- public void setFeatureCode(String featureCode) {
- this.featureCode = featureCode;
- }
-
- public String getCountryCode() {
- return countryCode;
- }
-
- public void setCountryCode(String countryCode) {
- this.countryCode = countryCode;
- }
-
- public List<String> getCc2() {
- return cc2;
- }
-
- public void setCc2(List<String> cc2) {
- this.cc2 = cc2;
- }
-
- public String getAdmin1Code() {
- return admin1Code;
- }
-
- public void setAdmin1Code(String admin1Code) {
- this.admin1Code = admin1Code;
- }
-
- public String getAdmin2Code() {
- return admin2Code;
- }
-
- public void setAdmin2Code(String admin2Code) {
- this.admin2Code = admin2Code;
- }
-
- public String getAdmin3Code() {
- return admin3Code;
- }
-
- public void setAdmin3Code(String admin3Code) {
- this.admin3Code = admin3Code;
- }
-
- public String getAdmin4Code() {
- return admin4Code;
- }
-
- public void setAdmin4Code(String admin4Code) {
- this.admin4Code = admin4Code;
- }
-
- public Integer getPopulation() {
- return population;
- }
-
- public void setPopulation(Integer population) {
- this.population = population;
- }
-
- public Integer getElevation() {
- return elevation;
- }
-
- public void setElevation(Integer elevation) {
- this.elevation = elevation;
- }
-
- public String getDem() {
- return dem;
- }
-
- public void setDem(String dem) {
- this.dem = dem;
- }
-
- public String getTimezone() {
- return timezone;
- }
-
- public void setTimezone(String timezone) {
- this.timezone = timezone;
- }
-
- public Date getModificationDate() {
- return modificationDate;
- }
-
- public void setModificationDate(Date modificationDate) {
- this.modificationDate = modificationDate;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonamesService.java
----------------------------------------------------------------------
diff --git a/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonamesService.java b/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonamesService.java
deleted file mode 100644
index 950df51..0000000
--- a/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonamesService.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jahia.unomi.geonames.services;
-
-import org.oasis_open.contextserver.api.PartialList;
-
-import java.util.Arrays;
-import java.util.List;
-
-public interface GeonamesService {
- List<String> FEATURES_CLASSES = Arrays.asList("A", "P");
- List<String> COUNTRY_FEATURE_CODES = Arrays.asList("PCL", "PCLD", "PCLF", "PCL", "PCLI", "PCLIX", "PCLS");
- List<String> ADM1_FEATURE_CODES = Arrays.asList("ADM1");
- List<String> ADM2_FEATURE_CODES = Arrays.asList("ADM2");
- List<String> CITIES_FEATURE_CODES = Arrays.asList("PPL", "PPLA", "PPLA2", "PPLA3", "PPLA4", "PPLC", "PPLCH", "PPLF", "PPLG", "PPLL", "PPLR", "PPLR");
- List<List<String>> ORDERED_FEATURES = Arrays.asList(COUNTRY_FEATURE_CODES, ADM1_FEATURE_CODES, ADM2_FEATURE_CODES, CITIES_FEATURE_CODES);
-
- void importDatabase();
-
- List<GeonameEntry> reverseGeoCode(String lat, String lon);
-
- List<GeonameEntry> getHierarchy(String id);
-
- PartialList<GeonameEntry> getChildrenEntries(List<String> items, int offset, int size);
-
- PartialList<GeonameEntry> getChildrenCities(List<String> items, int offset, int size);
-
- List<GeonameEntry> getCapitalEntries(String itemId);
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonamesServiceImpl.java
----------------------------------------------------------------------
diff --git a/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonamesServiceImpl.java b/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonamesServiceImpl.java
deleted file mode 100644
index 74a142e..0000000
--- a/extensions/geonames/services/src/main/java/org/jahia/unomi/geonames/services/GeonamesServiceImpl.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jahia.unomi.geonames.services;
-
-
-import org.apache.commons.lang3.StringUtils;
-import org.oasis_open.contextserver.api.PartialList;
-import org.oasis_open.contextserver.api.conditions.Condition;
-import org.oasis_open.contextserver.api.services.DefinitionsService;
-import org.oasis_open.contextserver.persistence.spi.PersistenceService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-public class GeonamesServiceImpl implements GeonamesService {
- public static final String GEOCODING_MAX_DISTANCE = "100km";
- private static final Logger logger = LoggerFactory.getLogger(GeonamesServiceImpl.class.getName());
- private DefinitionsService definitionsService;
- private PersistenceService persistenceService;
-
- private String pathToGeonamesDatabase;
- private Boolean forceDbImport;
-
- public void setForceDbImport(Boolean forceDbImport) {
- this.forceDbImport = forceDbImport;
- }
-
- public void setDefinitionsService(DefinitionsService definitionsService) {
- this.definitionsService = definitionsService;
- }
-
- public void setPersistenceService(PersistenceService persistenceService) {
- this.persistenceService = persistenceService;
- }
-
- public void setPathToGeonamesDatabase(String pathToGeonamesDatabase) {
- this.pathToGeonamesDatabase = pathToGeonamesDatabase;
- }
-
- public void start() {
- importDatabase();
- }
-
- public void stop() {
- }
-
- public void importDatabase() {
- if (!persistenceService.createIndex("geonames")) {
- if (forceDbImport) {
- persistenceService.removeIndex("geonames");
- persistenceService.createIndex("geonames");
- logger.info("Geonames index removed and recreated");
- } else if (persistenceService.getAllItemsCount(GeonameEntry.ITEM_TYPE) > 0) {
- return;
- }
- } else {
- logger.info("Geonames index created");
- }
-
- if (pathToGeonamesDatabase == null) {
- logger.info("No geonames DB provided");
- return;
- }
- final File f = new File(pathToGeonamesDatabase);
- if (f.exists()) {
- Timer t = new Timer();
- t.schedule(new TimerTask() {
- @Override
- public void run() {
- try {
- ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(f));
- ZipEntry zipEntry = zipInputStream.getNextEntry();
-
- BufferedReader reader = new BufferedReader(new InputStreamReader(zipInputStream, "UTF-8"));
-
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- String line;
- logger.info("Starting to import geonames database ...");
- while ((line = reader.readLine()) != null) {
- String[] values = line.split("\t");
-
- if (FEATURES_CLASSES.contains(values[6])) {
- GeonameEntry geonameEntry = new GeonameEntry(values[0], values[1], values[2],
- StringUtils.isEmpty(values[4]) ? null : Double.parseDouble(values[4]),
- StringUtils.isEmpty(values[5]) ? null : Double.parseDouble(values[5]),
- values[6], values[7], values[8],
- Arrays.asList(values[9].split(",")),
- values[10], values[11], values[12], values[13],
- StringUtils.isEmpty(values[14]) ? null : Integer.parseInt(values[14]),
- StringUtils.isEmpty(values[15]) ? null : Integer.parseInt(values[15]),
- values[16], values[17],
- sdf.parse(values[18]));
-
- persistenceService.save(geonameEntry);
- }
- }
- logger.info("Geonames database imported");
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- }
- }, 5000);
- }
- }
-
- public List<GeonameEntry> getHierarchy(String itemId) {
- return getHierarchy(persistenceService.load(itemId, GeonameEntry.class));
- }
-
- public List<GeonameEntry> getHierarchy(GeonameEntry entry) {
- List<GeonameEntry> entries = new ArrayList<>();
- entries.add(entry);
-
- List<Condition> l = new ArrayList<>();
- Condition andCondition = new Condition();
- andCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
- andCondition.setParameter("operator", "and");
- andCondition.setParameter("subConditions", l);
-
- Condition featureCodeCondition = new Condition();
- featureCodeCondition.setConditionType(definitionsService.getConditionType("sessionPropertyCondition"));
- featureCodeCondition.setParameter("propertyName", "featureCode");
- featureCodeCondition.setParameter("comparisonOperator", "in");
- l.add(featureCodeCondition);
-
- PartialList<GeonameEntry> country = buildHierarchy(andCondition, featureCodeCondition, "countryCode", entry.getCountryCode(), COUNTRY_FEATURE_CODES, 0, 1);
-
- if (!StringUtils.isEmpty(entry.getAdmin1Code())) {
- PartialList<GeonameEntry> adm1 = buildHierarchy(andCondition, featureCodeCondition, "admin1Code", entry.getAdmin1Code(), ADM1_FEATURE_CODES, 0, 1);
-
- if (!StringUtils.isEmpty(entry.getAdmin2Code())) {
- PartialList<GeonameEntry> adm2 = buildHierarchy(andCondition, featureCodeCondition, "admin2Code", entry.getAdmin2Code(), ADM2_FEATURE_CODES, 0, 1);
-
- if (!adm2.getList().isEmpty()) {
- entries.add(adm2.get(0));
- }
- }
- if (!adm1.getList().isEmpty()) {
- entries.add(adm1.get(0));
- }
-
- }
-
- if (!country.getList().isEmpty()) {
- entries.add(country.get(0));
- }
- return entries;
- }
-
- private PartialList<GeonameEntry> buildHierarchy(Condition andCondition, Condition featureCodeCondition, String featurePropertyName, String featureValue, List<String> featuresCode, int offset, int size) {
- featureCodeCondition.setParameter("propertyValues", featuresCode);
-
- List<Condition> l = (List<Condition>) andCondition.getParameter("subConditions");
- Condition condition = getPropertyCondition(featurePropertyName, "propertyValue", featureValue, "equals");
- l.add(condition);
-
- return persistenceService.query(andCondition, null, GeonameEntry.class, offset, size);
- }
-
- public List<GeonameEntry> reverseGeoCode(String lat, String lon) {
- List<Condition> l = new ArrayList<Condition>();
- Condition andCondition = new Condition();
- andCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
- andCondition.setParameter("operator", "and");
- andCondition.setParameter("subConditions", l);
-
-
- Condition geoLocation = new Condition();
- geoLocation.setConditionType(definitionsService.getConditionType("geoLocationByPointSessionCondition"));
- geoLocation.setParameter("type", "circle");
- geoLocation.setParameter("circleLatitude", Double.parseDouble(lat));
- geoLocation.setParameter("circleLongitude", Double.parseDouble(lon));
- geoLocation.setParameter("distance", GEOCODING_MAX_DISTANCE);
- l.add(geoLocation);
-
- l.add(getPropertyCondition("featureCode", "propertyValues", CITIES_FEATURE_CODES, "in"));
-
- PartialList<GeonameEntry> list = persistenceService.query(andCondition, "geo:location:" + lat + ":" + lon, GeonameEntry.class, 0, 1);
- if (!list.getList().isEmpty()) {
- return getHierarchy(list.getList().get(0));
- }
- return Collections.emptyList();
- }
-
-
- public PartialList<GeonameEntry> getChildrenEntries(List<String> items, int offset, int size) {
- Condition andCondition = getItemsInChildrenQuery(items, GeonamesService.CITIES_FEATURE_CODES);
- Condition featureCodeCondition = ((List<Condition>) andCondition.getParameter("subConditions")).get(0);
- int level = items.size();
-
- featureCodeCondition.setParameter("propertyValues", ORDERED_FEATURES.get(level));
- PartialList<GeonameEntry> r = persistenceService.query(andCondition, null, GeonameEntry.class, offset, size);
- while (r.size() == 0 && level < ORDERED_FEATURES.size() - 1) {
- level++;
- featureCodeCondition.setParameter("propertyValues", ORDERED_FEATURES.get(level));
- r = persistenceService.query(andCondition, null, GeonameEntry.class, offset, size);
- }
- return r;
- }
-
- public PartialList<GeonameEntry> getChildrenCities(List<String> items, int offset, int size) {
- return persistenceService.query(getItemsInChildrenQuery(items, GeonamesService.CITIES_FEATURE_CODES), null, GeonameEntry.class, offset, size);
- }
-
- private Condition getItemsInChildrenQuery(List<String> items, List<String> featureCodes) {
- List<Condition> l = new ArrayList<Condition>();
- Condition andCondition = new Condition();
- andCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
- andCondition.setParameter("operator", "and");
- andCondition.setParameter("subConditions", l);
-
- Condition featureCodeCondition = getPropertyCondition("featureCode", "propertyValues", featureCodes, "in");
- l.add(featureCodeCondition);
-
- if (items.size() > 0) {
- l.add(getPropertyCondition("countryCode", "propertyValue", items.get(0), "equals"));
- }
- if (items.size() > 1) {
- l.add(getPropertyCondition("admin1Code", "propertyValue", items.get(1), "equals"));
- }
- if (items.size() > 2) {
- l.add(getPropertyCondition("admin2Code", "propertyValue", items.get(2), "equals"));
- }
- return andCondition;
- }
-
- public List<GeonameEntry> getCapitalEntries(String itemId) {
- GeonameEntry entry = persistenceService.load(itemId, GeonameEntry.class);
- List<String> featureCodes;
-
- List<Condition> l = new ArrayList<Condition>();
- Condition andCondition = new Condition();
- andCondition.setConditionType(definitionsService.getConditionType("booleanCondition"));
- andCondition.setParameter("operator", "and");
- andCondition.setParameter("subConditions", l);
-
- l.add(getPropertyCondition("countryCode", "propertyValue", entry.getCountryCode(), "equals"));
-
- if (COUNTRY_FEATURE_CODES.contains(entry.getFeatureCode())) {
- featureCodes = Arrays.asList("PPLC");
- } else if (ADM1_FEATURE_CODES.contains(entry.getFeatureCode())) {
- featureCodes = Arrays.asList("PPLA", "PPLC");
- l.add(getPropertyCondition("admin1Code", "propertyValue", entry.getAdmin1Code(), "equals"));
- } else if (ADM2_FEATURE_CODES.contains(entry.getFeatureCode())) {
- featureCodes = Arrays.asList("PPLA2", "PPLA", "PPLC");
- l.add(getPropertyCondition("admin1Code", "propertyValue", entry.getAdmin1Code(), "equals"));
- l.add(getPropertyCondition("admin2Code", "propertyValue", entry.getAdmin2Code(), "equals"));
- } else {
- return Collections.emptyList();
- }
-
- Condition featureCodeCondition = new Condition();
- featureCodeCondition.setConditionType(definitionsService.getConditionType("sessionPropertyCondition"));
- featureCodeCondition.setParameter("propertyName", "featureCode");
- featureCodeCondition.setParameter("propertyValues", featureCodes);
- featureCodeCondition.setParameter("comparisonOperator", "in");
- l.add(featureCodeCondition);
- List<GeonameEntry> entries = persistenceService.query(andCondition, null, GeonameEntry.class);
- if (entries.size() == 0) {
- featureCodeCondition.setParameter("propertyValues", CITIES_FEATURE_CODES);
- entries = persistenceService.query(andCondition, "population:desc", GeonameEntry.class, 0, 1).getList();
- }
- if (entries.size() > 0) {
- return getHierarchy(entries.get(0));
- }
- return Collections.emptyList();
- }
-
- private Condition getPropertyCondition(String name, String propertyValueField, Object value, String operator) {
- Condition condition = new Condition();
- condition.setConditionType(definitionsService.getConditionType("sessionPropertyCondition"));
- condition.setParameter("propertyName", name);
- condition.setParameter(propertyValueField, value);
- condition.setParameter("comparisonOperator", operator);
- return condition;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/geonames/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/extensions/geonames/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/geonames/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 0da9bae..95a7366 100644
--- a/extensions/geonames/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/extensions/geonames/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -30,14 +30,15 @@
</cm:property-placeholder>
<reference id="persistenceService"
- interface="org.oasis_open.contextserver.persistence.spi.PersistenceService"/>
+ interface="org.apache.unomi.persistence.spi.PersistenceService"/>
- <reference id="definitionsService" interface="org.oasis_open.contextserver.api.services.DefinitionsService"/>
+ <reference id="definitionsService" interface="org.apache.unomi.api.services.DefinitionsService"/>
<!-- User List service -->
- <bean id="geonamesServiceImpl" class="org.jahia.unomi.geonames.services.GeonamesServiceImpl" init-method="start" destroy-method="stop">
+ <bean id="geonamesServiceImpl" class="org.apache.unomi.geonames.services.GeonamesServiceImpl" init-method="start"
+ destroy-method="stop">
<property name="persistenceService" ref="persistenceService"/>
<property name="definitionsService" ref="definitionsService"/>
<property name="pathToGeonamesDatabase" value="${request.geonamesDatabase.location}"/>
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/rest/src/main/java/org/apache/unomi/lists/rest/UserListServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/rest/src/main/java/org/apache/unomi/lists/rest/UserListServiceEndPoint.java b/extensions/lists-extension/rest/src/main/java/org/apache/unomi/lists/rest/UserListServiceEndPoint.java
new file mode 100644
index 0000000..a4eb8c9
--- /dev/null
+++ b/extensions/lists-extension/rest/src/main/java/org/apache/unomi/lists/rest/UserListServiceEndPoint.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.lists.rest;
+
+import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.query.Query;
+import org.apache.unomi.lists.UserList;
+import org.apache.unomi.services.UserListService;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+
+
+/**
+ * @author Christophe Laprun
+ */
+@WebService
+@Produces(MediaType.APPLICATION_JSON)
+@CrossOriginResourceSharing(
+ allowAllOrigins = true,
+ allowCredentials = true
+)
+public class UserListServiceEndPoint {
+ private UserListService userListService;
+
+ public UserListServiceEndPoint() {
+ System.out.println("Initializing user list service endpoint...");
+ }
+
+ @WebMethod(exclude = true)
+ public void setUserListService(UserListService userListService) {
+ this.userListService = userListService;
+ }
+
+ @GET
+ @Path("/")
+ public PartialList<Metadata> getListMetadatas() {
+ return userListService.getListMetadatas(0, 50, null);
+ }
+
+ @POST
+ @Path("/query")
+ public PartialList<Metadata> getListMetadatas(Query query) {
+ return userListService.getListMetadatas(query);
+ }
+
+ @GET
+ @Path("/{listId}")
+ public UserList load(@PathParam("listId") String listId) {
+ return userListService.load(listId);
+ }
+
+ @POST
+ @Path("/")
+ public void save(UserList list) {
+ userListService.save(list);
+ }
+
+ @DELETE
+ @Path("/{listId}")
+ public void delete(@PathParam("listId") String listId) {
+ userListService.delete(listId);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/rest/src/main/java/org/jahia/unomi/rest/UserListServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/rest/src/main/java/org/jahia/unomi/rest/UserListServiceEndPoint.java b/extensions/lists-extension/rest/src/main/java/org/jahia/unomi/rest/UserListServiceEndPoint.java
deleted file mode 100644
index c0d344d..0000000
--- a/extensions/lists-extension/rest/src/main/java/org/jahia/unomi/rest/UserListServiceEndPoint.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jahia.unomi.rest;
-
-import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing;
-import org.jahia.unomi.lists.UserList;
-import org.jahia.unomi.services.UserListService;
-import org.oasis_open.contextserver.api.Metadata;
-import org.oasis_open.contextserver.api.PartialList;
-import org.oasis_open.contextserver.api.query.Query;
-
-import javax.jws.WebMethod;
-import javax.jws.WebService;
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-
-
-/**
- * @author Christophe Laprun
- */
-@WebService
-@Produces(MediaType.APPLICATION_JSON)
-@CrossOriginResourceSharing(
- allowAllOrigins = true,
- allowCredentials = true
-)
-public class UserListServiceEndPoint {
- private UserListService userListService;
-
- public UserListServiceEndPoint() {
- System.out.println("Initializing user list service endpoint...");
- }
-
- @WebMethod(exclude = true)
- public void setUserListService(UserListService userListService) {
- this.userListService = userListService;
- }
-
- @GET
- @Path("/")
- public PartialList<Metadata> getListMetadatas() {
- return userListService.getListMetadatas(0, 50, null);
- }
-
- @POST
- @Path("/query")
- public PartialList<Metadata> getListMetadatas(Query query) {
- return userListService.getListMetadatas(query);
- }
-
- @GET
- @Path("/{listId}")
- public UserList load(@PathParam("listId") String listId) {
- return userListService.load(listId);
- }
-
- @POST
- @Path("/")
- public void save(UserList list) {
- userListService.save(list);
- }
-
- @DELETE
- @Path("/{listId}")
- public void delete(@PathParam("listId") String listId) {
- userListService.delete(listId);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/lists-extension/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 327c91d..7b7e626 100644
--- a/extensions/lists-extension/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/extensions/lists-extension/rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -30,7 +30,7 @@
</cxf:bus>
<bean id="cors-filter" class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter"/>
- <bean id="jacksonMapper" class="org.oasis_open.contextserver.persistence.spi.CustomObjectMapper"/>
+ <bean id="jacksonMapper" class="org.apache.unomi.persistence.spi.CustomObjectMapper"/>
<bean id="jaxb-provider" class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider">
<argument index="0" ref="jacksonMapper" type="com.fasterxml.jackson.databind.ObjectMapper "/>
<argument index="1" type="com.fasterxml.jackson.jaxrs.cfg.Annotations[]">
@@ -65,9 +65,9 @@
</jaxrs:serviceBeans>
</jaxrs:server>
- <reference id="userListService" interface="org.jahia.unomi.services.UserListService"/>
+ <reference id="userListService" interface="org.apache.unomi.services.UserListService"/>
- <bean id="userListServiceEndPoint" class="org.jahia.unomi.rest.UserListServiceEndPoint">
+ <bean id="userListServiceEndPoint" class="org.apache.unomi.lists.rest.UserListServiceEndPoint">
<property name="userListService" ref="userListService"/>
</bean>
</blueprint>
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/services/src/main/java/org/apache/unomi/lists/UserList.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/services/src/main/java/org/apache/unomi/lists/UserList.java b/extensions/lists-extension/services/src/main/java/org/apache/unomi/lists/UserList.java
new file mode 100644
index 0000000..e9ab509
--- /dev/null
+++ b/extensions/lists-extension/services/src/main/java/org/apache/unomi/lists/UserList.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.lists;
+
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.MetadataItem;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author Christophe Laprun
+ */
+@XmlRootElement
+public class UserList extends MetadataItem {
+ public static final String ITEM_TYPE = "userList";
+ private static final long serialVersionUID = 1L;
+
+ public UserList() {
+ }
+
+ public UserList(Metadata metadata) {
+ super(metadata);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListService.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListService.java b/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListService.java
new file mode 100644
index 0000000..b561337
--- /dev/null
+++ b/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListService.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.services;
+
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.query.Query;
+import org.apache.unomi.lists.UserList;
+
+
+/**
+ * @author Christophe Laprun
+ */
+public interface UserListService {
+
+ PartialList<Metadata> getListMetadatas(int offset, int size, String sortBy);
+
+ PartialList<Metadata> getListMetadatas(Query query);
+
+ UserList load(String listId);
+
+ void save(UserList list);
+
+ void delete(String listId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListServiceImpl.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListServiceImpl.java b/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListServiceImpl.java
new file mode 100644
index 0000000..e60cb19
--- /dev/null
+++ b/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListServiceImpl.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.services;
+
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.conditions.Condition;
+import org.apache.unomi.api.query.Query;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.lists.UserList;
+import org.apache.unomi.persistence.spi.PersistenceService;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Christophe Laprun
+ */
+public class UserListServiceImpl implements UserListService {
+ private PersistenceService persistenceService;
+
+ private DefinitionsService definitionsService;
+
+ public void setPersistenceService(PersistenceService persistenceService) {
+ this.persistenceService = persistenceService;
+ }
+
+ public void setDefinitionsService(DefinitionsService definitionsService) {
+ this.definitionsService = definitionsService;
+ }
+
+ public PartialList<Metadata> getListMetadatas(int offset, int size, String sortBy) {
+ PartialList<UserList> userLists = persistenceService.getAllItems(UserList.class, offset, size, sortBy);
+ List<Metadata> metadata = new LinkedList<>();
+ for (UserList definition : userLists.getList()) {
+ metadata.add(definition.getMetadata());
+ }
+ return new PartialList<>(metadata, userLists.getOffset(), userLists.getPageSize(), userLists.getTotalSize());
+ }
+
+ public PartialList<Metadata> getListMetadatas(Query query) {
+ if(query.isForceRefresh()){
+ persistenceService.refresh();
+ }
+ definitionsService.resolveConditionType(query.getCondition());
+ PartialList<UserList> userLists = persistenceService.query(query.getCondition(), query.getSortby(), UserList.class, query.getOffset(), query.getLimit());
+ List<Metadata> metadata = new LinkedList<>();
+ for (UserList definition : userLists.getList()) {
+ metadata.add(definition.getMetadata());
+ }
+ return new PartialList<>(metadata, userLists.getOffset(), userLists.getPageSize(), userLists.getTotalSize());
+ }
+
+ @Override
+ public UserList load(String listId) {
+ return persistenceService.load(listId, UserList.class);
+ }
+
+ @Override
+ public void save(UserList list) {
+ persistenceService.save(list);
+ }
+
+ @Override
+ public void delete(String listId) {
+ Condition query = new Condition(definitionsService.getConditionType("profilePropertyCondition"));
+ query.setParameter("propertyName", "systemProperties.lists");
+ query.setParameter("comparisonOperator", "equals");
+ query.setParameter("propertyValue", listId);
+
+ List<Profile> profiles = persistenceService.query(query, null, Profile.class);
+ Map<String, Object> profileProps;
+ for (Profile p : profiles) {
+ profileProps = p.getSystemProperties();
+ if(profileProps != null && profileProps.get("lists") != null) {
+ int index = ((List) profileProps.get("lists")).indexOf(listId);
+ if(index != -1){
+ ((List) profileProps.get("lists")).remove(index);
+ persistenceService.update(p.getItemId(), null, Profile.class, "systemProperties", profileProps);
+ }
+ }
+ }
+
+ persistenceService.remove(listId, UserList.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/services/src/main/java/org/jahia/unomi/lists/UserList.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/services/src/main/java/org/jahia/unomi/lists/UserList.java b/extensions/lists-extension/services/src/main/java/org/jahia/unomi/lists/UserList.java
deleted file mode 100644
index 8072657..0000000
--- a/extensions/lists-extension/services/src/main/java/org/jahia/unomi/lists/UserList.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jahia.unomi.lists;
-
-import org.oasis_open.contextserver.api.Metadata;
-import org.oasis_open.contextserver.api.MetadataItem;
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- * @author Christophe Laprun
- */
-@XmlRootElement
-public class UserList extends MetadataItem {
- public static final String ITEM_TYPE = "userList";
- private static final long serialVersionUID = 1L;
-
- public UserList() {
- }
-
- public UserList(Metadata metadata) {
- super(metadata);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/services/src/main/java/org/jahia/unomi/services/UserListService.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/services/src/main/java/org/jahia/unomi/services/UserListService.java b/extensions/lists-extension/services/src/main/java/org/jahia/unomi/services/UserListService.java
deleted file mode 100644
index ff8d50d..0000000
--- a/extensions/lists-extension/services/src/main/java/org/jahia/unomi/services/UserListService.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jahia.unomi.services;
-
-import org.jahia.unomi.lists.UserList;
-import org.oasis_open.contextserver.api.Metadata;
-import org.oasis_open.contextserver.api.PartialList;
-import org.oasis_open.contextserver.api.query.Query;
-
-
-/**
- * @author Christophe Laprun
- */
-public interface UserListService {
-
- PartialList<Metadata> getListMetadatas(int offset, int size, String sortBy);
-
- PartialList<Metadata> getListMetadatas(Query query);
-
- UserList load(String listId);
-
- void save(UserList list);
-
- void delete(String listId);
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/services/src/main/java/org/jahia/unomi/services/UserListServiceImpl.java
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/services/src/main/java/org/jahia/unomi/services/UserListServiceImpl.java b/extensions/lists-extension/services/src/main/java/org/jahia/unomi/services/UserListServiceImpl.java
deleted file mode 100644
index 54d85e8..0000000
--- a/extensions/lists-extension/services/src/main/java/org/jahia/unomi/services/UserListServiceImpl.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jahia.unomi.services;
-
-import org.jahia.unomi.lists.UserList;
-import org.oasis_open.contextserver.api.Metadata;
-import org.oasis_open.contextserver.api.PartialList;
-import org.oasis_open.contextserver.api.Profile;
-import org.oasis_open.contextserver.api.conditions.Condition;
-import org.oasis_open.contextserver.api.query.Query;
-import org.oasis_open.contextserver.api.services.DefinitionsService;
-import org.oasis_open.contextserver.persistence.spi.PersistenceService;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Christophe Laprun
- */
-public class UserListServiceImpl implements UserListService {
- private PersistenceService persistenceService;
-
- private DefinitionsService definitionsService;
-
- public void setPersistenceService(PersistenceService persistenceService) {
- this.persistenceService = persistenceService;
- }
-
- public void setDefinitionsService(DefinitionsService definitionsService) {
- this.definitionsService = definitionsService;
- }
-
- public PartialList<Metadata> getListMetadatas(int offset, int size, String sortBy) {
- PartialList<UserList> userLists = persistenceService.getAllItems(UserList.class, offset, size, sortBy);
- List<Metadata> metadata = new LinkedList<>();
- for (UserList definition : userLists.getList()) {
- metadata.add(definition.getMetadata());
- }
- return new PartialList<>(metadata, userLists.getOffset(), userLists.getPageSize(), userLists.getTotalSize());
- }
-
- public PartialList<Metadata> getListMetadatas(Query query) {
- if(query.isForceRefresh()){
- persistenceService.refresh();
- }
- definitionsService.resolveConditionType(query.getCondition());
- PartialList<UserList> userLists = persistenceService.query(query.getCondition(), query.getSortby(), UserList.class, query.getOffset(), query.getLimit());
- List<Metadata> metadata = new LinkedList<>();
- for (UserList definition : userLists.getList()) {
- metadata.add(definition.getMetadata());
- }
- return new PartialList<>(metadata, userLists.getOffset(), userLists.getPageSize(), userLists.getTotalSize());
- }
-
- @Override
- public UserList load(String listId) {
- return persistenceService.load(listId, UserList.class);
- }
-
- @Override
- public void save(UserList list) {
- persistenceService.save(list);
- }
-
- @Override
- public void delete(String listId) {
- Condition query = new Condition(definitionsService.getConditionType("profilePropertyCondition"));
- query.setParameter("propertyName", "systemProperties.lists");
- query.setParameter("comparisonOperator", "equals");
- query.setParameter("propertyValue", listId);
-
- List<Profile> profiles = persistenceService.query(query, null, Profile.class);
- Map<String, Object> profileProps;
- for (Profile p : profiles) {
- profileProps = p.getSystemProperties();
- if(profileProps != null && profileProps.get("lists") != null) {
- int index = ((List) profileProps.get("lists")).indexOf(listId);
- if(index != -1){
- ((List) profileProps.get("lists")).remove(index);
- persistenceService.update(p.getItemId(), null, Profile.class, "systemProperties", profileProps);
- }
- }
- }
-
- persistenceService.remove(listId, UserList.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/lists-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/extensions/lists-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/lists-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 6556a79..9b1f44b 100644
--- a/extensions/lists-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/extensions/lists-extension/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -20,14 +20,14 @@
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<reference id="persistenceService"
- interface="org.oasis_open.contextserver.persistence.spi.PersistenceService"/>
+ interface="org.apache.unomi.persistence.spi.PersistenceService"/>
- <reference id="definitionsService" interface="org.oasis_open.contextserver.api.services.DefinitionsService"/>
+ <reference id="definitionsService" interface="org.apache.unomi.api.services.DefinitionsService"/>
<!-- User List service -->
- <bean id="userListServiceImpl" class="org.jahia.unomi.services.UserListServiceImpl">
+ <bean id="userListServiceImpl" class="org.apache.unomi.services.UserListServiceImpl">
<property name="persistenceService" ref="persistenceService"/>
<property name="definitionsService" ref="definitionsService"/>
</bean>
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java b/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java
new file mode 100644
index 0000000..45a6146
--- /dev/null
+++ b/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.privacy.rest;
+
+import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing;
+import org.apache.unomi.api.ServerInfo;
+import org.apache.unomi.api.services.PrivacyService;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.NewCookie;
+import javax.ws.rs.core.Response;
+import java.util.List;
+
+/**
+ * REST API end point for privacy service
+ */
+@WebService
+@Produces(MediaType.APPLICATION_JSON)
+@CrossOriginResourceSharing(
+ allowAllOrigins = true,
+ allowCredentials = true
+)
+public class PrivacyServiceEndPoint {
+
+ private PrivacyService privacyService;
+
+ @WebMethod(exclude = true)
+ public void setPrivacyService(PrivacyService privacyService) {
+ this.privacyService = privacyService;
+ }
+
+ @GET
+ @Path("/info")
+ public ServerInfo getServerInfo() {
+ return privacyService.getServerInfo();
+ }
+
+ @DELETE
+ @Path("/profiles/{profileId}")
+ public Response deleteProfileData(@PathParam("profileId") String profileId, @QueryParam("withData") @DefaultValue("false") boolean withData) {
+ if (withData) {
+ privacyService.deleteProfileData(profileId);
+ } else {
+ privacyService.deleteProfile(profileId);
+ }
+ return Response.ok().build();
+ }
+
+ @POST
+ @Path("/profiles/{profileId}/anonymize")
+ public Response anonymizeBrowsingData(@PathParam("profileId") String profileId) {
+ String newProfileId = privacyService.anonymizeBrowsingData(profileId);
+ if (!profileId.equals(newProfileId)) {
+ return Response.ok()
+ .cookie(new NewCookie("context-profile-id", newProfileId, "/", null, null, NewCookie.DEFAULT_MAX_AGE, false))
+ .entity(newProfileId)
+ .build();
+ }
+ return Response.serverError().build();
+ }
+
+ @GET
+ @Path("/profiles/{profileId}/anonymous")
+ public Boolean isAnonymous(@PathParam("profileId") String profileId) {
+ return privacyService.isAnonymous(profileId);
+ }
+
+ @POST
+ @Path("/profiles/{profileId}/anonymous")
+ public Response activateAnonymousSurfing(@PathParam("profileId") String profileId) {
+ privacyService.setAnonymous(profileId, true);
+ return Response.ok().build();
+ }
+
+ @DELETE
+ @Path("/profiles/{profileId}/anonymous")
+ public Response deactivateAnonymousSurfing(@PathParam("profileId") String profileId) {
+ privacyService.setAnonymous(profileId, false);
+ return Response.ok().build();
+ }
+
+ @GET
+ @Path("/profiles/{profileId}/eventFilters")
+ public List<String> getEventFilters(@PathParam("profileId") String profileId) {
+ return privacyService.getFilteredEventTypes(profileId);
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/profiles/{profileId}/eventFilters")
+ public Response setEventFilters(@PathParam("profileId") String profileId, List<String> eventFilters) {
+ privacyService.setFilteredEventTypes(profileId, eventFilters);
+ return Response.ok().build();
+ }
+
+ @DELETE
+ @Path("/profiles/{profileId}/properties/{propertyName}")
+ public Response removeProperty(@PathParam("profileId") String profileId, @PathParam("propertyName") String propertyName) {
+ privacyService.removeProperty(profileId, propertyName);
+ return Response.ok().build();
+ }
+
+}