From 3c246b21b1389d0270f0a6c1fbc675a7d9b21ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 6 Nov 2014 16:25:54 +0100 Subject: [PATCH 01/69] Update Dependencies --- .classpath | 83 ------- .gitignore | 4 + .project | 27 -- .settings/org.eclipse.jdt.core.prefs | 6 - .settings/org.eclipse.wst.common.component | 232 ------------------ ....eclipse.wst.common.project.facet.core.xml | 7 - .settings/org.maven.ide.eclipse.prefs | 8 - pom.xml | 68 +++-- .../helpers/AttributeAssignmentResolver.java | 6 +- .../util/MarketplaceHibernateDao.java | 8 +- .../resources/spring/database/Hibernate.xml | 44 ++-- 11 files changed, 58 insertions(+), 435 deletions(-) delete mode 100644 .classpath create mode 100644 .gitignore delete mode 100644 .project delete mode 100644 .settings/org.eclipse.jdt.core.prefs delete mode 100644 .settings/org.eclipse.wst.common.component delete mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml delete mode 100644 .settings/org.maven.ide.eclipse.prefs diff --git a/.classpath b/.classpath deleted file mode 100644 index 8c09f27..0000000 --- a/.classpath +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4874fbf --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target +.classpath +.project +.settings diff --git a/.project b/.project deleted file mode 100644 index 62c869e..0000000 --- a/.project +++ /dev/null @@ -1,27 +0,0 @@ - - - FiwareMarketplace - NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - - - - org.eclipse.jdt.core.javabuilder - - - org.eclipse.wst.common.project.facet.core.builder - - - org.eclipse.wst.validation.validationbuilder - - - org.maven.ide.eclipse.maven2Builder - - - - org.maven.ide.eclipse.maven2Nature - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.jdt.core.javanature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jem.workbench.JavaEMFNature - - \ No newline at end of file diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 7c76982..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,6 +0,0 @@ -#Tue Mar 20 10:49:18 CET 2012 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component deleted file mode 100644 index 887e7e3..0000000 --- a/.settings/org.eclipse.wst.common.component +++ /dev/null @@ -1,232 +0,0 @@ - - - - - - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - uses - - - - - \ No newline at end of file diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml deleted file mode 100644 index f3728ad..0000000 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.settings/org.maven.ide.eclipse.prefs b/.settings/org.maven.ide.eclipse.prefs deleted file mode 100644 index 1b1848e..0000000 --- a/.settings/org.maven.ide.eclipse.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Mon Feb 20 13:17:23 CET 2012 -activeProfiles= -eclipse.preferences.version=1 -fullBuildGoals=process-test-resources -resolveWorkspaceProjects=true -resourceFilterGoals=process-resources resources\:testResources -skipCompilerPlugin=true -version=1 diff --git a/pom.xml b/pom.xml index 2ab6e44..070c979 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,11 @@ 4.0.0 + org.fiware.apps.marketplace FiwareMarketplace war - 3.2.1-SNAPSHOT + 4.1.1-SNAPSHOT FiwareMarketplace Webapp http://maven.apache.org @@ -38,7 +39,7 @@ junit junit - 4.8.2 + 4.11 test @@ -47,26 +48,26 @@ org.jboss.resteasy resteasy-jaxrs - 2.2.1.GA + 3.0.10.Final org.jboss.resteasy resteasy-jackson-provider - 2.2.1.GA + 3.0.10.Final org.jboss.resteasy resteasy-multipart-provider - 2.2.1.GA + 3.0.10.Final org.jboss.resteasy resteasy-jaxb-provider - 2.2.0.GA + 3.0.10.Final @@ -74,7 +75,7 @@ org.jboss.resteasy resteasy-oauth - 2.2.0.GA + 3.0.10.Final @@ -84,45 +85,45 @@ org.apache.httpcomponents httpclient - 4.0.1 + 4.3.5 compile org.apache.httpcomponents httpmime - 4.0.1 + 4.3.5 compile javax.activation activation - 1.1 + 1.1.1 com.hp.hpl.jena arq - 2.8.7 + 2.8.8 org.springframework spring-core - 3.0.5.RELEASE + 4.1.1.RELEASE org.springframework spring-context - 3.0.5.RELEASE + 4.1.1.RELEASE org.springframework spring-orm - 3.0.5.RELEASE + 4.1.1.RELEASE @@ -136,14 +137,14 @@ cglib cglib - 2.2 + 3.1 mysql mysql-connector-java - 5.1.9 + 5.1.33 @@ -151,20 +152,7 @@ org.hibernate hibernate-core - 3.6.0.Final - - - - - org.hibernate - hibernate-tools - 3.2.3.GA - - - - org.hibernate - hibernate-commons-annotations - 3.2.0.Final + 4.3.7.Final @@ -177,19 +165,19 @@ commons-logging commons-logging - 1.1.1 + 1.2 - commons-collections - commons-collections - 3.2.1 + org.apache.commons + commons-collections4 + 4.0 - antlr - antlr - 2.7.7 + org.antlr + antlr4 + 4.3 @@ -203,7 +191,11 @@ 1.6 1.6 - 2.3.2 + 3.2 + + + maven-dependency-plugin + 2.9 diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeAssignmentResolver.java b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeAssignmentResolver.java index 18c2325..f630290 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeAssignmentResolver.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeAssignmentResolver.java @@ -74,7 +74,7 @@ protected static int[] reduceArray(int[] arrayToReduce, int rowCount, int colCou protected static class HungarianAlgorithm { // Implementation of the Hungarian a.k.a. Munkres-Kuhn algorithm - // Solves the maximum weighted bipartite matching problem (a.k.a. marriage problem) in O(n³) + // Solves the maximum weighted bipartite matching problem (a.k.a. marriage problem) in O(n) // Based on the following source, but strongly refactored // http://www.koders.com/java/fid2C93F1FAE2F786A091D64ED84F2A67D2659EC4F2.aspx?s=249#L29 @@ -465,8 +465,8 @@ private static int[] performHungarianAlgorithm(double[][] costs) { List eliminatedRows = new ArrayList(); List eliminatedCols = new ArrayList(); - // Suche eine Kombination von Nullen derart, dass in jeder Zeile und in jeder Spalte nur eine Null ausgewählt ist. - // Steht in einer Zeile oder Spalte nur eine einzige Null, so muss sie natürlich in die Lösung. + // Suche eine Kombination von Nullen derart, dass in jeder Zeile und in jeder Spalte nur eine Null ausgewhlt ist. + // Steht in einer Zeile oder Spalte nur eine einzige Null, so muss sie natrlich in die Lsung. // This does not seem to work properly... diff --git a/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java b/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java index 642c19c..928ed8e 100644 --- a/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java +++ b/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java @@ -2,14 +2,12 @@ import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - - +import org.springframework.orm.hibernate4.support.HibernateDaoSupport; public class MarketplaceHibernateDao extends HibernateDaoSupport{ + @Autowired - public void anyMethodName(SessionFactory sessionFactory) - { + public void anyMethodName(SessionFactory sessionFactory) { setSessionFactory(sessionFactory); } } diff --git a/src/main/resources/spring/database/Hibernate.xml b/src/main/resources/spring/database/Hibernate.xml index bf846b2..e810e10 100644 --- a/src/main/resources/spring/database/Hibernate.xml +++ b/src/main/resources/spring/database/Hibernate.xml @@ -1,33 +1,25 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-4.1.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-4.1.xsd"> + - - - - - - + + + + + + + org.hibernate.dialect.MySQLDialect true - - - - - - org.fiware.apps.marketplace.model.Service - org.fiware.apps.marketplace.model.Store - org.fiware.apps.marketplace.model.Localuser - org.fiware.apps.marketplace.model.Rating - org.fiware.apps.marketplace.model.RatingCategory - org.fiware.apps.marketplace.model.RatingCategoryEntry - org.fiware.apps.marketplace.model.RatingObject - org.fiware.apps.marketplace.model.RatingObjectCategory - - + - + + \ No newline at end of file From 14931f713aea8b8e9228d336eea3f20961dfc85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 6 Nov 2014 16:47:08 +0100 Subject: [PATCH 02/69] Password is not sent anymore. Minor improvements in SW quality --- .../apps/marketplace/model/Localuser.java | 16 +++++++++---- .../fiware/apps/marketplace/model/Rating.java | 24 ++++++++++--------- .../marketplace/model/RatingCategory.java | 7 +++--- .../model/RatingCategoryEntry.java | 9 ++++--- .../apps/marketplace/model/RatingObject.java | 17 +++++++++---- .../model/RatingObjectCategory.java | 5 +++- .../marketplace/model/SearchResultEntry.java | 5 ---- .../model/SearchResultEntryMatch.java | 3 +-- .../apps/marketplace/model/Service.java | 10 +++++++- .../model/ServiceManifestation.java | 1 + .../fiware/apps/marketplace/model/Store.java | 13 ++++++++-- 11 files changed, 70 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java b/src/main/java/org/fiware/apps/marketplace/model/Localuser.java index a53323b..162b406 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Localuser.java @@ -8,16 +8,17 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; -import javax.persistence.Table; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; + @Entity @XmlRootElement(name = "user") public class Localuser { + private Integer id; private String username; private String password; @@ -25,7 +26,6 @@ public class Localuser { private Date registrationDate; private String company; - @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "LOCALUSER_ID", unique = true, nullable = false) @@ -33,6 +33,7 @@ public class Localuser { public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } @@ -43,24 +44,27 @@ public void setId(Integer id) { public String getUsername() { return username; } + public void setUsername(String username) { this.username = username; } - @XmlElement + @XmlTransient @Column(name = "LOCALUSER_PASSWORD", nullable = false) public String getPassword() { return password; } + public void setPassword(String password) { this.password = password; } - @XmlElement + @XmlTransient @Column(name = "LOCALUSER_EMAIL", unique = true, nullable = false) public String getEmail() { return email; } + public void setEmail(String email) { this.email = email; } @@ -69,7 +73,8 @@ public void setEmail(String email) { @Column(name = "LOCALUSER_REGISTRATION_DATE", nullable = false) public Date getRegistrationDate() { return registrationDate; - } + } + public void setRegistrationDate(Date registrationDate) { this.registrationDate = registrationDate; } @@ -79,6 +84,7 @@ public void setRegistrationDate(Date registrationDate) { public String getCompany() { return company; } + public void setCompany(String company) { this.company = company; } diff --git a/src/main/java/org/fiware/apps/marketplace/model/Rating.java b/src/main/java/org/fiware/apps/marketplace/model/Rating.java index 928a491..f52e57a 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Rating.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Rating.java @@ -3,7 +3,6 @@ import static javax.persistence.GenerationType.IDENTITY; import java.util.Date; -import java.util.List; import java.util.Set; import javax.persistence.CascadeType; @@ -31,9 +30,9 @@ public class Rating { private Set ratingCategoryEntries; private RatingObject ratingObject; private Date date; - private float overallRating; + //To be activated when the overallRating is enabled + //private float overallRating; - @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "RATING_ID", unique = true, nullable = false) @@ -41,26 +40,27 @@ public class Rating { public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } - @XmlElement @Column(name = "RATING_NAME", unique = false, nullable = true ) public String getName() { return name; } + public void setName(String name) { this.name = name; } - @XmlElement @Column(name = "RATING_FEEDBACK", unique = false, nullable = true) public String getFeedback() { return feedback; } + public void setFeedback(String feedback) { this.feedback = feedback; } @@ -70,6 +70,7 @@ public void setFeedback(String feedback) { public RatingObject getRatingObject() { return ratingObject; } + public void setRatingObject(RatingObject ratingObject) { this.ratingObject = ratingObject; } @@ -80,6 +81,7 @@ public void setRatingObject(RatingObject ratingObject) { public Set getRatingCategoryEntries() { return ratingCategoryEntries; } + public void setRatingCategoryEntries( Set ratingCategoryEntries) { this.ratingCategoryEntries = ratingCategoryEntries; @@ -90,17 +92,17 @@ public void setRatingCategoryEntries( public Date getDate() { return date; } + public void setDate(Date date) { this.date = date; } - - @XmlElement @Transient public float getOverallRating() { + //FIXME: The overall rating should be stored, not calculated float result = 0; - if(ratingCategoryEntries!=null){ + if(ratingCategoryEntries != null){ for (RatingCategoryEntry r : ratingCategoryEntries){ result += r.getValue(); } @@ -108,9 +110,9 @@ public float getOverallRating() { } return Float.NaN; } - public void setOverallRating(float overallRating) { - this.overallRating = overallRating; - } + /* public void setOverallRating(float overallRating) { + this.overallRating = overallRating; + }*/ } diff --git a/src/main/java/org/fiware/apps/marketplace/model/RatingCategory.java b/src/main/java/org/fiware/apps/marketplace/model/RatingCategory.java index 7a29eaf..cc61a88 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/RatingCategory.java +++ b/src/main/java/org/fiware/apps/marketplace/model/RatingCategory.java @@ -14,7 +14,6 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; @@ -28,7 +27,6 @@ public class RatingCategory { private List ratingCategoryEntries; private RatingObjectCategory ratingObjectCategory; - @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "RATING_CATEGORY_ID", unique = true, nullable = false) @@ -36,6 +34,7 @@ public class RatingCategory { public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } @@ -46,16 +45,17 @@ public void setId(Integer id) { public String getName() { return name; } + public void setName(String name) { this.name = name; } - @XmlTransient @OneToMany(mappedBy="ratingCategory", cascade=CascadeType.ALL, fetch=FetchType.LAZY) public List getRatingCategoryEntries() { return ratingCategoryEntries; } + public void setRatingCategoryEntries( List ratingCategoryEntries) { this.ratingCategoryEntries = ratingCategoryEntries; @@ -67,6 +67,7 @@ public void setRatingCategoryEntries( public RatingObjectCategory getRatingObjectCategory() { return ratingObjectCategory; } + public void setRatingObjectCategory(RatingObjectCategory ratingObjectCategory) { this.ratingObjectCategory = ratingObjectCategory; } diff --git a/src/main/java/org/fiware/apps/marketplace/model/RatingCategoryEntry.java b/src/main/java/org/fiware/apps/marketplace/model/RatingCategoryEntry.java index cf74140..01e58c4 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/RatingCategoryEntry.java +++ b/src/main/java/org/fiware/apps/marketplace/model/RatingCategoryEntry.java @@ -10,7 +10,6 @@ import javax.persistence.ManyToOne; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; @@ -26,11 +25,11 @@ public class RatingCategoryEntry { @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "RATING_CATEGORY_ENTRY_ID", unique = true, nullable = false) - @XmlAttribute public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } @@ -40,30 +39,30 @@ public void setId(Integer id) { public Integer getValue() { return value; } + public void setValue(Integer value) { this.value = value; } - @ManyToOne(optional = false) @JoinColumn(name = "RATING_CATEGORY_ID", nullable=false) public RatingCategory getRatingCategory() { return ratingCategory; } + public void setRatingCategory(RatingCategory ratingCategory) { this.ratingCategory = ratingCategory; } - @XmlTransient @ManyToOne(optional = false) @JoinColumn(name = "RATING_ID", nullable=false) public Rating getRating() { return rating; } + public void setRating(Rating rating) { this.rating = rating; } - } diff --git a/src/main/java/org/fiware/apps/marketplace/model/RatingObject.java b/src/main/java/org/fiware/apps/marketplace/model/RatingObject.java index da364a8..b1d3cbd 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/RatingObject.java +++ b/src/main/java/org/fiware/apps/marketplace/model/RatingObject.java @@ -28,7 +28,7 @@ public class RatingObject implements Comparable { String objectId; private Set ratings; private RatingObjectCategory ratingObjectCategory; - private float average; + //private float average; public static final int MAX_RATING = 5; public static final int MIN_RATING = 1; @@ -40,6 +40,7 @@ public class RatingObject implements Comparable { public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } @@ -50,6 +51,7 @@ public void setId(Integer id) { public String getObjectId() { return objectId; } + public void setObjectId(String objectId) { this.objectId = objectId; } @@ -59,6 +61,7 @@ public void setObjectId(String objectId) { public Set getRatings() { return ratings; } + public void setRatings(Set ratings) { this.ratings = ratings; } @@ -69,6 +72,7 @@ public void setRatings(Set ratings) { public RatingObjectCategory getRatingObjectCategory() { return ratingObjectCategory; } + public void setRatingObjectCategory(RatingObjectCategory ratingObjectCategory) { this.ratingObjectCategory = ratingObjectCategory; } @@ -76,21 +80,24 @@ public void setRatingObjectCategory(RatingObjectCategory ratingObjectCategory) { @XmlElement @Transient public float getAverage() { + //FIXME: Average should be stored + float result = (float) 0.0; int ratingCount= 0; for (Rating r : ratings){ - if(r.getOverallRating()>=MIN_RATING &&r.getOverallRating()<=MAX_RATING){ + if(r.getOverallRating() >= MIN_RATING && r.getOverallRating() <= MAX_RATING){ result += r.getOverallRating(); ratingCount++; - } } return result/ratingCount; } - public void setAverage(float average) { + + /*public void setAverage(float average) { this.average = average; - } + }*/ + @Override public int compareTo(RatingObject o) { if (getAverage() < o.getAverage()) diff --git a/src/main/java/org/fiware/apps/marketplace/model/RatingObjectCategory.java b/src/main/java/org/fiware/apps/marketplace/model/RatingObjectCategory.java index 7ad58d9..229b424 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/RatingObjectCategory.java +++ b/src/main/java/org/fiware/apps/marketplace/model/RatingObjectCategory.java @@ -12,7 +12,6 @@ import javax.persistence.Id; import javax.persistence.OneToMany; import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; @@ -34,6 +33,7 @@ public class RatingObjectCategory { public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } @@ -44,6 +44,7 @@ public void setId(Integer id) { public String getName() { return name; } + public void setName(String name) { this.name = name; } @@ -53,6 +54,7 @@ public void setName(String name) { public List getRatingObjects() { return ratingObjects; } + public void setRatingObjects(List ratingObjects) { this.ratingObjects = ratingObjects; } @@ -63,6 +65,7 @@ public void setRatingObjects(List ratingObjects) { public List getRatingCategorys() { return ratingCategorys; } + public void setRatingCategorys(List ratingCategorys) { this.ratingCategorys = ratingCategorys; } diff --git a/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntry.java b/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntry.java index b3af74a..4493814 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntry.java +++ b/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntry.java @@ -14,8 +14,6 @@ public class SearchResultEntry { private Service service; private Store store; - - public SearchResultEntry (){ } @@ -57,7 +55,4 @@ public void addMatch(SearchResultEntryMatch match){ matches.add(match); } - - - } diff --git a/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntryMatch.java b/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntryMatch.java index 3cc21a6..250c60d 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntryMatch.java +++ b/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntryMatch.java @@ -5,6 +5,7 @@ @XmlRootElement(name = "match") public class SearchResultEntryMatch { + private String text; private float luceneScore; private String literal; @@ -18,7 +19,6 @@ public SearchResultEntryMatch(String text, float luceneScore) { this.luceneScore = luceneScore; } - @XmlElement public String getText() { return text; @@ -36,7 +36,6 @@ public void setLuceneScore(float luceneScore) { this.luceneScore = luceneScore; } - @XmlElement public String getLiteral() { return literal; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Service.java b/src/main/java/org/fiware/apps/marketplace/model/Service.java index 1b2d5d5..98d0de3 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Service.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Service.java @@ -20,9 +20,9 @@ @Entity @Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "SERVICE_NAME", "STORE_ID" }) }) // each service name has to unique for a store context - @XmlRootElement(name = "resource") public class Service { + private Integer id; private String url; private String name; @@ -38,6 +38,7 @@ public class Service { public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } @@ -48,6 +49,7 @@ public void setId(Integer id) { public String getName() { return name; } + public void setName(String name) { this.name = name; } @@ -57,6 +59,7 @@ public void setName(String name) { public String getUrl() { return url; } + public void setUrl(String url) { this.url = url; } @@ -67,6 +70,7 @@ public void setUrl(String url) { public String getDescription() { return Description; } + public void setDescription(String description) { Description = description; } @@ -76,6 +80,7 @@ public void setDescription(String description) { public Date getRegistrationDate() { return registrationDate; } + public void setRegistrationDate(Date registrationDate) { this.registrationDate = registrationDate; } @@ -87,6 +92,7 @@ public void setRegistrationDate(Date registrationDate) { public Store getStore() { return store; } + public void setStore(Store store) { this.store = store; } @@ -98,6 +104,7 @@ public void setStore(Store store) { public Localuser getLasteditor() { return lasteditor; } + public void setLasteditor(Localuser lasteditor) { this.lasteditor = lasteditor; } @@ -109,6 +116,7 @@ public void setLasteditor(Localuser lasteditor) { public Localuser getCreator() { return creator; } + public void setCreator(Localuser creator) { this.creator = creator; } diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceManifestation.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceManifestation.java index 5c41e68..2c16034 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceManifestation.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceManifestation.java @@ -9,6 +9,7 @@ @XmlRootElement(name = "serviceManifestation") public class ServiceManifestation { + private Integer id; private String offeringUri; private String offeringTitle; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Store.java b/src/main/java/org/fiware/apps/marketplace/model/Store.java index 53e2594..fe62c83 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Store.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Store.java @@ -20,10 +20,13 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.codehaus.jackson.annotate.JsonIgnore; + @Entity @XmlRootElement(name = "resource") public class Store { + private Integer id; private String url; private String name; @@ -40,6 +43,7 @@ public class Store { public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } @@ -50,6 +54,7 @@ public void setId(Integer id) { public String getName() { return name; } + public void setName(String name) { this.name = name; } @@ -59,17 +64,17 @@ public void setName(String name) { public String getUrl() { return url; } + public void setUrl(String url) { this.url = url; } - - @XmlElement @Column(name = "STORE_DESC") public String getDescription() { return Description; } + public void setDescription(String description) { Description = description; } @@ -79,6 +84,7 @@ public void setDescription(String description) { public Date getRegistrationDate() { return registrationDate; } + public void setRegistrationDate(Date registrationDate) { this.registrationDate = registrationDate; } @@ -89,6 +95,7 @@ public void setRegistrationDate(Date registrationDate) { public List getServices() { return services; } + public void setServices(List services) { this.services = services; } @@ -99,6 +106,7 @@ public void setServices(List services) { public Localuser getLasteditor() { return lasteditor; } + public void setLasteditor(Localuser lasteditor) { this.lasteditor = lasteditor; } @@ -109,6 +117,7 @@ public void setLasteditor(Localuser lasteditor) { public Localuser getCreator() { return creator; } + public void setCreator(Localuser creator) { this.creator = creator; } From 06566291a25aa0b498c55142b799aeffa649128d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 11 Nov 2014 16:36:19 +0100 Subject: [PATCH 03/69] Add Transaction Manager. Adapt LocalUserDao Implementation --- pom.xml | 9 ++++++- .../marketplace/bo/impl/LocaluserBoImpl.java | 9 +++---- .../dao/impl/LocaluserDaoImpl.java | 4 +-- .../util/ApplicationContextProvider.java | 3 +++ .../util/MarketplaceHibernateDao.java | 1 + .../resources/spring/database/Hibernate.xml | 25 +++++++++++++------ 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 070c979..e750940 100644 --- a/pom.xml +++ b/pom.xml @@ -144,7 +144,7 @@ mysql mysql-connector-java - 5.1.33 + 5.1.34 @@ -155,6 +155,13 @@ 4.3.7.Final + + org.javassist + javassist + 3.18.2-GA + + + dom4j diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java index 7a99f61..c4849d8 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java @@ -4,10 +4,10 @@ import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.dao.LocaluserDao; -import org.fiware.apps.marketplace.dao.StoreDao; import org.fiware.apps.marketplace.model.Localuser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service("localuserBo") public class LocaluserBoImpl implements LocaluserBo{ @@ -20,27 +20,26 @@ public void setStoreDao (LocaluserDao localuser){ } @Override + @Transactional(readOnly=false) public void save(Localuser localuser) { localuserDao.save(localuser); - } @Override + @Transactional(readOnly=false) public void update(Localuser localuser) { localuserDao.update(localuser); - } @Override + @Transactional(readOnly=false) public void delete(Localuser localuser) { localuserDao.delete(localuser); - } @Override public Localuser findByName(String username) { return localuserDao.findByName(username); - } @Override diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java index afbdc3b..93b2f76 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java @@ -13,7 +13,6 @@ public class LocaluserDaoImpl extends MarketplaceHibernateDao implements Localu @Override public void save(Localuser store) { getHibernateTemplate().saveOrUpdate(store); - } @Override @@ -24,8 +23,7 @@ public void update(Localuser store) { @Override public void delete(Localuser store) { - getHibernateTemplate().delete(store); - + getHibernateTemplate().delete(store); } @Override diff --git a/src/main/java/org/fiware/apps/marketplace/util/ApplicationContextProvider.java b/src/main/java/org/fiware/apps/marketplace/util/ApplicationContextProvider.java index 961dd64..69ff79a 100644 --- a/src/main/java/org/fiware/apps/marketplace/util/ApplicationContextProvider.java +++ b/src/main/java/org/fiware/apps/marketplace/util/ApplicationContextProvider.java @@ -6,10 +6,13 @@ import org.springframework.context.ApplicationContextAware; public class ApplicationContextProvider implements ApplicationContextAware{ + private static ApplicationContext ctx = null; + public static ApplicationContext getApplicationContext() { return ctx; } + public void setApplicationContext(ApplicationContext ctx) throws BeansException { this.ctx = ctx; } diff --git a/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java b/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java index 928ed8e..77e2f7a 100644 --- a/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java +++ b/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate4.support.HibernateDaoSupport; + public class MarketplaceHibernateDao extends HibernateDaoSupport{ @Autowired diff --git a/src/main/resources/spring/database/Hibernate.xml b/src/main/resources/spring/database/Hibernate.xml index e810e10..da890f7 100644 --- a/src/main/resources/spring/database/Hibernate.xml +++ b/src/main/resources/spring/database/Hibernate.xml @@ -1,25 +1,34 @@ - + http://www.springframework.org/schema/context/spring-context-4.1.xsd + http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx/spring-tx.xsd "> + + + - - + + - + org.hibernate.dialect.MySQLDialect true + + + \ No newline at end of file From 87d913538ca596c8d5c6a7a90122200d9b952968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 20 Nov 2014 17:45:58 +0100 Subject: [PATCH 04/69] Add Auth functions for Users. Password and Mail are not returned in the API anymore. Refactor --- pom.xml | 6 + .../marketplace/bo/impl/CompareBoImpl.java | 2 +- .../bo/impl/MaintenanceBoImpl.java | 2 +- .../marketplace/bo/impl/SearchBoImpl.java | 4 +- .../marketplace/bo/impl/ServiceBoImpl.java | 2 +- .../marketplace/bo/impl/VocabularyBoImpl.java | 2 +- .../dao/impl/LocaluserDaoImpl.java | 32 ++--- .../marketplace/dao/impl/RatingDaoImpl.java | 2 +- .../marketplace/dao/impl/ServiceDaoImpl.java | 2 +- .../marketplace/dao/impl/StoreDaoImpl.java | 2 +- .../apps/marketplace/model/Localuser.java | 21 ++- .../apps/marketplace/rest/CompareService.java | 2 +- .../marketplace/rest/OfferingService.java | 2 +- .../apps/marketplace/rest/RatingService.java | 2 +- .../rest/RecommendationService.java | 2 +- .../apps/marketplace/rest/SearchService.java | 2 +- .../ServiceManifestationIndexerService.java | 2 +- .../rest/StoreRegistrationService.java | 2 +- .../rest/UserRegistrationService.java | 126 +++++++++++------- .../security/UserManagementService.java | 14 +- .../marketplace/security/auth/AuthUtils.java | 29 ++++ .../security/auth/UserRegistrationAuth.java | 39 ++++++ .../ApplicationContextProvider.java | 2 +- .../utils/HiddenFieldsXMLAdapter.java | 17 +++ .../MarketplaceHibernateDao.java | 2 +- .../{util => utils}/PropertiesUtil.java | 2 +- src/main/resources/spring/config/security.xml | 4 +- .../resources/spring/database/DataSource.xml | 4 +- src/main/webapp/WEB-INF/web.xml | 6 +- 29 files changed, 237 insertions(+), 99 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java create mode 100644 src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java rename src/main/java/org/fiware/apps/marketplace/{util => utils}/ApplicationContextProvider.java (91%) create mode 100644 src/main/java/org/fiware/apps/marketplace/utils/HiddenFieldsXMLAdapter.java rename src/main/java/org/fiware/apps/marketplace/{util => utils}/MarketplaceHibernateDao.java (89%) rename src/main/java/org/fiware/apps/marketplace/{util => utils}/PropertiesUtil.java (95%) diff --git a/pom.xml b/pom.xml index e750940..4001d13 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,12 @@ spring-orm 4.1.1.RELEASE + + + org.springframework + spring-aop + 4.1.1.RELEASE + org.codehaus.spring-security-oauth diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/CompareBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/CompareBoImpl.java index 5c3b23e..2477f37 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/CompareBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/CompareBoImpl.java @@ -10,7 +10,7 @@ import org.fiware.apps.marketplace.helpers.ServiceManifestationComparator; import org.fiware.apps.marketplace.model.ComparisonResult; import org.fiware.apps.marketplace.model.ServiceManifestation; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; import com.mysql.jdbc.StringUtils; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java index e6220a9..46215da 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java @@ -19,7 +19,7 @@ import org.fiware.apps.marketplace.model.ServiceAttributeTypeStatistics; import org.fiware.apps.marketplace.model.ServiceManifestation; import org.fiware.apps.marketplace.model.Store; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; @org.springframework.stereotype.Service("maintenanceBo") diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/SearchBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/SearchBoImpl.java index 2b31719..1ef1aed 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/SearchBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/SearchBoImpl.java @@ -13,8 +13,8 @@ import org.fiware.apps.marketplace.model.SearchResultEntryMatch; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.rdf.IndexBuilderStringExtended; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; -import org.fiware.apps.marketplace.util.PropertiesUtil; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.PropertiesUtil; import org.springframework.context.ApplicationContext; import com.hp.hpl.jena.graph.Node; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java index 16c8eeb..13f7365 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java @@ -5,7 +5,7 @@ import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.rdf.RdfHelper; import org.fiware.apps.marketplace.rdf.RdfIndexer; -import org.fiware.apps.marketplace.util.PropertiesUtil; +import org.fiware.apps.marketplace.utils.PropertiesUtil; import org.springframework.beans.factory.annotation.Autowired; import com.hp.hpl.jena.rdf.model.Model; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/VocabularyBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/VocabularyBoImpl.java index ba2e45f..c0e8b50 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/VocabularyBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/VocabularyBoImpl.java @@ -4,7 +4,7 @@ import java.util.List; import org.fiware.apps.marketplace.bo.VocabularyBo; -import org.fiware.apps.marketplace.util.PropertiesUtil; +import org.fiware.apps.marketplace.utils.PropertiesUtil; import org.springframework.stereotype.Service; @Service("vocabularyBo") diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java index 93b2f76..2128293 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java @@ -4,43 +4,45 @@ import org.fiware.apps.marketplace.dao.LocaluserDao; import org.fiware.apps.marketplace.model.Localuser; -import org.fiware.apps.marketplace.util.MarketplaceHibernateDao; +import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; import org.springframework.stereotype.Repository; @Repository("localuserDao") public class LocaluserDaoImpl extends MarketplaceHibernateDao implements LocaluserDao { @Override - public void save(Localuser store) { - getHibernateTemplate().saveOrUpdate(store); + public void save(Localuser user) { + getHibernateTemplate().saveOrUpdate(user); } @Override - public void update(Localuser store) { - getHibernateTemplate().update(store); + public void update(Localuser user) { + getHibernateTemplate().update(user); } @Override - public void delete(Localuser store) { - getHibernateTemplate().delete(store); + public void delete(Localuser user) { + getHibernateTemplate().delete(user); } @Override public Localuser findByName(String username) { - List list = getHibernateTemplate().find( - "from Localuser where username=?",username - ); - if (list.size()!=0){ - return (Localuser)list.get(0); - } + List list = getHibernateTemplate().find("from Localuser where username=?", username); + + if (list.size() != 0){ + return (Localuser) list.get(0); + } + //FIXME: Else -> Throw UserNotFoundException + return null; } @Override public List findLocalusers() { - List list = getHibernateTemplate().loadAll(Localuser.class); - if (list.size()==0){ + List list = getHibernateTemplate().loadAll(Localuser.class); + + if (list.size() == 0){ return null; } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/RatingDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/RatingDaoImpl.java index c39020b..c638aa1 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/RatingDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/RatingDaoImpl.java @@ -8,7 +8,7 @@ import org.fiware.apps.marketplace.model.RatingCategoryEntry; import org.fiware.apps.marketplace.model.RatingObject; import org.fiware.apps.marketplace.model.RatingObjectCategory; -import org.fiware.apps.marketplace.util.MarketplaceHibernateDao; +import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; import org.springframework.stereotype.Repository; @Repository("ratingDao") diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java index ff40ddd..08a941e 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java @@ -4,7 +4,7 @@ import org.fiware.apps.marketplace.dao.ServiceDao; import org.fiware.apps.marketplace.model.Service; -import org.fiware.apps.marketplace.util.MarketplaceHibernateDao; +import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; import org.springframework.stereotype.Repository; @Repository("serviceDao") diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java index a103a1d..73a0be5 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java @@ -4,7 +4,7 @@ import org.fiware.apps.marketplace.dao.StoreDao; import org.fiware.apps.marketplace.model.Store; -import org.fiware.apps.marketplace.util.MarketplaceHibernateDao; +import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; import org.springframework.stereotype.Repository; @Repository("storeDao") diff --git a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java b/src/main/java/org/fiware/apps/marketplace/model/Localuser.java index 162b406..98234d4 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Localuser.java @@ -13,7 +13,9 @@ import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.fiware.apps.marketplace.utils.HiddenFieldsXMLAdapter; @Entity @XmlRootElement(name = "user") @@ -25,7 +27,7 @@ public class Localuser { private String email; private Date registrationDate; private String company; - + @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "LOCALUSER_ID", unique = true, nullable = false) @@ -49,7 +51,8 @@ public void setUsername(String username) { this.username = username; } - @XmlTransient + @XmlElement + @XmlJavaTypeAdapter(HiddenFieldsXMLAdapter.class) //Avoid returning the Password in the XML, JSON @Column(name = "LOCALUSER_PASSWORD", nullable = false) public String getPassword() { return password; @@ -59,7 +62,8 @@ public void setPassword(String password) { this.password = password; } - @XmlTransient + @XmlElement + @XmlJavaTypeAdapter(HiddenFieldsXMLAdapter.class) //Avoid returning the Mail in the XML, JSON @Column(name = "LOCALUSER_EMAIL", unique = true, nullable = false) public String getEmail() { return email; @@ -88,5 +92,16 @@ public String getCompany() { public void setCompany(String company) { this.company = company; } + + @Override + public int hashCode() { + return this.id == null ? 0 : this.id; + } + + @Override + public boolean equals(Object obj) { + Localuser other = (Localuser) obj; + return other.id == this.id; + } } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/CompareService.java b/src/main/java/org/fiware/apps/marketplace/rest/CompareService.java index 46f5d62..f264dc9 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/CompareService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/CompareService.java @@ -10,7 +10,7 @@ import org.fiware.apps.marketplace.bo.CompareBo; import org.fiware.apps.marketplace.bo.MaintenanceBo; import org.fiware.apps.marketplace.model.ComparisonResult; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; @Path("/compare") diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java index ccbd4f1..ffee785 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java @@ -20,7 +20,7 @@ import org.fiware.apps.marketplace.bo.StoreBo; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/RatingService.java b/src/main/java/org/fiware/apps/marketplace/rest/RatingService.java index 4f43a76..a48fb83 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/RatingService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/RatingService.java @@ -21,7 +21,7 @@ import org.fiware.apps.marketplace.model.RatingCategoryEntry; import org.fiware.apps.marketplace.model.RatingObject; import org.fiware.apps.marketplace.model.RatingObjectCategory; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; @Path("/rating") diff --git a/src/main/java/org/fiware/apps/marketplace/rest/RecommendationService.java b/src/main/java/org/fiware/apps/marketplace/rest/RecommendationService.java index 2fdde59..4d1ec15 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/RecommendationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/RecommendationService.java @@ -13,7 +13,7 @@ import org.fiware.apps.marketplace.bo.RatingBo; import org.fiware.apps.marketplace.model.RatingObject; import org.fiware.apps.marketplace.model.RatingObjectCategory; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/SearchService.java b/src/main/java/org/fiware/apps/marketplace/rest/SearchService.java index 4b1fb9b..a458c79 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/SearchService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/SearchService.java @@ -9,7 +9,7 @@ import org.fiware.apps.marketplace.bo.SearchBo; import org.fiware.apps.marketplace.model.SearchResult; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; @Path("/search") diff --git a/src/main/java/org/fiware/apps/marketplace/rest/ServiceManifestationIndexerService.java b/src/main/java/org/fiware/apps/marketplace/rest/ServiceManifestationIndexerService.java index 60870dd..e60654d 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/ServiceManifestationIndexerService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/ServiceManifestationIndexerService.java @@ -10,7 +10,7 @@ import org.fiware.apps.marketplace.bo.MaintenanceBo; import org.fiware.apps.marketplace.bo.ServiceManifestationBo; import org.fiware.apps.marketplace.model.ServiceManifestation; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; @Path("/serviceManifestationIndex") diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 6c44125..a14d94f 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -20,7 +20,7 @@ import org.fiware.apps.marketplace.bo.StoreBo; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 5b7c21b..a1cc80a 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -1,5 +1,6 @@ package org.fiware.apps.marketplace.rest; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -11,80 +12,111 @@ 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.Response; import javax.ws.rs.core.Response.Status; import org.fiware.apps.marketplace.bo.LocaluserBo; -import org.fiware.apps.marketplace.bo.ServiceBo; -import org.fiware.apps.marketplace.bo.StoreBo; import org.fiware.apps.marketplace.model.Localuser; -import org.fiware.apps.marketplace.model.Store; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; -import org.springframework.beans.factory.annotation.Autowired; +import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; -@Path("/registration/userManagement") +@Path("/user") public class UserRegistrationService { - - ApplicationContext appContext = ApplicationContextProvider.getApplicationContext(); - LocaluserBo localuserBo = (LocaluserBo)appContext.getBean("localuserBo"); - - @PUT + // CLASS ATTRIBUTES // + private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); + private LocaluserBo localuserBo = (LocaluserBo) context.getBean("localuserBo"); + private UserRegistrationAuth userRegistrationAuth = (UserRegistrationAuth) context.getBean("userRegistrationAuth"); + + // CLASS METHODS // + @POST @Consumes({"application/xml", "application/json"}) - @Path("/user") - public Response saveLocaluser(Localuser lucaluser) { - lucaluser.setRegistrationDate(new Date()); - localuserBo.save(lucaluser); - return Response.status(Status.CREATED).build(); + @Path("/") + public Response createUser(Localuser localUser) { + //FIXME: Catch Exceptions + if (userRegistrationAuth.canCreate()) { + localUser.setRegistrationDate(new Date()); + localuserBo.save(localUser); + return Response.status(Status.CREATED).build(); + } else { + return Response.status(Status.FORBIDDEN).build(); + } } - - @POST + @PUT @Consumes({"application/xml", "application/json"}) - @Path("/user/{username}") - public Response updateLocaluser(@PathParam("username") String username, Localuser localuser) { - Localuser localuserDB = localuserBo.findByName(username); - localuserDB.setCompany(localuser.getCompany()); - localuser.setPassword(localuser.getPassword()); - localuser.setEmail(localuser.getEmail()); - localuser.setUsername(localuser.getUsername()); - localuserBo.update(localuserDB); - return Response.status(Status.OK).build(); + @Path("/{username}") + public Response updateUser(@PathParam("username") String username, Localuser localUser) { + //FIXME: Catch exceptions + Localuser userToBeUpdated = localuserBo.findByName(username); + + if (userRegistrationAuth.canUpdate(userToBeUpdated)) { + userToBeUpdated.setCompany(localUser.getCompany()); + userToBeUpdated.setPassword(localUser.getPassword()); + userToBeUpdated.setEmail(localUser.getEmail()); + userToBeUpdated.setUsername(localUser.getUsername()); + localuserBo.update(userToBeUpdated); + return Response.status(Status.OK).build(); + } else { + return Response.status(Status.FORBIDDEN).build(); + } } @DELETE - @Path("/user/{username}") - public Response deleteLocaluser(@PathParam("username") String username) { - Localuser localuser = localuserBo.findByName(username); - localuserBo.delete(localuser); - return Response.status(Status.OK).build(); + @Path("/{username}") + public Response deleteUser(@PathParam("username") String username) { + //FIXME: Catch exceptions + Localuser userToBeDeleted = localuserBo.findByName(username); + + // Only a user can delete his/her account + if (userRegistrationAuth.canDelete(userToBeDeleted)) { + localuserBo.delete(userToBeDeleted); + return Response.status(Status.OK).build(); + } else { + return Response.status(Status.FORBIDDEN).build(); + } } @GET @Produces({"application/xml", "application/json"}) - @Path("/user/{username}") - public Localuser findLocaluser(@PathParam("username") String username) { + @Path("/{username}") + public Response findUser(@PathParam("username") String username) { + //FIXME: Catch exceptions Localuser localuser = localuserBo.findByName(username); - if (localuser==null){ - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Not Found").build()); + Response response; + + if (userRegistrationAuth.canGet(localuser)) { + // If the user does not exist, we should raise a 404 Not Found Error + if (localuser == null){ + response = Response.status(Status.NOT_FOUND).build(); + } else { + response = Response.status(Status.OK).entity(localuser).build(); + } + } else { + response = Response.status(Status.FORBIDDEN).build(); } - return localuser; + return response; } @GET @Produces({"application/xml", "application/json"}) - @Path("/users/") - public List findLocalusers() { - List users = localuserBo.findLocalusers(); - if (users==null){ - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Not Found").build()); + @Path("/") + public Response getList() { + //FIXME: Catch Exceptions + //FIXME: It does not work if the user ask for an XML response + if (userRegistrationAuth.canList()) { + List users = localuserBo.findLocalusers(); + + // Return an empty list just in case the system has no users registered + if (users == null){ + users = new ArrayList(); + } + + return Response.status(Status.OK).entity(users).build(); + } else { + return Response.status(Status.FORBIDDEN).build(); } - return users; - } - - } diff --git a/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java b/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java index e443fd6..77b92df 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java +++ b/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java @@ -2,7 +2,7 @@ import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.model.Localuser; -import org.fiware.apps.marketplace.util.ApplicationContextProvider; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.dao.DataAccessException; @@ -11,26 +11,22 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; - - - @Service("userManagementService") public class UserManagementService implements UserDetailsService{ - ApplicationContext appContext = ApplicationContextProvider.getApplicationContext(); - LocaluserBo localuserBo = (LocaluserBo)appContext.getBean("localuserBo"); + LocaluserBo localuserBo = (LocaluserBo) appContext.getBean("localuserBo"); - @Autowired private Assembler assembler; + @Autowired + private Assembler assembler; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { - Localuser userEntity = localuserBo.findByName(username); if (userEntity == null) - throw new UsernameNotFoundException("user not found"); + throw new UsernameNotFoundException("user not found"); return assembler.buildUserFromUserEntity(userEntity); } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java new file mode 100644 index 0000000..6bba1f2 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java @@ -0,0 +1,29 @@ +package org.fiware.apps.marketplace.security.auth; + +import org.fiware.apps.marketplace.bo.LocaluserBo; +import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; +import org.springframework.security.core.context.SecurityContextHolder; + +public class AuthUtils { + + // Avoid users to instanciate this class + private AuthUtils() { + this.localuserBo = (LocaluserBo) ApplicationContextProvider.getApplicationContext().getBean("localuserBo"); + } + + public static AuthUtils getAuthUtils() { + return singleton; + } + + //Singleton + private static AuthUtils singleton = new AuthUtils(); + + //Instance attributes + private LocaluserBo localuserBo; + + public Localuser getLoggedUser() { + return localuserBo.findByName(SecurityContextHolder.getContext().getAuthentication().getName()); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java new file mode 100644 index 0000000..32e6e8a --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java @@ -0,0 +1,39 @@ +package org.fiware.apps.marketplace.security.auth; + +import org.fiware.apps.marketplace.model.Localuser; +import org.springframework.stereotype.Service; + +@Service("userRegistrationAuth") +public class UserRegistrationAuth { + + private boolean isTheSameUser(Localuser user) { + boolean canAccess = false; + if (AuthUtils.getAuthUtils().getLoggedUser().equals(user)) { + canAccess = true; + } + + return canAccess; + } + + public boolean canCreate() { + return true; + } + + public boolean canUpdate(Localuser user) { + return this.isTheSameUser(user); + } + + public boolean canDelete(Localuser user) { + return this.isTheSameUser(user); + } + + public boolean canGet(Localuser user) { + return true; + } + + public boolean canList() { + return true; + } + + +} diff --git a/src/main/java/org/fiware/apps/marketplace/util/ApplicationContextProvider.java b/src/main/java/org/fiware/apps/marketplace/utils/ApplicationContextProvider.java similarity index 91% rename from src/main/java/org/fiware/apps/marketplace/util/ApplicationContextProvider.java rename to src/main/java/org/fiware/apps/marketplace/utils/ApplicationContextProvider.java index 69ff79a..e678d7e 100644 --- a/src/main/java/org/fiware/apps/marketplace/util/ApplicationContextProvider.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/ApplicationContextProvider.java @@ -1,4 +1,4 @@ -package org.fiware.apps.marketplace.util; +package org.fiware.apps.marketplace.utils; import org.springframework.beans.BeansException; diff --git a/src/main/java/org/fiware/apps/marketplace/utils/HiddenFieldsXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/HiddenFieldsXMLAdapter.java new file mode 100644 index 0000000..9bb9088 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/utils/HiddenFieldsXMLAdapter.java @@ -0,0 +1,17 @@ +package org.fiware.apps.marketplace.utils; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class HiddenFieldsXMLAdapter extends XmlAdapter{ + + @Override + public String marshal(String val) throws Exception { + return null; + } + + @Override + public String unmarshal(String val) throws Exception { + return val; + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java b/src/main/java/org/fiware/apps/marketplace/utils/MarketplaceHibernateDao.java similarity index 89% rename from src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java rename to src/main/java/org/fiware/apps/marketplace/utils/MarketplaceHibernateDao.java index 77e2f7a..bc32c4e 100644 --- a/src/main/java/org/fiware/apps/marketplace/util/MarketplaceHibernateDao.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/MarketplaceHibernateDao.java @@ -1,4 +1,4 @@ -package org.fiware.apps.marketplace.util; +package org.fiware.apps.marketplace.utils; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/org/fiware/apps/marketplace/util/PropertiesUtil.java b/src/main/java/org/fiware/apps/marketplace/utils/PropertiesUtil.java similarity index 95% rename from src/main/java/org/fiware/apps/marketplace/util/PropertiesUtil.java rename to src/main/java/org/fiware/apps/marketplace/utils/PropertiesUtil.java index 96b66ab..3868ff6 100644 --- a/src/main/java/org/fiware/apps/marketplace/util/PropertiesUtil.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/PropertiesUtil.java @@ -1,4 +1,4 @@ -package org.fiware.apps.marketplace.util; +package org.fiware.apps.marketplace.utils; import java.util.HashMap; import java.util.HashSet; diff --git a/src/main/resources/spring/config/security.xml b/src/main/resources/spring/config/security.xml index b277f7a..c0c8f9c 100644 --- a/src/main/resources/spring/config/security.xml +++ b/src/main/resources/spring/config/security.xml @@ -9,8 +9,8 @@ - - + + diff --git a/src/main/resources/spring/database/DataSource.xml b/src/main/resources/spring/database/DataSource.xml index 946b717..0e5b59f 100644 --- a/src/main/resources/spring/database/DataSource.xml +++ b/src/main/resources/spring/database/DataSource.xml @@ -9,7 +9,7 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + /WEB-INF/classes/properties/marketplace.properties @@ -21,5 +21,5 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 5d29c49..0fa60ee 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -5,8 +5,8 @@ Fiware Marketplace - - + + springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy @@ -59,6 +59,7 @@ + CORS * @@ -87,6 +88,7 @@ org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap + resteasy-servlet From ff297bfd77c89c216aa318cbfd2804d83d7da7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 20 Nov 2014 18:02:15 +0100 Subject: [PATCH 05/69] Minor bug fix. Improve code --- .../marketplace/rest/UserRegistrationService.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index a1cc80a..b6f1513 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -86,15 +86,14 @@ public Response findUser(@PathParam("username") String username) { Localuser localuser = localuserBo.findByName(username); Response response; - if (userRegistrationAuth.canGet(localuser)) { - // If the user does not exist, we should raise a 404 Not Found Error - if (localuser == null){ - response = Response.status(Status.NOT_FOUND).build(); + if (localuser == null) { + response = Response.status(Status.NOT_FOUND).build(); + } else { + if (userRegistrationAuth.canGet(localuser)) { + response = Response.status(Status.OK).entity(localuser).build(); } else { - response = Response.status(Status.OK).entity(localuser).build(); + response = Response.status(Status.FORBIDDEN).build(); } - } else { - response = Response.status(Status.FORBIDDEN).build(); } return response; From c2941d4388ec9ee0d4c11063d83b3d8c0ba915a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Fri, 21 Nov 2014 10:23:09 +0100 Subject: [PATCH 06/69] Throw exception when the user cannot be found. Fix problem with returning the list of users as XML --- .../apps/marketplace/bo/LocaluserBo.java | 3 +- .../marketplace/bo/impl/LocaluserBoImpl.java | 3 +- .../apps/marketplace/dao/LocaluserDao.java | 3 +- .../dao/impl/LocaluserDaoImpl.java | 10 +-- .../exceptions/UserNotFoundException.java | 11 +++ .../fiware/apps/marketplace/model/Users.java | 30 +++++++++ .../marketplace/rest/OfferingService.java | 8 ++- .../rest/StoreRegistrationService.java | 7 +- .../rest/UserRegistrationService.java | 67 ++++++++++++------- .../security/UserManagementService.java | 12 ++-- .../marketplace/security/auth/AuthUtils.java | 8 ++- 11 files changed, 119 insertions(+), 43 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/exceptions/UserNotFoundException.java create mode 100644 src/main/java/org/fiware/apps/marketplace/model/Users.java diff --git a/src/main/java/org/fiware/apps/marketplace/bo/LocaluserBo.java b/src/main/java/org/fiware/apps/marketplace/bo/LocaluserBo.java index fc9d632..35bfdab 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/LocaluserBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/LocaluserBo.java @@ -2,12 +2,13 @@ import java.util.List; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Localuser; public interface LocaluserBo { void save(Localuser localuser); void update(Localuser localuser); void delete(Localuser localuser); - Localuser findByName(String username); + Localuser findByName(String username) throws UserNotFoundException; List findLocalusers(); } diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java index c4849d8..72dcc91 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java @@ -4,6 +4,7 @@ import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.dao.LocaluserDao; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Localuser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -38,7 +39,7 @@ public void delete(Localuser localuser) { } @Override - public Localuser findByName(String username) { + public Localuser findByName(String username) throws UserNotFoundException { return localuserDao.findByName(username); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/LocaluserDao.java b/src/main/java/org/fiware/apps/marketplace/dao/LocaluserDao.java index b48f807..bbc92f9 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/LocaluserDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/LocaluserDao.java @@ -2,12 +2,13 @@ import java.util.List; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Localuser; public interface LocaluserDao { void save(Localuser localuser); void update(Localuser localuser); void delete(Localuser localuser); - Localuser findByName(String username); + Localuser findByName(String username) throws UserNotFoundException; List findLocalusers(); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java index 2128293..9663af4 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java @@ -3,6 +3,7 @@ import java.util.List; import org.fiware.apps.marketplace.dao.LocaluserDao; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Localuser; import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; import org.springframework.stereotype.Repository; @@ -27,15 +28,14 @@ public void delete(Localuser user) { } @Override - public Localuser findByName(String username) { + public Localuser findByName(String username) throws UserNotFoundException{ List list = getHibernateTemplate().find("from Localuser where username=?", username); - if (list.size() != 0){ + if (list.size() == 0) { + throw new UserNotFoundException(username + " not found"); + } else { return (Localuser) list.get(0); } - //FIXME: Else -> Throw UserNotFoundException - - return null; } @Override diff --git a/src/main/java/org/fiware/apps/marketplace/exceptions/UserNotFoundException.java b/src/main/java/org/fiware/apps/marketplace/exceptions/UserNotFoundException.java new file mode 100644 index 0000000..7483b17 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/exceptions/UserNotFoundException.java @@ -0,0 +1,11 @@ +package org.fiware.apps.marketplace.exceptions; + +public class UserNotFoundException extends Exception { + + private static final long serialVersionUID = 1L; + + public UserNotFoundException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/model/Users.java b/src/main/java/org/fiware/apps/marketplace/model/Users.java new file mode 100644 index 0000000..3364d4b --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/Users.java @@ -0,0 +1,30 @@ +package org.fiware.apps.marketplace.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "users") +public class Users { + + private List users = null; + + public Users() { + this.setUsers(new ArrayList()); + } + + public Users(List users) { + this.setUsers(users); + } + + @XmlElement(name = "user") + public List getUsers() { + return this.users; + } + + public void setUsers(List users) { + this.users = users; + } +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java index ffee785..619a06a 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java @@ -18,6 +18,7 @@ import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.bo.ServiceBo; import org.fiware.apps.marketplace.bo.StoreBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; @@ -41,7 +42,9 @@ public class OfferingService { @PUT @Consumes({"application/xml", "application/json"}) @Path("/store/{storeName}/offering") - public Response saveService(@PathParam("storeName") String storeName, Service service) { + public Response saveService(@PathParam("storeName") String storeName, Service service) throws UserNotFoundException { + //FIXME: Temporal solution. Exception should be caught + Store store = storeBo.findByName(storeName); if (store==null){ throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Not Found").build()); @@ -59,7 +62,8 @@ public Response saveService(@PathParam("storeName") String storeName, Service se @POST @Consumes({"application/xml", "application/json"}) @Path("/store/{storeName}/offering/{serviceName}") - public Response updateService(@PathParam("storeName") String storeName, @PathParam("serviceName") String serviceName, Service service) { + public Response updateService(@PathParam("storeName") String storeName, @PathParam("serviceName") String serviceName, Service service) throws UserNotFoundException { + //FIXME: Temporal solution. Exception should be caught Service serviceDB = serviceBo.findByNameAndStore(serviceName, storeName); serviceDB.setName(service.getName()); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index a14d94f..10f576f 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -18,6 +18,7 @@ import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.bo.ServiceBo; import org.fiware.apps.marketplace.bo.StoreBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; @@ -40,7 +41,8 @@ public class StoreRegistrationService { @PUT @Consumes({"application/xml", "application/json"}) @Path("/store") - public Response saveStore(Store store) { + public Response saveStore(Store store) throws UserNotFoundException { + //FIXME: Temporal solution. Exception should be caught store.setRegistrationDate(new Date()); store.setCreator(localuserBo.findByName(actUser)); store.setLasteditor(localuserBo.findByName(actUser)); @@ -52,7 +54,8 @@ public Response saveStore(Store store) { @POST @Consumes({"application/xml", "application/json"}) @Path("/store/{storeName}") - public Response updateStore(@PathParam("storeName") String storeName, Store store) { + public Response updateStore(@PathParam("storeName") String storeName, Store store) throws UserNotFoundException { + //FIXME: Temporal solution. Exception should be caught Store storeDB = storeBo.findByName(storeName); storeDB.setName(store.getName()); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index b6f1513..1ade766 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -16,7 +16,9 @@ import javax.ws.rs.core.Response.Status; import org.fiware.apps.marketplace.bo.LocaluserBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.Users; import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; @@ -49,33 +51,48 @@ public Response createUser(Localuser localUser) { @Path("/{username}") public Response updateUser(@PathParam("username") String username, Localuser localUser) { //FIXME: Catch exceptions - Localuser userToBeUpdated = localuserBo.findByName(username); + Response response; - if (userRegistrationAuth.canUpdate(userToBeUpdated)) { - userToBeUpdated.setCompany(localUser.getCompany()); - userToBeUpdated.setPassword(localUser.getPassword()); - userToBeUpdated.setEmail(localUser.getEmail()); - userToBeUpdated.setUsername(localUser.getUsername()); - localuserBo.update(userToBeUpdated); - return Response.status(Status.OK).build(); - } else { - return Response.status(Status.FORBIDDEN).build(); + try { + Localuser userToBeUpdated = localuserBo.findByName(username); + + if (userRegistrationAuth.canUpdate(userToBeUpdated)) { + userToBeUpdated.setCompany(localUser.getCompany()); + userToBeUpdated.setPassword(localUser.getPassword()); + userToBeUpdated.setEmail(localUser.getEmail()); + userToBeUpdated.setUsername(localUser.getUsername()); + localuserBo.update(userToBeUpdated); + response = Response.status(Status.OK).build(); + } else { + response = Response.status(Status.FORBIDDEN).build(); + } + } catch (UserNotFoundException ex) { + response = Response.status(Status.NOT_FOUND).build(); } + + return response; } @DELETE @Path("/{username}") public Response deleteUser(@PathParam("username") String username) { //FIXME: Catch exceptions - Localuser userToBeDeleted = localuserBo.findByName(username); - - // Only a user can delete his/her account - if (userRegistrationAuth.canDelete(userToBeDeleted)) { - localuserBo.delete(userToBeDeleted); - return Response.status(Status.OK).build(); - } else { - return Response.status(Status.FORBIDDEN).build(); + Response response; + + try { + Localuser userToBeDeleted = localuserBo.findByName(username); + // Only a user can delete his/her account + if (userRegistrationAuth.canDelete(userToBeDeleted)) { + localuserBo.delete(userToBeDeleted); + response = Response.status(Status.OK).build(); + } else { + response = Response.status(Status.FORBIDDEN).build(); + } + } catch (UserNotFoundException ex) { + response = Response.status(Status.NOT_FOUND).build(); } + + return response; } @GET @@ -83,17 +100,18 @@ public Response deleteUser(@PathParam("username") String username) { @Path("/{username}") public Response findUser(@PathParam("username") String username) { //FIXME: Catch exceptions - Localuser localuser = localuserBo.findByName(username); Response response; - if (localuser == null) { - response = Response.status(Status.NOT_FOUND).build(); - } else { + try { + Localuser localuser = localuserBo.findByName(username); + if (userRegistrationAuth.canGet(localuser)) { response = Response.status(Status.OK).entity(localuser).build(); } else { response = Response.status(Status.FORBIDDEN).build(); } + } catch (UserNotFoundException ex) { + response = Response.status(Status.NOT_FOUND).build(); } return response; @@ -102,9 +120,8 @@ public Response findUser(@PathParam("username") String username) { @GET @Produces({"application/xml", "application/json"}) @Path("/") - public Response getList() { + public Response getList() { //FIXME: Catch Exceptions - //FIXME: It does not work if the user ask for an XML response if (userRegistrationAuth.canList()) { List users = localuserBo.findLocalusers(); @@ -113,7 +130,7 @@ public Response getList() { users = new ArrayList(); } - return Response.status(Status.OK).entity(users).build(); + return Response.status(Status.OK).entity(new Users(users)).build(); } else { return Response.status(Status.FORBIDDEN).build(); } diff --git a/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java b/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java index 77b92df..cda2be1 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java +++ b/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java @@ -1,6 +1,7 @@ package org.fiware.apps.marketplace.security; import org.fiware.apps.marketplace.bo.LocaluserBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Localuser; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -23,12 +24,13 @@ public class UserManagementService implements UserDetailsService{ @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { - - Localuser userEntity = localuserBo.findByName(username); - if (userEntity == null) + + try { + Localuser userEntity = localuserBo.findByName(username); + return assembler.buildUserFromUserEntity(userEntity); + } catch (UserNotFoundException ex) { throw new UsernameNotFoundException("user not found"); - - return assembler.buildUserFromUserEntity(userEntity); + } } } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java index 6bba1f2..bd056ba 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java @@ -1,6 +1,7 @@ package org.fiware.apps.marketplace.security.auth; import org.fiware.apps.marketplace.bo.LocaluserBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Localuser; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.security.core.context.SecurityContextHolder; @@ -23,7 +24,12 @@ public static AuthUtils getAuthUtils() { private LocaluserBo localuserBo; public Localuser getLoggedUser() { - return localuserBo.findByName(SecurityContextHolder.getContext().getAuthentication().getName()); + try { + return localuserBo.findByName(SecurityContextHolder.getContext().getAuthentication().getName()); + } catch (UserNotFoundException ex) { + //This exception should never happen: a logged user should be found in the database... + return null; + } } } From d6d3224f6e77336fec29bea8754c6c32e048544e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Fri, 21 Nov 2014 11:59:07 +0100 Subject: [PATCH 07/69] Return Error information in requests. --- .../apps/marketplace/model/ErrorType.java | 12 ++ .../apps/marketplace/model/ServiceError.java | 43 +++++++ .../rest/UserRegistrationService.java | 121 +++++++++++++----- .../marketplace/security/auth/AuthUtils.java | 5 +- .../security/auth/UserRegistrationAuth.java | 5 +- 5 files changed, 150 insertions(+), 36 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/model/ErrorType.java create mode 100644 src/main/java/org/fiware/apps/marketplace/model/ServiceError.java diff --git a/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java b/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java new file mode 100644 index 0000000..5f61f81 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java @@ -0,0 +1,12 @@ +package org.fiware.apps.marketplace.model; + +public enum ErrorType { + + BAD_REQUEST, + UNAUTHORIZED, + FORBIDDEN, + NOT_FOUND, + SERVICE_UNAVAILABLE, + + +} diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceError.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceError.java new file mode 100644 index 0000000..298160e --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceError.java @@ -0,0 +1,43 @@ +package org.fiware.apps.marketplace.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "error") +public class ServiceError { + + private ErrorType errorType; + private String errorMessage; + + public ServiceError() { + + } + + public ServiceError(ErrorType errorType, String errorMessage) { + this.errorType = errorType; + this.errorMessage = errorMessage; + } + + @XmlElement(name = "type") + public ErrorType getErrorType() { + return errorType; + } + + public void setErrorType(ErrorType errorType) { + this.errorType = errorType; + } + + @XmlElement(name = "message") + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + + + + +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 1ade766..86edd87 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -17,42 +17,84 @@ import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.ErrorType; +import org.fiware.apps.marketplace.model.ServiceError; import org.fiware.apps.marketplace.model.Localuser; import org.fiware.apps.marketplace.model.Users; import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; +import org.springframework.dao.DataAccessException; + +import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; @Path("/user") public class UserRegistrationService { - - // CLASS ATTRIBUTES // + + // OBJECT ATTRIBUTES // private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); private LocaluserBo localuserBo = (LocaluserBo) context.getBean("localuserBo"); private UserRegistrationAuth userRegistrationAuth = (UserRegistrationAuth) context.getBean("userRegistrationAuth"); - // CLASS METHODS // + // CLASS METHODS: Generate HTTP Responses // + private static Response badRequestResponse(DataAccessException ex) { + String message; + if (ex.getRootCause() instanceof MySQLIntegrityConstraintViolationException) { + message = "The user and/or the email introduced are already registered in the system"; + } else { + message = ex.getRootCause().getMessage(); + } + + return Response.status(Status.BAD_REQUEST).entity( + new ServiceError(ErrorType.BAD_REQUEST, message)).build(); + } + + private static Response userNotFoundResponse(String username) { + return Response.status(Status.NOT_FOUND).entity( + new ServiceError(ErrorType.NOT_FOUND, "User " + username + " not found")).build(); + } + + private static Response unauthorizedResponse(String action) { + return Response.status(Status.UNAUTHORIZED).entity( + new ServiceError(ErrorType.NOT_FOUND, "You are not authorized to " + action)).build(); + } + + private static Response serviceUnavailableResponse(String cause) { + return Response.status(Status.SERVICE_UNAVAILABLE).entity( + new ServiceError(ErrorType.SERVICE_UNAVAILABLE, cause)).build(); + } + + // OBJECT METHODS // @POST @Consumes({"application/xml", "application/json"}) @Path("/") public Response createUser(Localuser localUser) { - //FIXME: Catch Exceptions - if (userRegistrationAuth.canCreate()) { - localUser.setRegistrationDate(new Date()); - localuserBo.save(localUser); - return Response.status(Status.CREATED).build(); - } else { - return Response.status(Status.FORBIDDEN).build(); + + Response response; + try { + if (userRegistrationAuth.canCreate()) { + localUser.setRegistrationDate(new Date()); + localuserBo.save(localUser); + response = Response.status(Status.CREATED).build(); + } else { + response = unauthorizedResponse("create user"); + } + } catch (DataAccessException ex) { + response = badRequestResponse(ex); + } catch (Exception ex) { + response = serviceUnavailableResponse(ex.getCause().getMessage()); } + + return response; + } @PUT @Consumes({"application/xml", "application/json"}) @Path("/{username}") public Response updateUser(@PathParam("username") String username, Localuser localUser) { - //FIXME: Catch exceptions - Response response; + Response response; try { Localuser userToBeUpdated = localuserBo.findByName(username); @@ -64,10 +106,14 @@ public Response updateUser(@PathParam("username") String username, Localuser loc localuserBo.update(userToBeUpdated); response = Response.status(Status.OK).build(); } else { - response = Response.status(Status.FORBIDDEN).build(); + response = unauthorizedResponse("update user " + username); } + } catch (DataAccessException ex) { + response = badRequestResponse(ex); } catch (UserNotFoundException ex) { - response = Response.status(Status.NOT_FOUND).build(); + response = userNotFoundResponse(username); + } catch (Exception ex) { + response = serviceUnavailableResponse(ex.getCause().getMessage()); } return response; @@ -76,9 +122,8 @@ public Response updateUser(@PathParam("username") String username, Localuser loc @DELETE @Path("/{username}") public Response deleteUser(@PathParam("username") String username) { - //FIXME: Catch exceptions + Response response; - try { Localuser userToBeDeleted = localuserBo.findByName(username); // Only a user can delete his/her account @@ -86,10 +131,12 @@ public Response deleteUser(@PathParam("username") String username) { localuserBo.delete(userToBeDeleted); response = Response.status(Status.OK).build(); } else { - response = Response.status(Status.FORBIDDEN).build(); + response = unauthorizedResponse("delete user " + username); } } catch (UserNotFoundException ex) { - response = Response.status(Status.NOT_FOUND).build(); + response = userNotFoundResponse(username); + } catch (Exception ex) { + response = serviceUnavailableResponse(ex.getCause().getMessage()); } return response; @@ -99,19 +146,20 @@ public Response deleteUser(@PathParam("username") String username) { @Produces({"application/xml", "application/json"}) @Path("/{username}") public Response findUser(@PathParam("username") String username) { - //FIXME: Catch exceptions + Response response; - try { Localuser localuser = localuserBo.findByName(username); if (userRegistrationAuth.canGet(localuser)) { response = Response.status(Status.OK).entity(localuser).build(); } else { - response = Response.status(Status.FORBIDDEN).build(); + response = unauthorizedResponse("get user " + username); } } catch (UserNotFoundException ex) { - response = Response.status(Status.NOT_FOUND).build(); + response = userNotFoundResponse(username); + } catch (Exception ex) { + response = serviceUnavailableResponse(ex.getCause().getMessage()); } return response; @@ -121,18 +169,25 @@ public Response findUser(@PathParam("username") String username) { @Produces({"application/xml", "application/json"}) @Path("/") public Response getList() { - //FIXME: Catch Exceptions - if (userRegistrationAuth.canList()) { - List users = localuserBo.findLocalusers(); - - // Return an empty list just in case the system has no users registered - if (users == null){ - users = new ArrayList(); + + Response response; + try { + if (userRegistrationAuth.canList()) { + List users = localuserBo.findLocalusers(); + + // Return an empty list just in case the system has no users registered + if (users == null){ + users = new ArrayList(); + } + + return Response.status(Status.OK).entity(new Users(users)).build(); + } else { + response = unauthorizedResponse("list users"); } - - return Response.status(Status.OK).entity(new Users(users)).build(); - } else { - return Response.status(Status.FORBIDDEN).build(); + } catch (Exception ex) { + response = serviceUnavailableResponse(ex.getCause().getMessage()); } + + return response; } } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java index bd056ba..539ac95 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java @@ -8,7 +8,7 @@ public class AuthUtils { - // Avoid users to instanciate this class + // Avoid users to instantiate this class private AuthUtils() { this.localuserBo = (LocaluserBo) ApplicationContextProvider.getApplicationContext().getBean("localuserBo"); } @@ -27,7 +27,8 @@ public Localuser getLoggedUser() { try { return localuserBo.findByName(SecurityContextHolder.getContext().getAuthentication().getName()); } catch (UserNotFoundException ex) { - //This exception should never happen: a logged user should be found in the database... + //Maybe the user is not logged in + //Maybe the user is not registered in the database return null; } } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java index 32e6e8a..0049d62 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java @@ -8,7 +8,10 @@ public class UserRegistrationAuth { private boolean isTheSameUser(Localuser user) { boolean canAccess = false; - if (AuthUtils.getAuthUtils().getLoggedUser().equals(user)) { + Localuser loggedUser = AuthUtils.getAuthUtils().getLoggedUser(); + + // logged User can be null if the user is not logged in... + if (loggedUser != null && loggedUser.equals(user)) { canAccess = true; } From fa808b9363fd22b4587cbcdb044d7c1ded48ab21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 24 Nov 2014 15:28:20 +0100 Subject: [PATCH 08/69] Encrypt user passwords --- pom.xml | 21 ++++++++++++++++++- .../apps/marketplace/model/Localuser.java | 15 +++++++++---- .../apps/marketplace/rdf/RdfIndexer.java | 2 +- .../HiddenFieldsXMLAdapter.java | 2 +- .../utils/xmladapters/PasswordXMLAdapter.java | 17 +++++++++++++++ .../resources/spring/config/BeanLocations.xml | 16 +++++++------- src/main/resources/spring/config/security.xml | 13 ++++++++---- 7 files changed, 66 insertions(+), 20 deletions(-) rename src/main/java/org/fiware/apps/marketplace/utils/{ => xmladapters}/HiddenFieldsXMLAdapter.java (84%) create mode 100644 src/main/java/org/fiware/apps/marketplace/utils/xmladapters/PasswordXMLAdapter.java diff --git a/pom.xml b/pom.xml index 4001d13..aa367d3 100644 --- a/pom.xml +++ b/pom.xml @@ -125,13 +125,32 @@ spring-orm 4.1.1.RELEASE - + org.springframework spring-aop 4.1.1.RELEASE + + + org.springframework.security + spring-security-core + 3.2.5.RELEASE + + + + org.springframework.security + spring-security-web + 3.2.5.RELEASE + + + + org.springframework.security + spring-security-config + 3.2.5.RELEASE + + org.codehaus.spring-security-oauth spring-security-oauth diff --git a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java b/src/main/java/org/fiware/apps/marketplace/model/Localuser.java index 98234d4..8cc1bc2 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Localuser.java @@ -15,7 +15,10 @@ import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import org.fiware.apps.marketplace.utils.HiddenFieldsXMLAdapter; +import org.fiware.apps.marketplace.utils.xmladapters.HiddenFieldsXMLAdapter; +import org.fiware.apps.marketplace.utils.xmladapters.PasswordXMLAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; @Entity @XmlRootElement(name = "user") @@ -27,7 +30,7 @@ public class Localuser { private String email; private Date registrationDate; private String company; - + @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "LOCALUSER_ID", unique = true, nullable = false) @@ -52,18 +55,22 @@ public void setUsername(String username) { } @XmlElement - @XmlJavaTypeAdapter(HiddenFieldsXMLAdapter.class) //Avoid returning the Password in the XML, JSON + // Avoid returning the password in the API + // Encrypt the password received through the API + @XmlJavaTypeAdapter(PasswordXMLAdapter.class) @Column(name = "LOCALUSER_PASSWORD", nullable = false) public String getPassword() { return password; } public void setPassword(String password) { + // The password is encoded using the user name as salt this.password = password; } @XmlElement - @XmlJavaTypeAdapter(HiddenFieldsXMLAdapter.class) //Avoid returning the Mail in the XML, JSON + // Avoid returning the mail in the API + @XmlJavaTypeAdapter(HiddenFieldsXMLAdapter.class) @Column(name = "LOCALUSER_EMAIL", unique = true, nullable = false) public String getEmail() { return email; diff --git a/src/main/java/org/fiware/apps/marketplace/rdf/RdfIndexer.java b/src/main/java/org/fiware/apps/marketplace/rdf/RdfIndexer.java index c1efafa..3c836cd 100644 --- a/src/main/java/org/fiware/apps/marketplace/rdf/RdfIndexer.java +++ b/src/main/java/org/fiware/apps/marketplace/rdf/RdfIndexer.java @@ -11,7 +11,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.store.LockObtainFailedException; import org.fiware.apps.marketplace.model.Service; -import org.fiware.apps.marketplace.util.PropertiesUtil; +import org.fiware.apps.marketplace.utils.PropertiesUtil; import com.hp.hpl.jena.query.larq.IndexLARQ; import com.hp.hpl.jena.query.larq.LARQ; diff --git a/src/main/java/org/fiware/apps/marketplace/utils/HiddenFieldsXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapter.java similarity index 84% rename from src/main/java/org/fiware/apps/marketplace/utils/HiddenFieldsXMLAdapter.java rename to src/main/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapter.java index 9bb9088..2094aff 100644 --- a/src/main/java/org/fiware/apps/marketplace/utils/HiddenFieldsXMLAdapter.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapter.java @@ -1,4 +1,4 @@ -package org.fiware.apps.marketplace.utils; +package org.fiware.apps.marketplace.utils.xmladapters; import javax.xml.bind.annotation.adapters.XmlAdapter; diff --git a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/PasswordXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/PasswordXMLAdapter.java new file mode 100644 index 0000000..92ced12 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/PasswordXMLAdapter.java @@ -0,0 +1,17 @@ +package org.fiware.apps.marketplace.utils.xmladapters; + +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; +import org.springframework.security.crypto.password.PasswordEncoder; + +public class PasswordXMLAdapter extends HiddenFieldsXMLAdapter{ + + // Encoder must be the same in all the platform: use the bean + private static final PasswordEncoder ENCODER = (PasswordEncoder) + ApplicationContextProvider.getApplicationContext().getBean("encoder"); + + @Override + public String unmarshal(String password) throws Exception { + return ENCODER.encode(password); + } + +} diff --git a/src/main/resources/spring/config/BeanLocations.xml b/src/main/resources/spring/config/BeanLocations.xml index a5f7486..1185002 100644 --- a/src/main/resources/spring/config/BeanLocations.xml +++ b/src/main/resources/spring/config/BeanLocations.xml @@ -1,17 +1,15 @@ - - - + + + - - + + \ No newline at end of file diff --git a/src/main/resources/spring/config/security.xml b/src/main/resources/spring/config/security.xml index c0c8f9c..581019c 100644 --- a/src/main/resources/spring/config/security.xml +++ b/src/main/resources/spring/config/security.xml @@ -7,14 +7,19 @@ http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd"> - + + - - + + + - + + + From 6ca990e6835f2d3ea9fa92c0ce848d0d30332064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 24 Nov 2014 15:42:41 +0100 Subject: [PATCH 09/69] Minor improvements: Restore /vocabulary and /demoservices as services that do not require authentication --- src/main/resources/spring/config/security.xml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/resources/spring/config/security.xml b/src/main/resources/spring/config/security.xml index 581019c..0a38c3d 100644 --- a/src/main/resources/spring/config/security.xml +++ b/src/main/resources/spring/config/security.xml @@ -1,23 +1,25 @@ - + + + - - + - + From 2d13246b003a9792db977a0c0f1436f4acff8020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 24 Nov 2014 15:46:06 +0100 Subject: [PATCH 10/69] Remove default user --- src/main/resources/spring/config/security.xml | 6 ------ .../resources/spring/database/DataSource.xml | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/resources/spring/config/security.xml b/src/main/resources/spring/config/security.xml index 0a38c3d..1a1baf0 100644 --- a/src/main/resources/spring/config/security.xml +++ b/src/main/resources/spring/config/security.xml @@ -1,6 +1,5 @@ - - - - - diff --git a/src/main/resources/spring/database/DataSource.xml b/src/main/resources/spring/database/DataSource.xml index 0e5b59f..9e7a8a5 100644 --- a/src/main/resources/spring/database/DataSource.xml +++ b/src/main/resources/spring/database/DataSource.xml @@ -1,25 +1,27 @@ - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> + + /WEB-INF/classes/properties/database.properties - + /WEB-INF/classes/properties/marketplace.properties - + - + \ No newline at end of file From e0b0e25254086913173e6a44362381a9d1f7487c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 24 Nov 2014 15:49:47 +0100 Subject: [PATCH 11/69] Remove unneeded imports --- src/main/java/org/fiware/apps/marketplace/model/Localuser.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java b/src/main/java/org/fiware/apps/marketplace/model/Localuser.java index 8cc1bc2..d8c1038 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Localuser.java @@ -17,8 +17,6 @@ import org.fiware.apps.marketplace.utils.xmladapters.HiddenFieldsXMLAdapter; import org.fiware.apps.marketplace.utils.xmladapters.PasswordXMLAdapter; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; @Entity @XmlRootElement(name = "user") From 8acfa70398669fa8e2fbf267b4f2c9d4356d6db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 24 Nov 2014 17:56:07 +0100 Subject: [PATCH 12/69] Update Stores API. Fix bugs in Users API. Unify functions --- .../fiware/apps/marketplace/bo/StoreBo.java | 3 +- .../apps/marketplace/bo/impl/StoreBoImpl.java | 15 +- .../fiware/apps/marketplace/dao/StoreDao.java | 3 +- .../dao/impl/LocaluserDaoImpl.java | 5 +- .../marketplace/dao/impl/StoreDaoImpl.java | 32 +-- .../exceptions/StoreNotFoundException.java | 11 + .../apps/marketplace/model/ErrorType.java | 2 +- .../fiware/apps/marketplace/model/Stores.java | 30 +++ .../apps/marketplace/rest/ErrorUtils.java | 52 +++++ .../marketplace/rest/OfferingService.java | 5 +- .../rest/StoreRegistrationService.java | 188 ++++++++++++------ .../rest/UserRegistrationService.java | 72 ++----- .../security/auth/StoreRegistrationAuth.java | 43 ++++ src/main/resources/spring/config/security.xml | 7 +- 14 files changed, 320 insertions(+), 148 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/exceptions/StoreNotFoundException.java create mode 100644 src/main/java/org/fiware/apps/marketplace/model/Stores.java create mode 100644 src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java create mode 100644 src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java diff --git a/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java b/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java index bd80350..4a062e4 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java @@ -2,6 +2,7 @@ import java.util.List; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.model.Store; @@ -9,7 +10,7 @@ public interface StoreBo { void save(Store store); void update(Store store); void delete(Store store); - Store findByName(String name); + Store findByName(String name) throws StoreNotFoundException; List findStores(); } diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java index c808148..08dcfae 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java @@ -1,14 +1,14 @@ package org.fiware.apps.marketplace.bo.impl; - - import java.util.List; import org.fiware.apps.marketplace.bo.StoreBo; import org.fiware.apps.marketplace.dao.StoreDao; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.model.Store; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service("storeBo") public class StoreBoImpl implements StoreBo{ @@ -20,35 +20,34 @@ public void setStoreDao (StoreDao storeDao){ this.storeDao = storeDao; } - @Override + @Transactional(readOnly=false) public void save(Store store) { storeDao.save(store); } @Override + @Transactional(readOnly=false) public void update(Store store) { storeDao.update(store); } @Override + @Transactional(readOnly=false) public void delete(Store store) { storeDao.delete(store); } @Override - public Store findByName(String name) { + public Store findByName(String name) throws StoreNotFoundException { return storeDao.findByName(name); } @Override - public List findStores() { + public List findStores() { return storeDao.findStores(); } - - - } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java b/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java index 11b48d7..cbda5bc 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java @@ -2,13 +2,14 @@ import java.util.List; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.model.Store; public interface StoreDao { void save(Store store); void update(Store store); void delete(Store store); - Store findByName(String url); + Store findByName(String url) throws StoreNotFoundException; List findStores(); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java index 9663af4..079b5f0 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java @@ -1,5 +1,6 @@ package org.fiware.apps.marketplace.dao.impl; +import java.util.ArrayList; import java.util.List; import org.fiware.apps.marketplace.dao.LocaluserDao; @@ -32,7 +33,7 @@ public Localuser findByName(String username) throws UserNotFoundException{ List list = getHibernateTemplate().find("from Localuser where username=?", username); if (list.size() == 0) { - throw new UserNotFoundException(username + " not found"); + throw new UserNotFoundException("User " + username + " not found"); } else { return (Localuser) list.get(0); } @@ -43,7 +44,7 @@ public List findLocalusers() { List list = getHibernateTemplate().loadAll(Localuser.class); if (list.size() == 0){ - return null; + list = new ArrayList(); } return list; diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java index 73a0be5..a4f8562 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java @@ -1,8 +1,10 @@ package org.fiware.apps.marketplace.dao.impl; +import java.util.ArrayList; import java.util.List; import org.fiware.apps.marketplace.dao.StoreDao; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; import org.springframework.stereotype.Repository; @@ -14,47 +16,35 @@ public class StoreDaoImpl extends MarketplaceHibernateDao implements StoreDao { public void save(Store store) { getHibernateTemplate().saveOrUpdate(store); } - - @Override public void update(Store store) { getHibernateTemplate().update(store); - } - - - @Override public void delete(Store store) { getHibernateTemplate().delete(store); - } - - @Override - public Store findByName(String name) { - List list = getHibernateTemplate().find( - "from Store where name=?",name - ); - - System.out.println(list.size()); + public Store findByName(String name) throws StoreNotFoundException { + List list = getHibernateTemplate().find("from Store where name=?", name); - - if (list.size()!=0){ + if (list.size() != 0){ return (Store)list.get(0); - } - return null; + } else { + throw new StoreNotFoundException("Store " + name + " not found"); + } } @Override public List findStores() { - List list = getHibernateTemplate().loadAll(Store.class); + List list = getHibernateTemplate().loadAll(Store.class); + if (list.size()==0){ - return null; + list = new ArrayList(); } return list; diff --git a/src/main/java/org/fiware/apps/marketplace/exceptions/StoreNotFoundException.java b/src/main/java/org/fiware/apps/marketplace/exceptions/StoreNotFoundException.java new file mode 100644 index 0000000..d9aa445 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/exceptions/StoreNotFoundException.java @@ -0,0 +1,11 @@ +package org.fiware.apps.marketplace.exceptions; + +public class StoreNotFoundException extends Exception { + + private static final long serialVersionUID = 1L; + + public StoreNotFoundException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java b/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java index 5f61f81..1ffae6e 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java @@ -7,6 +7,6 @@ public enum ErrorType { FORBIDDEN, NOT_FOUND, SERVICE_UNAVAILABLE, - + INTERNAL_SERVER_ERROR } diff --git a/src/main/java/org/fiware/apps/marketplace/model/Stores.java b/src/main/java/org/fiware/apps/marketplace/model/Stores.java new file mode 100644 index 0000000..5576ab0 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/Stores.java @@ -0,0 +1,30 @@ +package org.fiware.apps.marketplace.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "stores") +public class Stores { + + private List stores = null; + + public Stores() { + this.setStores(new ArrayList()); + } + + public Stores(List stores) { + this.setStores(stores); + } + + @XmlElement(name = "store") + public List getStores() { + return this.stores; + } + + public void setStores(List stores) { + this.stores = stores; + } +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java new file mode 100644 index 0000000..8cf030a --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java @@ -0,0 +1,52 @@ +package org.fiware.apps.marketplace.rest; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.fiware.apps.marketplace.model.ErrorType; +import org.fiware.apps.marketplace.model.ServiceError; +import org.springframework.dao.DataAccessException; + +import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; + +public class ErrorUtils { + + private String contraintViolationMessage; + + public ErrorUtils(String contraintViolationMessage) { + this.contraintViolationMessage = contraintViolationMessage; + } + + public Response badRequestResponse(DataAccessException ex) { + String message; + if (ex.getRootCause() instanceof MySQLIntegrityConstraintViolationException) { + message = this.contraintViolationMessage; + } else { + message = ex.getRootCause().getMessage(); + } + + return Response.status(Status.BAD_REQUEST).entity( + new ServiceError(ErrorType.BAD_REQUEST, message)).build(); + } + + public Response entityNotFoundResponse(Exception ex) { + return Response.status(Status.NOT_FOUND).entity( + new ServiceError(ErrorType.NOT_FOUND, ex.getMessage())).build(); + } + + public Response unauthorizedResponse(String action) { + return Response.status(Status.UNAUTHORIZED).entity( + new ServiceError(ErrorType.UNAUTHORIZED, "You are not authorized to " + action)).build(); + } + + public Response internalServerError(String cause) { + return Response.status(Status.INTERNAL_SERVER_ERROR).entity( + new ServiceError(ErrorType.INTERNAL_SERVER_ERROR, cause)).build(); + } + + public Response serviceUnavailableResponse(String cause) { + return Response.status(Status.SERVICE_UNAVAILABLE).entity( + new ServiceError(ErrorType.SERVICE_UNAVAILABLE, cause)).build(); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java index 619a06a..a1da809 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java @@ -18,6 +18,7 @@ import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.bo.ServiceBo; import org.fiware.apps.marketplace.bo.StoreBo; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; @@ -42,7 +43,7 @@ public class OfferingService { @PUT @Consumes({"application/xml", "application/json"}) @Path("/store/{storeName}/offering") - public Response saveService(@PathParam("storeName") String storeName, Service service) throws UserNotFoundException { + public Response saveService(@PathParam("storeName") String storeName, Service service) throws UserNotFoundException, StoreNotFoundException { //FIXME: Temporal solution. Exception should be caught Store store = storeBo.findByName(storeName); @@ -97,7 +98,7 @@ public Service findService(@PathParam("storeName") String storeName, @PathParam( @GET @Produces({"application/xml", "application/json"}) @Path("/store/{storeName}/offerings/") - public List findServices(@PathParam("storeName") String storeName) { + public List findServices(@PathParam("storeName") String storeName) throws StoreNotFoundException { Store store = storeBo.findByName(storeName); if (store==null){ throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Service Not Found").build()); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 10f576f..a67345d 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -11,96 +11,172 @@ 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.Response; import javax.ws.rs.core.Response.Status; import org.fiware.apps.marketplace.bo.LocaluserBo; -import org.fiware.apps.marketplace.bo.ServiceBo; import org.fiware.apps.marketplace.bo.StoreBo; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Service; +import org.fiware.apps.marketplace.model.Localuser; import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.model.Stores; +import org.fiware.apps.marketplace.security.auth.StoreRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; -import org.springframework.security.core.Authentication; +import org.springframework.dao.DataAccessException; import org.springframework.security.core.context.SecurityContextHolder; -@Path("/registration") -public class StoreRegistrationService { - ApplicationContext appContext = ApplicationContextProvider.getApplicationContext(); +@Path("/store") +public class StoreRegistrationService { - StoreBo storeBo = (StoreBo)appContext.getBean("storeBo"); - ServiceBo serviceBo = (ServiceBo)appContext.getBean("serviceBo"); - LocaluserBo localuserBo = (LocaluserBo)appContext.getBean("localuserBo"); + // OBJECT ATTRIBUTES // + private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); + private StoreBo storeBo = (StoreBo) context.getBean("storeBo"); + private LocaluserBo localuserBo = (LocaluserBo) context.getBean("localuserBo"); + private StoreRegistrationAuth storeRegistrationAuth = (StoreRegistrationAuth) context.getBean("storeRegistrationAuth"); + + // CLASS ATTRIBUTES // + private static final ErrorUtils ERROR_UTILS = new ErrorUtils( + "There is already a Store with that name/URL registered in the system"); - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - String actUser = auth.getName(); + private Localuser getCurrentUser() throws UserNotFoundException { + String username = SecurityContextHolder.getContext().getAuthentication().getName(); + return localuserBo.findByName(username); + } - @PUT + // OBJECT METHODS // + @POST @Consumes({"application/xml", "application/json"}) - @Path("/store") - public Response saveStore(Store store) throws UserNotFoundException { - //FIXME: Temporal solution. Exception should be caught - store.setRegistrationDate(new Date()); - store.setCreator(localuserBo.findByName(actUser)); - store.setLasteditor(localuserBo.findByName(actUser)); - storeBo.save(store); - return Response.status(Status.CREATED).build(); + @Path("/") + public Response createStore(Store store) { + Response response; + + if (storeRegistrationAuth.canCreate()) { + try { + // Get the current user + Localuser currentUser = this.getCurrentUser(); + + store.setRegistrationDate(new Date()); + store.setCreator(currentUser); + store.setLasteditor(currentUser); + + // Save the new Store and return CREATED + storeBo.save(store); + response = Response.status(Status.CREATED).build(); + } catch (UserNotFoundException ex) { + response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); + } catch (DataAccessException ex) { + response = ERROR_UTILS.badRequestResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + } else { + response = ERROR_UTILS.unauthorizedResponse("create store"); + } + + return response; } - @POST + @PUT @Consumes({"application/xml", "application/json"}) - @Path("/store/{storeName}") + @Path("/{storeName}") public Response updateStore(@PathParam("storeName") String storeName, Store store) throws UserNotFoundException { - //FIXME: Temporal solution. Exception should be caught - - Store storeDB = storeBo.findByName(storeName); - storeDB.setName(store.getName()); - storeDB.setUrl(store.getUrl()); - store.setLasteditor(localuserBo.findByName(actUser)); + Response response; - storeBo.update(storeDB); - return Response.status(Status.OK).build(); + try { + Store storeDB = storeBo.findByName(storeName); + if (storeRegistrationAuth.canUpdate(storeDB)) { + storeDB.setName(store.getName()); + storeDB.setUrl(store.getUrl()); + store.setLasteditor(this.getCurrentUser()); + + // Save the new Store and Return OK + storeBo.update(storeDB); + response = Response.status(Status.OK).build(); + } else { + response = ERROR_UTILS.unauthorizedResponse("update store " + storeName); + } + } catch (UserNotFoundException ex) { + response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); + } catch (DataAccessException ex) { + response = ERROR_UTILS.badRequestResponse(ex); + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + + return response; } @DELETE - @Path("/store/{storeName}") - public Response deleteStore(@PathParam("storeName") String storeName) { - Store store = storeBo.findByName(storeName); - storeBo.delete(store); - return Response.status(Status.OK).build(); + @Path("/{storeName}") + public Response deleteStore(@PathParam("storeName") String storeName) { + Response response; + + try { + //Retrieve the Store from the database + Store store = storeBo.findByName(storeName); + + if (storeRegistrationAuth.canDelete(store)) { + storeBo.delete(store); + response = Response.status(Status.OK).build(); // Return OK + } else { + response = ERROR_UTILS.unauthorizedResponse("delete store " + storeName); + } + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + + return response; } @GET @Produces({"application/xml", "application/json"}) - @Path("/store/{storeName}") - public Store findStore(@PathParam("storeName") String storeName) { - Store store = storeBo.findByName(storeName); - if (store==null){ - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Not Found").build()); + @Path("/{storeName}") + public Response getStore(@PathParam("storeName") String storeName) { + Response response; + + try { + // Retrieve the Store from the database + Store store = storeBo.findByName(storeName); + + if (storeRegistrationAuth.canGet(store)) { + response = Response.status(Status.OK).entity(store).build(); //Return the Store + } else { + response = ERROR_UTILS.unauthorizedResponse("get store " + storeName); + } + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - return store; - + + return response; } @GET @Produces({"application/xml", "application/json"}) - @Path("/stores/") - public List findStores() { - List stores = storeBo.findStores(); - if (stores==null){ - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Not Found").build()); + @Path("/") + public Response listStores() { + Response response; + + try { + if (storeRegistrationAuth.canList()) { + List stores = storeBo.findStores(); + response = Response.status(Status.OK).entity(new Stores(stores)).build(); + } else { + response = ERROR_UTILS.unauthorizedResponse("list stores"); + } + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - - - return stores; - + + return response; } - - - - } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 86edd87..66cafbe 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -1,6 +1,5 @@ package org.fiware.apps.marketplace.rest; -import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -17,8 +16,6 @@ import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.ErrorType; -import org.fiware.apps.marketplace.model.ServiceError; import org.fiware.apps.marketplace.model.Localuser; import org.fiware.apps.marketplace.model.Users; import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; @@ -26,7 +23,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.dao.DataAccessException; -import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; @Path("/user") public class UserRegistrationService { @@ -36,33 +32,9 @@ public class UserRegistrationService { private LocaluserBo localuserBo = (LocaluserBo) context.getBean("localuserBo"); private UserRegistrationAuth userRegistrationAuth = (UserRegistrationAuth) context.getBean("userRegistrationAuth"); - // CLASS METHODS: Generate HTTP Responses // - private static Response badRequestResponse(DataAccessException ex) { - String message; - if (ex.getRootCause() instanceof MySQLIntegrityConstraintViolationException) { - message = "The user and/or the email introduced are already registered in the system"; - } else { - message = ex.getRootCause().getMessage(); - } - - return Response.status(Status.BAD_REQUEST).entity( - new ServiceError(ErrorType.BAD_REQUEST, message)).build(); - } - - private static Response userNotFoundResponse(String username) { - return Response.status(Status.NOT_FOUND).entity( - new ServiceError(ErrorType.NOT_FOUND, "User " + username + " not found")).build(); - } - - private static Response unauthorizedResponse(String action) { - return Response.status(Status.UNAUTHORIZED).entity( - new ServiceError(ErrorType.NOT_FOUND, "You are not authorized to " + action)).build(); - } - - private static Response serviceUnavailableResponse(String cause) { - return Response.status(Status.SERVICE_UNAVAILABLE).entity( - new ServiceError(ErrorType.SERVICE_UNAVAILABLE, cause)).build(); - } + // CLASS ATTRIBUTES // + private static final ErrorUtils ERROR_UTILS = new ErrorUtils( + "The user and/or the email introduced are already registered in the system"); // OBJECT METHODS // @POST @@ -77,12 +49,12 @@ public Response createUser(Localuser localUser) { localuserBo.save(localUser); response = Response.status(Status.CREATED).build(); } else { - response = unauthorizedResponse("create user"); + response = ERROR_UTILS.unauthorizedResponse("create user"); } } catch (DataAccessException ex) { - response = badRequestResponse(ex); + response = ERROR_UTILS.badRequestResponse(ex); } catch (Exception ex) { - response = serviceUnavailableResponse(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } return response; @@ -106,14 +78,14 @@ public Response updateUser(@PathParam("username") String username, Localuser loc localuserBo.update(userToBeUpdated); response = Response.status(Status.OK).build(); } else { - response = unauthorizedResponse("update user " + username); + response = ERROR_UTILS.unauthorizedResponse("update user " + username); } } catch (DataAccessException ex) { - response = badRequestResponse(ex); + response = ERROR_UTILS.badRequestResponse(ex); } catch (UserNotFoundException ex) { - response = userNotFoundResponse(username); + response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = serviceUnavailableResponse(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } return response; @@ -131,12 +103,12 @@ public Response deleteUser(@PathParam("username") String username) { localuserBo.delete(userToBeDeleted); response = Response.status(Status.OK).build(); } else { - response = unauthorizedResponse("delete user " + username); + response = ERROR_UTILS.unauthorizedResponse("delete user " + username); } } catch (UserNotFoundException ex) { - response = userNotFoundResponse(username); + response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = serviceUnavailableResponse(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } return response; @@ -154,12 +126,12 @@ public Response findUser(@PathParam("username") String username) { if (userRegistrationAuth.canGet(localuser)) { response = Response.status(Status.OK).entity(localuser).build(); } else { - response = unauthorizedResponse("get user " + username); + response = ERROR_UTILS.unauthorizedResponse("get user " + username); } } catch (UserNotFoundException ex) { - response = userNotFoundResponse(username); + response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = serviceUnavailableResponse(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } return response; @@ -168,24 +140,18 @@ public Response findUser(@PathParam("username") String username) { @GET @Produces({"application/xml", "application/json"}) @Path("/") - public Response getList() { + public Response listUsers() { Response response; try { if (userRegistrationAuth.canList()) { List users = localuserBo.findLocalusers(); - - // Return an empty list just in case the system has no users registered - if (users == null){ - users = new ArrayList(); - } - return Response.status(Status.OK).entity(new Users(users)).build(); } else { - response = unauthorizedResponse("list users"); + response = ERROR_UTILS.unauthorizedResponse("list users"); } } catch (Exception ex) { - response = serviceUnavailableResponse(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } return response; diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java new file mode 100644 index 0000000..1d0023e --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java @@ -0,0 +1,43 @@ +package org.fiware.apps.marketplace.security.auth; + +import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.Store; +import org.springframework.stereotype.Service; + +@Service("storeRegistrationAuth") +public class StoreRegistrationAuth { + + private boolean isTheSameUser(Store store) { + boolean canAccess = false; + Localuser loggedUser = AuthUtils.getAuthUtils().getLoggedUser(); + + // logged User can be null if the user is not logged in... + if (loggedUser != null && loggedUser.equals(store.getCreator())) { + canAccess = true; + } + + return canAccess; + } + + public boolean canCreate() { + return AuthUtils.getAuthUtils().getLoggedUser() != null; + } + + public boolean canUpdate(Store store) { + return this.isTheSameUser(store); + } + + public boolean canDelete(Store store) { + return this.isTheSameUser(store); + } + + public boolean canGet(Store store) { + return true; + } + + public boolean canList() { + return true; + } + + +} diff --git a/src/main/resources/spring/config/security.xml b/src/main/resources/spring/config/security.xml index 1a1baf0..842d25c 100644 --- a/src/main/resources/spring/config/security.xml +++ b/src/main/resources/spring/config/security.xml @@ -8,9 +8,10 @@ http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd"> - - - + + + + From 0ee058a06cf00a739b784da953c61ea8daa6ded3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 25 Nov 2014 17:07:09 +0100 Subject: [PATCH 13/69] Improve Offerings API. Fix some bugs. Refactor --- .../fiware/apps/marketplace/bo/ServiceBo.java | 8 +- .../marketplace/bo/impl/ServiceBoImpl.java | 17 +- .../apps/marketplace/dao/ServiceDao.java | 5 +- .../marketplace/dao/impl/ServiceDaoImpl.java | 33 +-- .../marketplace/dao/impl/StoreDaoImpl.java | 6 +- .../exceptions/ServiceNotFoundException.java | 11 + .../apps/marketplace/model/Service.java | 2 - .../apps/marketplace/model/Services.java | 30 +++ .../rest/OfferingRegistrationService.java | 200 ++++++++++++++++++ .../marketplace/rest/OfferingService.java | 111 ---------- .../rest/StoreRegistrationService.java | 14 +- .../marketplace/security/auth/AuthUtils.java | 10 +- .../auth/OfferingRegistrationAuth.java | 15 ++ .../security/auth/RegistrationAuth.java | 92 ++++++++ .../security/auth/StoreRegistrationAuth.java | 38 +--- .../security/auth/UserRegistrationAuth.java | 33 +-- src/main/webapp/WEB-INF/web.xml | 2 +- .../fiware/apps/marketplace/tests/App.java | 8 +- 18 files changed, 406 insertions(+), 229 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/exceptions/ServiceNotFoundException.java create mode 100644 src/main/java/org/fiware/apps/marketplace/model/Services.java create mode 100644 src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java delete mode 100644 src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java create mode 100644 src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java create mode 100644 src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java diff --git a/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java b/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java index bd07f03..e9b759f 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java @@ -1,12 +1,14 @@ package org.fiware.apps.marketplace.bo; +import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.model.Service; public interface ServiceBo { void save(Service service); void update(Service service); void delete(Service service); - Service findByName(String name); - Service findByNameAndStore(String name, String store); - Service findById(Integer id); + Service findByName(String name) throws ServiceNotFoundException; + Service findByNameAndStore(String name, String store) throws ServiceNotFoundException, StoreNotFoundException; + Service findById(Integer id) throws ServiceNotFoundException; } diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java index 13f7365..27a1dc9 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java @@ -2,14 +2,12 @@ import org.fiware.apps.marketplace.bo.ServiceBo; import org.fiware.apps.marketplace.dao.ServiceDao; +import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.model.Service; -import org.fiware.apps.marketplace.rdf.RdfHelper; import org.fiware.apps.marketplace.rdf.RdfIndexer; -import org.fiware.apps.marketplace.utils.PropertiesUtil; import org.springframework.beans.factory.annotation.Autowired; - -import com.hp.hpl.jena.rdf.model.Model; - +import org.springframework.transaction.annotation.Transactional; @org.springframework.stereotype.Service("serviceBo") public class ServiceBoImpl implements ServiceBo{ @@ -22,12 +20,14 @@ public void setServiceDao (ServiceDao serviceDao){ } @Override + @Transactional(readOnly=false) public void save(Service service) { serviceDao.save(service); RdfIndexer.indexService(service); } @Override + @Transactional(readOnly=false) public void update(Service service) { serviceDao.update(service); RdfIndexer.deleteService(service); @@ -35,23 +35,24 @@ public void update(Service service) { } @Override + @Transactional(readOnly=false) public void delete(Service service) { serviceDao.delete(service); RdfIndexer.deleteService(service); } @Override - public Service findById(Integer id) { + public Service findById(Integer id) throws ServiceNotFoundException{ return serviceDao.findById(id); } @Override - public Service findByName(String name) { + public Service findByName(String name) throws ServiceNotFoundException { return serviceDao.findByName(name); } @Override - public Service findByNameAndStore(String name, String store) { + public Service findByNameAndStore(String name, String store) throws ServiceNotFoundException, StoreNotFoundException { return serviceDao.findByNameAndStore(name, store); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java b/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java index 9cbcefb..8e50f18 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java @@ -1,12 +1,13 @@ package org.fiware.apps.marketplace.dao; +import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; import org.fiware.apps.marketplace.model.Service; public interface ServiceDao { void save(Service service); void update(Service service); void delete(Service service); - Service findByName(String name); - Service findByNameAndStore(String name, String store); + Service findByName(String name) throws ServiceNotFoundException; + Service findByNameAndStore(String name, String store) throws ServiceNotFoundException; Service findById(Integer id); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java index 08a941e..ec83ba4 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java @@ -3,6 +3,7 @@ import java.util.List; import org.fiware.apps.marketplace.dao.ServiceDao; +import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; import org.springframework.stereotype.Repository; @@ -26,31 +27,31 @@ public void delete(Service service) { } @Override - public Service findById(Integer id){ + public Service findById(Integer id) { Object res = getHibernateTemplate().get(Service.class, id); return (Service) res; } + private Service findByQuery(String query, Object[] params) throws ServiceNotFoundException { + List list = getHibernateTemplate().find(query, params); + + if (list.size() == 0) { + throw new ServiceNotFoundException("Service " + params[0] + " not found"); + } else { + return (Service) list.get(0); + } + } + @Override - public Service findByName(String name) { - List list = getHibernateTemplate().find( - "from Service where name=?",name - ); - if (list.size()!=0){ - return (Service)list.get(0); - } - return null; + public Service findByName(String name) throws ServiceNotFoundException { + Object[] params = {name}; + return this.findByQuery("from Service where name = ?", params); } @Override - public Service findByNameAndStore(String name, String store) { + public Service findByNameAndStore(String name, String store) throws ServiceNotFoundException { Object[] params = {name , store}; - List list = getHibernateTemplate().find("from Service where name=? and store.name =?", params); - - if (list.size()!=0){ - return (Service)list.get(0); - } - return null; + return this.findByQuery("from Service where name = ? and store.name = ?", params); } } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java index a4f8562..9660923 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java @@ -31,10 +31,10 @@ public void delete(Store store) { public Store findByName(String name) throws StoreNotFoundException { List list = getHibernateTemplate().find("from Store where name=?", name); - if (list.size() != 0){ - return (Store)list.get(0); - } else { + if (list.size() == 0){ throw new StoreNotFoundException("Store " + name + " not found"); + } else { + return (Store) list.get(0); } } diff --git a/src/main/java/org/fiware/apps/marketplace/exceptions/ServiceNotFoundException.java b/src/main/java/org/fiware/apps/marketplace/exceptions/ServiceNotFoundException.java new file mode 100644 index 0000000..267c4db --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/exceptions/ServiceNotFoundException.java @@ -0,0 +1,11 @@ +package org.fiware.apps.marketplace.exceptions; + +public class ServiceNotFoundException extends Exception { + + private static final long serialVersionUID = 1L; + + public ServiceNotFoundException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/model/Service.java b/src/main/java/org/fiware/apps/marketplace/model/Service.java index 98d0de3..e34c1a5 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Service.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Service.java @@ -98,7 +98,6 @@ public void setStore(Store store) { } @XmlElement - //@XmlTransient @ManyToOne(optional = false) @JoinColumn(name = "LOCALUSER_LAST_EDITOR_ID", nullable=false) public Localuser getLasteditor() { @@ -110,7 +109,6 @@ public void setLasteditor(Localuser lasteditor) { } @XmlElement - //@XmlTransient @ManyToOne(optional = false) @JoinColumn(name = "LOCALUSER_CREATOR_ID", nullable=false) public Localuser getCreator() { diff --git a/src/main/java/org/fiware/apps/marketplace/model/Services.java b/src/main/java/org/fiware/apps/marketplace/model/Services.java new file mode 100644 index 0000000..fc64f27 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/Services.java @@ -0,0 +1,30 @@ +package org.fiware.apps.marketplace.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "services") +public class Services { + + private List services = null; + + public Services() { + this.setServices(new ArrayList()); + } + + public Services(List services) { + this.setServices(services); + } + + @XmlElement(name = "service") + public List getServices() { + return this.services; + } + + public void setServices(List services) { + this.services = services; + } +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java new file mode 100644 index 0000000..108c78c --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -0,0 +1,200 @@ +package org.fiware.apps.marketplace.rest; + +import java.util.Date; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.fiware.apps.marketplace.bo.ServiceBo; +import org.fiware.apps.marketplace.bo.StoreBo; +import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.Service; +import org.fiware.apps.marketplace.model.Services; +import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.security.auth.AuthUtils; +import org.fiware.apps.marketplace.security.auth.OfferingRegistrationAuth; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; +import org.springframework.context.ApplicationContext; +import org.springframework.dao.DataAccessException; + +@Path("/store/{storeName}/offering") +public class OfferingRegistrationService { + + // OBJECT ATTRIBUTES // + private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); + private StoreBo storeBo = (StoreBo) context.getBean("storeBo"); + private ServiceBo serviceBo = (ServiceBo) context.getBean("serviceBo"); + private OfferingRegistrationAuth offeringRegistrationAuth = (OfferingRegistrationAuth) + context.getBean("offeringRegistrationAuth"); + + // CLASS ATTRIBUTES // + private static final AuthUtils AUTH_UTILS = AuthUtils.getAuthUtils(); + private static final ErrorUtils ERROR_UTILS = new ErrorUtils( + "There is already an Offering in this Store with that name/URL"); + + @POST + @Consumes({"application/xml", "application/json"}) + @Path("/") + public Response saveService(@PathParam("storeName") String storeName, Service service) { + Response response; + + if (offeringRegistrationAuth.canCreate()) { + try { + Localuser user = AUTH_UTILS.getLoggedUser(); + Store store = storeBo.findByName(storeName); + service.setRegistrationDate(new Date()); + service.setStore(store); + service.setCreator(user); + service.setLasteditor(user); + + serviceBo.save(service); + response = Response.status(Status.CREATED).build(); + } catch (StoreNotFoundException ex) { + //The Store is an URL... If the Store does not exist a 404 + //should be returned instead of a 400 + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (UserNotFoundException ex) { + response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); + } catch (DataAccessException ex) { + response = ERROR_UTILS.badRequestResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + } else { + response = ERROR_UTILS.unauthorizedResponse("create offering"); + } + + return response; + } + + + @PUT + @Consumes({"application/xml", "application/json"}) + @Path("/{serviceName}") + public Response updateService(@PathParam("storeName") String storeName, + @PathParam("serviceName") String serviceName, Service serviceInfo) { + + Response response; + + try { + @SuppressWarnings("unused") + Store store = storeBo.findByName(storeName); //Check that the Store exists + Service service = serviceBo.findByNameAndStore(serviceName, storeName); + + if (offeringRegistrationAuth.canUpdate(service)) { + service.setName(serviceInfo.getName()); + service.setUrl(serviceInfo.getUrl()); + service.setLasteditor(AUTH_UTILS.getLoggedUser()); + //TODO: merger in model + + serviceBo.update(service); + response = Response.status(Status.OK).build(); + } else { + response = ERROR_UTILS.unauthorizedResponse("update offering " + serviceName); + } + } catch (ServiceNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (UserNotFoundException ex) { + response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); + } catch (DataAccessException ex) { + response = ERROR_UTILS.badRequestResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + + return response; + } + + @DELETE + @Path("/{serviceName}") + public Response deleteService(@PathParam("storeName") String storeName, @PathParam("serviceName") String serviceName) { + Response response; + + try { + @SuppressWarnings("unused") + Store store = storeBo.findByName(storeName); //Check that the Store exists + Service service = serviceBo.findByNameAndStore(serviceName, storeName); + + if (offeringRegistrationAuth.canUpdate(service)) { + serviceBo.delete(service); + response = Response.status(Status.OK).build(); + } else { + response = ERROR_UTILS.unauthorizedResponse("update offering " + serviceName); + } + } catch (ServiceNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + + return response; + } + + @GET + @Produces({"application/xml", "application/json"}) + @Path("/{serviceName}") + public Response getService(@PathParam("storeName") String storeName, + @PathParam("serviceName") String serviceName) { + Response response; + + try { + @SuppressWarnings("unused") + Store store = storeBo.findByName(storeName); //Check that the Store exists + Service service = serviceBo.findByNameAndStore(serviceName, storeName); + + if (offeringRegistrationAuth.canGet(service)) { + response = Response.status(Status.OK).entity(service).build(); + } else { + response = ERROR_UTILS.unauthorizedResponse("get offering " + serviceName); + } + } catch (ServiceNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + + return response; + } + + @GET + @Produces({"application/xml", "application/json"}) + @Path("/") + public Response listServices(@PathParam("storeName") String storeName) { + Response response; + + if (offeringRegistrationAuth.canList()) { + try { + Store store = storeBo.findByName(storeName); + response = Response.status(Status.OK).entity(new Services(store.getServices())).build(); + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + } else { + response = ERROR_UTILS.unauthorizedResponse("list offerings"); + } + + return response; + + } + + +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java deleted file mode 100644 index a1da809..0000000 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingService.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.fiware.apps.marketplace.rest; - -import java.util.Date; -import java.util.List; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -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.Response; -import javax.ws.rs.core.Response.Status; - -import org.fiware.apps.marketplace.bo.LocaluserBo; -import org.fiware.apps.marketplace.bo.ServiceBo; -import org.fiware.apps.marketplace.bo.StoreBo; -import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; -import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Service; -import org.fiware.apps.marketplace.model.Store; -import org.fiware.apps.marketplace.utils.ApplicationContextProvider; -import org.springframework.context.ApplicationContext; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; - -@Path("/offering") -public class OfferingService { - - ApplicationContext appContext = ApplicationContextProvider.getApplicationContext(); - - StoreBo storeBo = (StoreBo)appContext.getBean("storeBo"); - ServiceBo serviceBo = (ServiceBo)appContext.getBean("serviceBo"); - LocaluserBo localuserBo = (LocaluserBo)appContext.getBean("localuserBo"); - - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - String actUser = auth.getName(); - - - @PUT - @Consumes({"application/xml", "application/json"}) - @Path("/store/{storeName}/offering") - public Response saveService(@PathParam("storeName") String storeName, Service service) throws UserNotFoundException, StoreNotFoundException { - //FIXME: Temporal solution. Exception should be caught - - Store store = storeBo.findByName(storeName); - if (store==null){ - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Not Found").build()); - } - service.setRegistrationDate(new Date()); - service.setStore(store); - service.setCreator(localuserBo.findByName(actUser)); - service.setLasteditor(localuserBo.findByName(actUser)); - - serviceBo.save(service); - return Response.status(Status.CREATED).build(); - } - - - @POST - @Consumes({"application/xml", "application/json"}) - @Path("/store/{storeName}/offering/{serviceName}") - public Response updateService(@PathParam("storeName") String storeName, @PathParam("serviceName") String serviceName, Service service) throws UserNotFoundException { - //FIXME: Temporal solution. Exception should be caught - Service serviceDB = serviceBo.findByNameAndStore(serviceName, storeName); - - serviceDB.setName(service.getName()); - serviceDB.setUrl(service.getUrl()); - serviceDB.setLasteditor(localuserBo.findByName(actUser)); - //TODO: merger in model - serviceBo.update(serviceDB); - return Response.status(Status.OK).build(); - } - - @DELETE - @Path("/store/{storeName}/offering/{serviceName}") - public Response deleteService(@PathParam("storeName") String storeName, @PathParam("serviceName") String serviceName) { - Service service = serviceBo.findByNameAndStore(serviceName, storeName); - serviceBo.delete(service); - return Response.status(Status.OK).build(); - } - - @GET - @Produces({"application/xml", "application/json"}) - @Path("/store/{storeName}/offering/{serviceName}") - public Service findService(@PathParam("storeName") String storeName, @PathParam("serviceName") String serviceName) { - Service service = serviceBo.findByNameAndStore(serviceName, storeName); - if (service==null){ - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Service Not Found").build()); - } - return service; - - } - - @GET - @Produces({"application/xml", "application/json"}) - @Path("/store/{storeName}/offerings/") - public List findServices(@PathParam("storeName") String storeName) throws StoreNotFoundException { - Store store = storeBo.findByName(storeName); - if (store==null){ - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Service Not Found").build()); - } - return store.getServices(); - - } - - -} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index a67345d..e731ca7 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -14,18 +14,17 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.fiware.apps.marketplace.bo.LocaluserBo; import org.fiware.apps.marketplace.bo.StoreBo; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Localuser; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.model.Stores; +import org.fiware.apps.marketplace.security.auth.AuthUtils; import org.fiware.apps.marketplace.security.auth.StoreRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; import org.springframework.dao.DataAccessException; -import org.springframework.security.core.context.SecurityContextHolder; @Path("/store") @@ -34,18 +33,13 @@ public class StoreRegistrationService { // OBJECT ATTRIBUTES // private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); private StoreBo storeBo = (StoreBo) context.getBean("storeBo"); - private LocaluserBo localuserBo = (LocaluserBo) context.getBean("localuserBo"); private StoreRegistrationAuth storeRegistrationAuth = (StoreRegistrationAuth) context.getBean("storeRegistrationAuth"); // CLASS ATTRIBUTES // + private static final AuthUtils AUTH_UTILS = AuthUtils.getAuthUtils(); private static final ErrorUtils ERROR_UTILS = new ErrorUtils( "There is already a Store with that name/URL registered in the system"); - private Localuser getCurrentUser() throws UserNotFoundException { - String username = SecurityContextHolder.getContext().getAuthentication().getName(); - return localuserBo.findByName(username); - } - // OBJECT METHODS // @POST @Consumes({"application/xml", "application/json"}) @@ -56,7 +50,7 @@ public Response createStore(Store store) { if (storeRegistrationAuth.canCreate()) { try { // Get the current user - Localuser currentUser = this.getCurrentUser(); + Localuser currentUser = AUTH_UTILS.getLoggedUser(); store.setRegistrationDate(new Date()); store.setCreator(currentUser); @@ -91,7 +85,7 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor if (storeRegistrationAuth.canUpdate(storeDB)) { storeDB.setName(store.getName()); storeDB.setUrl(store.getUrl()); - store.setLasteditor(this.getCurrentUser()); + store.setLasteditor(AUTH_UTILS.getLoggedUser()); // Save the new Store and Return OK storeBo.update(storeDB); diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java index 539ac95..59cbf8f 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java @@ -23,14 +23,8 @@ public static AuthUtils getAuthUtils() { //Instance attributes private LocaluserBo localuserBo; - public Localuser getLoggedUser() { - try { - return localuserBo.findByName(SecurityContextHolder.getContext().getAuthentication().getName()); - } catch (UserNotFoundException ex) { - //Maybe the user is not logged in - //Maybe the user is not registered in the database - return null; - } + public Localuser getLoggedUser() throws UserNotFoundException { + return localuserBo.findByName(SecurityContextHolder.getContext().getAuthentication().getName()); } } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java new file mode 100644 index 0000000..a2981b0 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java @@ -0,0 +1,15 @@ +package org.fiware.apps.marketplace.security.auth; + +import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.Service; + + +@org.springframework.stereotype.Service("offeringRegistrationAuth") +public class OfferingRegistrationAuth extends RegistrationAuth { + + @Override + protected Localuser getEntityOwner(Service service) { + return service.getCreator(); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java new file mode 100644 index 0000000..36c0238 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java @@ -0,0 +1,92 @@ +package org.fiware.apps.marketplace.security.auth; + +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.Localuser; + +public abstract class RegistrationAuth { + + /** + * Method to return the Localuser who is owner of the entity + * @param entity The entity whose owner the developer wants to know + * @return The owner of the entity + */ + protected abstract Localuser getEntityOwner(T entity); + + /** + * Method to know if the logged user is the owner of the entity + * @param entity The entity to check. + * @return True if the logged user is the owner of the entity. False otherwise + */ + protected boolean isLoggedUserTheOwner(T entity) { + boolean canAccess = false; + + try { + Localuser loggedUser = AuthUtils.getAuthUtils().getLoggedUser(); + // logged User can be null if the user is not logged in... + if (loggedUser != null && loggedUser.equals(this.getEntityOwner(entity))) { + canAccess = true; + } + } catch (UserNotFoundException ex) { + // Nothing to do... False will be returned + } + + return canAccess; + + } + + /** + * Method to know if the user is logged in + * @return True if the user is logged in. Otherwise, it will return False + */ + protected boolean isLoggedIn() { + boolean isLoggedIn = false; + + try { + isLoggedIn = AuthUtils.getAuthUtils().getLoggedUser() != null; + } catch (UserNotFoundException ex) { + //Nothing to do... False will be returned + } + + return isLoggedIn; + } + + /** + * @return By default it returns True if the user is logged in + */ + public boolean canCreate() { + return this.isLoggedIn(); + } + + /** + * @param entity The entity that is going to be updated + * @return By default it returns True if the logged user is the owner of the entity + */ + public boolean canUpdate(T entity) { + return this.isLoggedUserTheOwner(entity); + } + + /** + * @param entity The entity that is going to be deleted + * @return By default it returns True if the logged user is the owner of the entity + */ + public boolean canDelete(T entity) { + return this.isLoggedUserTheOwner(entity); + } + + /** + * @param entity The entity that is going to be got + * @return By default it returns True + */ + public boolean canGet(T entity) { + return true; + } + + /** + * @return By default, it returns True + */ + public boolean canList() { + return true; + } + + +} diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java index 1d0023e..4e25a34 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java @@ -5,39 +5,11 @@ import org.springframework.stereotype.Service; @Service("storeRegistrationAuth") -public class StoreRegistrationAuth { - - private boolean isTheSameUser(Store store) { - boolean canAccess = false; - Localuser loggedUser = AuthUtils.getAuthUtils().getLoggedUser(); - - // logged User can be null if the user is not logged in... - if (loggedUser != null && loggedUser.equals(store.getCreator())) { - canAccess = true; - } - - return canAccess; - } - - public boolean canCreate() { - return AuthUtils.getAuthUtils().getLoggedUser() != null; - } - - public boolean canUpdate(Store store) { - return this.isTheSameUser(store); - } - - public boolean canDelete(Store store) { - return this.isTheSameUser(store); - } - - public boolean canGet(Store store) { - return true; - } - - public boolean canList() { - return true; +public class StoreRegistrationAuth extends RegistrationAuth { + + @Override + protected Localuser getEntityOwner(Store store) { + return store.getCreator(); } - } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java index 0049d62..a74f165 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java @@ -4,39 +4,16 @@ import org.springframework.stereotype.Service; @Service("userRegistrationAuth") -public class UserRegistrationAuth { +public class UserRegistrationAuth extends RegistrationAuth { - private boolean isTheSameUser(Localuser user) { - boolean canAccess = false; - Localuser loggedUser = AuthUtils.getAuthUtils().getLoggedUser(); - - // logged User can be null if the user is not logged in... - if (loggedUser != null && loggedUser.equals(user)) { - canAccess = true; - } - - return canAccess; + @Override + protected Localuser getEntityOwner(Localuser user) { + return user; } + @Override public boolean canCreate() { return true; } - - public boolean canUpdate(Localuser user) { - return this.isTheSameUser(user); - } - - public boolean canDelete(Localuser user) { - return this.isTheSameUser(user); - } - - public boolean canGet(Localuser user) { - return true; - } - - public boolean canList() { - return true; - } - } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 0fa60ee..1089b81 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -70,7 +70,7 @@ org.fiware.apps.marketplace.rest.StoreRegistrationService, org.fiware.apps.marketplace.rest.SearchService, org.fiware.apps.marketplace.rest.UserRegistrationService, - org.fiware.apps.marketplace.rest.OfferingService, + org.fiware.apps.marketplace.rest.OfferingRegistrationService, org.fiware.apps.marketplace.rest.RatingService, org.fiware.apps.marketplace.rest.RecommendationService, org.fiware.apps.marketplace.rest.CompareService, diff --git a/src/test/java/org/fiware/apps/marketplace/tests/App.java b/src/test/java/org/fiware/apps/marketplace/tests/App.java index 37eab24..64afffa 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/App.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/App.java @@ -21,12 +21,12 @@ public static void main( String[] args ) serviceBo.save(service); /** select **/ - Service service2 = serviceBo.findByName("testurl"); - System.out.println(service2); + //Service service2 = serviceBo.findByName("testurl"); + //System.out.println(service2); /** update **/ - service2.setName("HAIO-1"); - serviceBo.update(service2); + //service2.setName("HAIO-1"); + //serviceBo.update(service2); /** delete **/ //serviceBo.delete(service2); From 048bdb55834531f3ff7bc1c0654199ed3d9b0445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 25 Nov 2014 17:50:12 +0100 Subject: [PATCH 14/69] Create Tables Automatically without running the SQL script to ease the installation process --- src/main/resources/spring/database/Hibernate.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/spring/database/Hibernate.xml b/src/main/resources/spring/database/Hibernate.xml index da890f7..44946f0 100644 --- a/src/main/resources/spring/database/Hibernate.xml +++ b/src/main/resources/spring/database/Hibernate.xml @@ -22,6 +22,7 @@ org.hibernate.dialect.MySQLDialect true + update From c5192a56791b305816b181c41a311bea8a216b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 25 Nov 2014 17:53:00 +0100 Subject: [PATCH 15/69] Change name to avoid confussion --- .../model/{ServiceError.java => APIError.java} | 6 +++--- .../org/fiware/apps/marketplace/rest/ErrorUtils.java | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) rename src/main/java/org/fiware/apps/marketplace/model/{ServiceError.java => APIError.java} (85%) diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceError.java b/src/main/java/org/fiware/apps/marketplace/model/APIError.java similarity index 85% rename from src/main/java/org/fiware/apps/marketplace/model/ServiceError.java rename to src/main/java/org/fiware/apps/marketplace/model/APIError.java index 298160e..2fb3715 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceError.java +++ b/src/main/java/org/fiware/apps/marketplace/model/APIError.java @@ -4,16 +4,16 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "error") -public class ServiceError { +public class APIError { private ErrorType errorType; private String errorMessage; - public ServiceError() { + public APIError() { } - public ServiceError(ErrorType errorType, String errorMessage) { + public APIError(ErrorType errorType, String errorMessage) { this.errorType = errorType; this.errorMessage = errorMessage; } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java index 8cf030a..9a10043 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java @@ -4,7 +4,7 @@ import javax.ws.rs.core.Response.Status; import org.fiware.apps.marketplace.model.ErrorType; -import org.fiware.apps.marketplace.model.ServiceError; +import org.fiware.apps.marketplace.model.APIError; import org.springframework.dao.DataAccessException; import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; @@ -26,27 +26,27 @@ public Response badRequestResponse(DataAccessException ex) { } return Response.status(Status.BAD_REQUEST).entity( - new ServiceError(ErrorType.BAD_REQUEST, message)).build(); + new APIError(ErrorType.BAD_REQUEST, message)).build(); } public Response entityNotFoundResponse(Exception ex) { return Response.status(Status.NOT_FOUND).entity( - new ServiceError(ErrorType.NOT_FOUND, ex.getMessage())).build(); + new APIError(ErrorType.NOT_FOUND, ex.getMessage())).build(); } public Response unauthorizedResponse(String action) { return Response.status(Status.UNAUTHORIZED).entity( - new ServiceError(ErrorType.UNAUTHORIZED, "You are not authorized to " + action)).build(); + new APIError(ErrorType.UNAUTHORIZED, "You are not authorized to " + action)).build(); } public Response internalServerError(String cause) { return Response.status(Status.INTERNAL_SERVER_ERROR).entity( - new ServiceError(ErrorType.INTERNAL_SERVER_ERROR, cause)).build(); + new APIError(ErrorType.INTERNAL_SERVER_ERROR, cause)).build(); } public Response serviceUnavailableResponse(String cause) { return Response.status(Status.SERVICE_UNAVAILABLE).entity( - new ServiceError(ErrorType.SERVICE_UNAVAILABLE, cause)).build(); + new APIError(ErrorType.SERVICE_UNAVAILABLE, cause)).build(); } } From a8d147ab7f3ef2911a32af40e5d9954728622a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 1 Dec 2014 12:41:26 +0100 Subject: [PATCH 16/69] Modify the database structure. Add more details for users table --- license.txt | 1 + .../apps/marketplace/bo/LocaluserBo.java | 14 ---- .../fiware/apps/marketplace/bo/UserBo.java | 16 +++++ .../marketplace/bo/impl/LocaluserBoImpl.java | 51 -------------- .../apps/marketplace/bo/impl/UserBoImpl.java | 51 ++++++++++++++ .../apps/marketplace/dao/LocaluserDao.java | 14 ---- .../fiware/apps/marketplace/dao/UserDao.java | 14 ++++ .../dao/impl/LocaluserDaoImpl.java | 53 -------------- .../marketplace/dao/impl/UserDaoImpl.java | 53 ++++++++++++++ .../marketplace/db/HibernateDDLGenerator.java | 4 +- .../apps/marketplace/model/Service.java | 65 +++++++++-------- .../fiware/apps/marketplace/model/Store.java | 69 +++++++++---------- .../model/{Localuser.java => User.java} | 55 +++++++++------ .../fiware/apps/marketplace/model/Users.java | 10 +-- .../rest/OfferingRegistrationService.java | 4 +- .../rest/StoreRegistrationService.java | 4 +- .../rest/UserRegistrationService.java | 26 +++---- .../apps/marketplace/security/Assembler.java | 13 ++-- .../security/UserManagementService.java | 8 +-- .../marketplace/security/auth/AuthUtils.java | 10 +-- .../auth/OfferingRegistrationAuth.java | 4 +- .../security/auth/RegistrationAuth.java | 6 +- .../security/auth/StoreRegistrationAuth.java | 4 +- .../security/auth/UserRegistrationAuth.java | 6 +- 24 files changed, 283 insertions(+), 272 deletions(-) delete mode 100644 src/main/java/org/fiware/apps/marketplace/bo/LocaluserBo.java create mode 100644 src/main/java/org/fiware/apps/marketplace/bo/UserBo.java delete mode 100644 src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java create mode 100644 src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java delete mode 100644 src/main/java/org/fiware/apps/marketplace/dao/LocaluserDao.java create mode 100644 src/main/java/org/fiware/apps/marketplace/dao/UserDao.java delete mode 100644 src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java create mode 100644 src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java rename src/main/java/org/fiware/apps/marketplace/model/{Localuser.java => User.java} (73%) diff --git a/license.txt b/license.txt index 758c6c7..4925c96 100644 --- a/license.txt +++ b/license.txt @@ -2,6 +2,7 @@ Modified BSD License ==================== Copyright (c) 2012, SAP AG +Copyright (c) 2014, UPM All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/src/main/java/org/fiware/apps/marketplace/bo/LocaluserBo.java b/src/main/java/org/fiware/apps/marketplace/bo/LocaluserBo.java deleted file mode 100644 index 35bfdab..0000000 --- a/src/main/java/org/fiware/apps/marketplace/bo/LocaluserBo.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.fiware.apps.marketplace.bo; - -import java.util.List; - -import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; - -public interface LocaluserBo { - void save(Localuser localuser); - void update(Localuser localuser); - void delete(Localuser localuser); - Localuser findByName(String username) throws UserNotFoundException; - List findLocalusers(); -} diff --git a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java new file mode 100644 index 0000000..faafd8f --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java @@ -0,0 +1,16 @@ +package org.fiware.apps.marketplace.bo; + +import java.util.List; + +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.User; + +public interface UserBo { + + void save(User localuser); + void update(User localuser); + void delete(User localuser); + User findByName(String username) throws UserNotFoundException; + List findLocalusers(); + +} diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java deleted file mode 100644 index 72dcc91..0000000 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/LocaluserBoImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.fiware.apps.marketplace.bo.impl; - -import java.util.List; - -import org.fiware.apps.marketplace.bo.LocaluserBo; -import org.fiware.apps.marketplace.dao.LocaluserDao; -import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service("localuserBo") -public class LocaluserBoImpl implements LocaluserBo{ - - @Autowired - LocaluserDao localuserDao; - - public void setStoreDao (LocaluserDao localuser){ - this.localuserDao = localuser; - } - - @Override - @Transactional(readOnly=false) - public void save(Localuser localuser) { - localuserDao.save(localuser); - } - - @Override - @Transactional(readOnly=false) - public void update(Localuser localuser) { - localuserDao.update(localuser); - } - - @Override - @Transactional(readOnly=false) - public void delete(Localuser localuser) { - localuserDao.delete(localuser); - } - - @Override - public Localuser findByName(String username) throws UserNotFoundException { - return localuserDao.findByName(username); - } - - @Override - public List findLocalusers() { - return localuserDao.findLocalusers(); - } - -} diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java new file mode 100644 index 0000000..b3aa291 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java @@ -0,0 +1,51 @@ +package org.fiware.apps.marketplace.bo.impl; + +import java.util.List; + +import org.fiware.apps.marketplace.bo.UserBo; +import org.fiware.apps.marketplace.dao.UserDao; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service("userBo") +public class UserBoImpl implements UserBo { + + @Autowired + UserDao userDao; + + public void setStoreDao (UserDao localuser){ + this.userDao = localuser; + } + + @Override + @Transactional(readOnly=false) + public void save(User localuser) { + userDao.save(localuser); + } + + @Override + @Transactional(readOnly=false) + public void update(User localuser) { + userDao.update(localuser); + } + + @Override + @Transactional(readOnly=false) + public void delete(User localuser) { + userDao.delete(localuser); + } + + @Override + public User findByName(String username) throws UserNotFoundException { + return userDao.findByName(username); + } + + @Override + public List findLocalusers() { + return userDao.findLocalusers(); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/dao/LocaluserDao.java b/src/main/java/org/fiware/apps/marketplace/dao/LocaluserDao.java deleted file mode 100644 index bbc92f9..0000000 --- a/src/main/java/org/fiware/apps/marketplace/dao/LocaluserDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.fiware.apps.marketplace.dao; - -import java.util.List; - -import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; - -public interface LocaluserDao { - void save(Localuser localuser); - void update(Localuser localuser); - void delete(Localuser localuser); - Localuser findByName(String username) throws UserNotFoundException; - List findLocalusers(); -} diff --git a/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java b/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java new file mode 100644 index 0000000..66d3ee2 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java @@ -0,0 +1,14 @@ +package org.fiware.apps.marketplace.dao; + +import java.util.List; + +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.User; + +public interface UserDao { + void save(User localuser); + void update(User localuser); + void delete(User localuser); + User findByName(String username) throws UserNotFoundException; + List findLocalusers(); +} diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java deleted file mode 100644 index 079b5f0..0000000 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/LocaluserDaoImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.fiware.apps.marketplace.dao.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.fiware.apps.marketplace.dao.LocaluserDao; -import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; -import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; -import org.springframework.stereotype.Repository; - -@Repository("localuserDao") -public class LocaluserDaoImpl extends MarketplaceHibernateDao implements LocaluserDao { - - @Override - public void save(Localuser user) { - getHibernateTemplate().saveOrUpdate(user); - } - - @Override - public void update(Localuser user) { - getHibernateTemplate().update(user); - - } - - @Override - public void delete(Localuser user) { - getHibernateTemplate().delete(user); - } - - @Override - public Localuser findByName(String username) throws UserNotFoundException{ - List list = getHibernateTemplate().find("from Localuser where username=?", username); - - if (list.size() == 0) { - throw new UserNotFoundException("User " + username + " not found"); - } else { - return (Localuser) list.get(0); - } - } - - @Override - public List findLocalusers() { - List list = getHibernateTemplate().loadAll(Localuser.class); - - if (list.size() == 0){ - list = new ArrayList(); - } - - return list; - } - -} diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java new file mode 100644 index 0000000..a5ce5cf --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java @@ -0,0 +1,53 @@ +package org.fiware.apps.marketplace.dao.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.fiware.apps.marketplace.dao.UserDao; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.User; +import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; +import org.springframework.stereotype.Repository; + +@Repository("userDao") +public class UserDaoImpl extends MarketplaceHibernateDao implements UserDao { + + @Override + public void save(User user) { + getHibernateTemplate().saveOrUpdate(user); + } + + @Override + public void update(User user) { + getHibernateTemplate().update(user); + + } + + @Override + public void delete(User user) { + getHibernateTemplate().delete(user); + } + + @Override + public User findByName(String username) throws UserNotFoundException{ + List list = getHibernateTemplate().find("from User where userName=?", username); + + if (list.size() == 0) { + throw new UserNotFoundException("User " + username + " not found"); + } else { + return (User) list.get(0); + } + } + + @Override + public List findLocalusers() { + List list = getHibernateTemplate().loadAll(User.class); + + if (list.size() == 0){ + list = new ArrayList(); + } + + return list; + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/db/HibernateDDLGenerator.java b/src/main/java/org/fiware/apps/marketplace/db/HibernateDDLGenerator.java index 1360f8c..1ecadf9 100644 --- a/src/main/java/org/fiware/apps/marketplace/db/HibernateDDLGenerator.java +++ b/src/main/java/org/fiware/apps/marketplace/db/HibernateDDLGenerator.java @@ -1,7 +1,7 @@ package org.fiware.apps.marketplace.db; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Rating; import org.fiware.apps.marketplace.model.RatingCategory; import org.fiware.apps.marketplace.model.RatingCategoryEntry; @@ -18,7 +18,7 @@ public class HibernateDDLGenerator { * @param args */ public static void main(String[] args) { - new HibernateDDLGenerator().execute(Dialect.MYSQL5, Store.class, Service.class, Localuser.class, Rating.class, RatingCategory.class, RatingCategoryEntry.class, RatingObject.class, RatingObjectCategory.class); + new HibernateDDLGenerator().execute(Dialect.MYSQL5, Store.class, Service.class, User.class, Rating.class, RatingCategory.class, RatingCategoryEntry.class, RatingObject.class, RatingObjectCategory.class); } private void execute(Dialect dialect, Class... classes) { AnnotationConfiguration configuration = new AnnotationConfiguration(); diff --git a/src/main/java/org/fiware/apps/marketplace/model/Service.java b/src/main/java/org/fiware/apps/marketplace/model/Service.java index e34c1a5..699c5e4 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Service.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Service.java @@ -19,22 +19,22 @@ import javax.xml.bind.annotation.XmlTransient; @Entity -@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "SERVICE_NAME", "STORE_ID" }) }) // each service name has to unique for a store context +@Table(name = "Services", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "store" }) }) // each service name has to unique for a store context @XmlRootElement(name = "resource") public class Service { - private Integer id; + private Integer id; private String url; private String name; - private String Description; + private String description; private Date registrationDate; private Store store; - private Localuser lasteditor; - private Localuser creator; + private User lasteditor; + private User creator; @Id @GeneratedValue(strategy = IDENTITY) - @Column(name = "SERVICE_ID", unique = true, nullable = false) + @Column(name = "id", unique = true, nullable = false) public Integer getId() { return id; } @@ -45,7 +45,7 @@ public void setId(Integer id) { @XmlID @XmlAttribute - @Column(name = "SERVICE_NAME", nullable = false) + @Column(name = "name", nullable = false) public String getName() { return name; } @@ -55,7 +55,7 @@ public void setName(String name) { } @XmlElement - @Column(name = "SERVICE_URL", unique = true, nullable = false) + @Column(name = "url", unique = true, nullable = false) public String getUrl() { return url; } @@ -63,32 +63,20 @@ public String getUrl() { public void setUrl(String url) { this.url = url; } - @XmlElement - @Column(name = "SERVICE_DESC") + @Column(name = "description") public String getDescription() { - return Description; + return description; } public void setDescription(String description) { - Description = description; + this.description = description; } - - @XmlElement - @Column(name = "SERVICE_REG_DATE") - public Date getRegistrationDate() { - return registrationDate; - } - - public void setRegistrationDate(Date registrationDate) { - this.registrationDate = registrationDate; - } - @XmlTransient @ManyToOne(optional = false) - @JoinColumn(name = "STORE_ID", nullable=false) + @JoinColumn(name = "store", nullable=false) public Store getStore() { return store; } @@ -99,24 +87,33 @@ public void setStore(Store store) { @XmlElement @ManyToOne(optional = false) - @JoinColumn(name = "LOCALUSER_LAST_EDITOR_ID", nullable=false) - public Localuser getLasteditor() { - return lasteditor; + @JoinColumn(name = "creator", nullable=false) + public User getCreator() { + return creator; } - public void setLasteditor(Localuser lasteditor) { - this.lasteditor = lasteditor; + public void setCreator(User creator) { + this.creator = creator; } @XmlElement @ManyToOne(optional = false) - @JoinColumn(name = "LOCALUSER_CREATOR_ID", nullable=false) - public Localuser getCreator() { - return creator; + @JoinColumn(name = "last_editor", nullable=false) + public User getLasteditor() { + return lasteditor; } - public void setCreator(Localuser creator) { - this.creator = creator; + public void setLasteditor(User lasteditor) { + this.lasteditor = lasteditor; } + @XmlElement + @Column(name = "registration_date") + public Date getRegistrationDate() { + return registrationDate; + } + + public void setRegistrationDate(Date registrationDate) { + this.registrationDate = registrationDate; + } } diff --git a/src/main/java/org/fiware/apps/marketplace/model/Store.java b/src/main/java/org/fiware/apps/marketplace/model/Store.java index fe62c83..0122e34 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Store.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Store.java @@ -14,31 +14,31 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.Table; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; -import org.codehaus.jackson.annotate.JsonIgnore; - @Entity +@Table(name = "Stores") @XmlRootElement(name = "resource") public class Store { private Integer id; private String url; private String name; - private String Description; + private String description; private Date registrationDate; private List services; - private Localuser lasteditor; - private Localuser creator; + private User lasteditor; + private User creator; @Id @GeneratedValue(strategy = IDENTITY) - @Column(name = "STORE_ID", unique = true, nullable = false) + @Column(name = "id", unique = true, nullable = false) @XmlTransient public Integer getId() { return id; @@ -50,7 +50,7 @@ public void setId(Integer id) { @XmlID @XmlAttribute - @Column(name = "STORE_NAME", unique = true, nullable = false) + @Column(name = "name", unique = true, nullable = false) public String getName() { return name; } @@ -60,7 +60,7 @@ public void setName(String name) { } @XmlElement - @Column(name = "STORE_URL", unique = true, nullable = false) + @Column(name = "url", unique = true, nullable = false) public String getUrl() { return url; } @@ -70,17 +70,39 @@ public void setUrl(String url) { } @XmlElement - @Column(name = "STORE_DESC") + @Column(name = "description") public String getDescription() { - return Description; + return description; } public void setDescription(String description) { - Description = description; + this.description = description; + } + + @XmlElement + @ManyToOne(optional = false) + @JoinColumn(name = "creator", nullable=false) + public User getCreator() { + return creator; + } + + public void setCreator(User creator) { + this.creator = creator; + } + + @XmlElement + @ManyToOne(optional = false) + @JoinColumn(name = "last_editor", nullable=false) + public User getLasteditor() { + return lasteditor; + } + + public void setLasteditor(User lasteditor) { + this.lasteditor = lasteditor; } @XmlElement - @Column(name = "STORE_DATE") + @Column(name = "registration_date") public Date getRegistrationDate() { return registrationDate; } @@ -89,7 +111,6 @@ public void setRegistrationDate(Date registrationDate) { this.registrationDate = registrationDate; } - @XmlTransient @OneToMany(mappedBy="store", cascade=CascadeType.ALL, fetch=FetchType.EAGER) public List getServices() { @@ -99,27 +120,5 @@ public List getServices() { public void setServices(List services) { this.services = services; } - - @XmlElement - @ManyToOne(optional = false) - @JoinColumn(name = "LOCALUSER_LAST_EDITOR_ID", nullable=false) - public Localuser getLasteditor() { - return lasteditor; - } - - public void setLasteditor(Localuser lasteditor) { - this.lasteditor = lasteditor; - } - - @XmlElement - @ManyToOne(optional = false) - @JoinColumn(name = "LOCALUSER_CREATOR_ID", nullable=false) - public Localuser getCreator() { - return creator; - } - - public void setCreator(Localuser creator) { - this.creator = creator; - } } diff --git a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java b/src/main/java/org/fiware/apps/marketplace/model/User.java similarity index 73% rename from src/main/java/org/fiware/apps/marketplace/model/Localuser.java rename to src/main/java/org/fiware/apps/marketplace/model/User.java index d8c1038..5d7c8c1 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Localuser.java +++ b/src/main/java/org/fiware/apps/marketplace/model/User.java @@ -8,6 +8,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Table; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlID; @@ -19,11 +20,13 @@ import org.fiware.apps.marketplace.utils.xmladapters.PasswordXMLAdapter; @Entity +@Table(name = "Users") @XmlRootElement(name = "user") -public class Localuser { +public class User { private Integer id; - private String username; + private String userName; + private String displayName; private String password; private String email; private Date registrationDate; @@ -31,7 +34,7 @@ public class Localuser { @Id @GeneratedValue(strategy = IDENTITY) - @Column(name = "LOCALUSER_ID", unique = true, nullable = false) + @Column(name = "id", unique = true, nullable = false) @XmlTransient public Integer getId() { return id; @@ -43,33 +46,29 @@ public void setId(Integer id) { @XmlID @XmlAttribute - @Column(name = "LOCALUSER_USERNAME", unique = true, nullable = false) - public String getUsername() { - return username; + @Column(name = "user_name", unique = true, nullable = false) + public String getUserName() { + return userName; } - public void setUsername(String username) { - this.username = username; + public void setUserName(String userName) { + this.userName = userName; } @XmlElement - // Avoid returning the password in the API - // Encrypt the password received through the API - @XmlJavaTypeAdapter(PasswordXMLAdapter.class) - @Column(name = "LOCALUSER_PASSWORD", nullable = false) - public String getPassword() { - return password; + @Column(name = "display_name") + public String getDisplayName() { + return this.displayName; } - public void setPassword(String password) { - // The password is encoded using the user name as salt - this.password = password; + public void setDisplayName(String displayName) { + this.displayName = displayName; } @XmlElement // Avoid returning the mail in the API @XmlJavaTypeAdapter(HiddenFieldsXMLAdapter.class) - @Column(name = "LOCALUSER_EMAIL", unique = true, nullable = false) + @Column(name = "email", unique = true, nullable = false) public String getEmail() { return email; } @@ -79,7 +78,21 @@ public void setEmail(String email) { } @XmlElement - @Column(name = "LOCALUSER_REGISTRATION_DATE", nullable = false) + // Avoid returning the password in the API + // Encrypt the password received through the API + @XmlJavaTypeAdapter(PasswordXMLAdapter.class) + @Column(name = "password", nullable = false) + public String getPassword() { + return password; + } + + public void setPassword(String password) { + // The password is encoded using the user name as salt + this.password = password; + } + + @XmlElement + @Column(name = "registration_date", nullable = false) public Date getRegistrationDate() { return registrationDate; } @@ -89,7 +102,7 @@ public void setRegistrationDate(Date registrationDate) { } @XmlElement - @Column(name = "LOCALUSER_COMPANY") + @Column(name = "company") public String getCompany() { return company; } @@ -105,7 +118,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - Localuser other = (Localuser) obj; + User other = (User) obj; return other.id == this.id; } diff --git a/src/main/java/org/fiware/apps/marketplace/model/Users.java b/src/main/java/org/fiware/apps/marketplace/model/Users.java index 3364d4b..cef4a51 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Users.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Users.java @@ -9,22 +9,22 @@ @XmlRootElement(name = "users") public class Users { - private List users = null; + private List users = null; public Users() { - this.setUsers(new ArrayList()); + this.setUsers(new ArrayList()); } - public Users(List users) { + public Users(List users) { this.setUsers(users); } @XmlElement(name = "user") - public List getUsers() { + public List getUsers() { return this.users; } - public void setUsers(List users) { + public void setUsers(List users) { this.users = users; } } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index 108c78c..744af4d 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -18,7 +18,7 @@ import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Services; import org.fiware.apps.marketplace.model.Store; @@ -51,7 +51,7 @@ public Response saveService(@PathParam("storeName") String storeName, Service se if (offeringRegistrationAuth.canCreate()) { try { - Localuser user = AUTH_UTILS.getLoggedUser(); + User user = AUTH_UTILS.getLoggedUser(); Store store = storeBo.findByName(storeName); service.setRegistrationDate(new Date()); service.setStore(store); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index e731ca7..8e2c0f6 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -17,7 +17,7 @@ import org.fiware.apps.marketplace.bo.StoreBo; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.model.Stores; import org.fiware.apps.marketplace.security.auth.AuthUtils; @@ -50,7 +50,7 @@ public Response createStore(Store store) { if (storeRegistrationAuth.canCreate()) { try { // Get the current user - Localuser currentUser = AUTH_UTILS.getLoggedUser(); + User currentUser = AUTH_UTILS.getLoggedUser(); store.setRegistrationDate(new Date()); store.setCreator(currentUser); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 66cafbe..1eb058e 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -14,9 +14,9 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.fiware.apps.marketplace.bo.LocaluserBo; +import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Users; import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; @@ -29,7 +29,7 @@ public class UserRegistrationService { // OBJECT ATTRIBUTES // private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); - private LocaluserBo localuserBo = (LocaluserBo) context.getBean("localuserBo"); + private UserBo userBo = (UserBo) context.getBean("userBo"); private UserRegistrationAuth userRegistrationAuth = (UserRegistrationAuth) context.getBean("userRegistrationAuth"); // CLASS ATTRIBUTES // @@ -40,13 +40,13 @@ public class UserRegistrationService { @POST @Consumes({"application/xml", "application/json"}) @Path("/") - public Response createUser(Localuser localUser) { + public Response createUser(User localUser) { Response response; try { if (userRegistrationAuth.canCreate()) { localUser.setRegistrationDate(new Date()); - localuserBo.save(localUser); + userBo.save(localUser); response = Response.status(Status.CREATED).build(); } else { response = ERROR_UTILS.unauthorizedResponse("create user"); @@ -64,18 +64,18 @@ public Response createUser(Localuser localUser) { @PUT @Consumes({"application/xml", "application/json"}) @Path("/{username}") - public Response updateUser(@PathParam("username") String username, Localuser localUser) { + public Response updateUser(@PathParam("username") String username, User localUser) { Response response; try { - Localuser userToBeUpdated = localuserBo.findByName(username); + User userToBeUpdated = userBo.findByName(username); if (userRegistrationAuth.canUpdate(userToBeUpdated)) { userToBeUpdated.setCompany(localUser.getCompany()); userToBeUpdated.setPassword(localUser.getPassword()); userToBeUpdated.setEmail(localUser.getEmail()); - userToBeUpdated.setUsername(localUser.getUsername()); - localuserBo.update(userToBeUpdated); + userToBeUpdated.setUserName(localUser.getUserName()); + userBo.update(userToBeUpdated); response = Response.status(Status.OK).build(); } else { response = ERROR_UTILS.unauthorizedResponse("update user " + username); @@ -97,10 +97,10 @@ public Response deleteUser(@PathParam("username") String username) { Response response; try { - Localuser userToBeDeleted = localuserBo.findByName(username); + User userToBeDeleted = userBo.findByName(username); // Only a user can delete his/her account if (userRegistrationAuth.canDelete(userToBeDeleted)) { - localuserBo.delete(userToBeDeleted); + userBo.delete(userToBeDeleted); response = Response.status(Status.OK).build(); } else { response = ERROR_UTILS.unauthorizedResponse("delete user " + username); @@ -121,7 +121,7 @@ public Response findUser(@PathParam("username") String username) { Response response; try { - Localuser localuser = localuserBo.findByName(username); + User localuser = userBo.findByName(username); if (userRegistrationAuth.canGet(localuser)) { response = Response.status(Status.OK).entity(localuser).build(); @@ -145,7 +145,7 @@ public Response listUsers() { Response response; try { if (userRegistrationAuth.canList()) { - List users = localuserBo.findLocalusers(); + List users = userBo.findLocalusers(); return Response.status(Status.OK).entity(new Users(users)).build(); } else { response = ERROR_UTILS.unauthorizedResponse("list users"); diff --git a/src/main/java/org/fiware/apps/marketplace/security/Assembler.java b/src/main/java/org/fiware/apps/marketplace/security/Assembler.java index dd3bbed..dab9b18 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/Assembler.java +++ b/src/main/java/org/fiware/apps/marketplace/security/Assembler.java @@ -3,9 +3,8 @@ import java.util.ArrayList; import java.util.Collection; -import org.fiware.apps.marketplace.model.Localuser; import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.GrantedAuthorityImpl; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -14,9 +13,9 @@ public class Assembler { @Transactional(readOnly = true) - User buildUserFromUserEntity(Localuser user) { + User buildUserFromUserEntity(org.fiware.apps.marketplace.model.User user) { - String username = user.getUsername(); + String username = user.getUserName(); String password = user.getPassword(); boolean enabled = true; @@ -26,13 +25,13 @@ User buildUserFromUserEntity(Localuser user) { Collection authorities = new ArrayList(); - /*for (SecurityRoleEntity role : user.getRoles()) { + /* + for (SecurityRoleEntity role : user.getRoles()) { authorities.add(new GrantedAuthorityImpl(role.getRoleName())); } */ - GrantedAuthority role = new GrantedAuthorityImpl("ROLE_USER"); - authorities.add(role); + authorities.add(new SimpleGrantedAuthority("ROLE_USER")); User springUser = new User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); return springUser; } diff --git a/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java b/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java index cda2be1..3631da4 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java +++ b/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java @@ -1,8 +1,8 @@ package org.fiware.apps.marketplace.security; -import org.fiware.apps.marketplace.bo.LocaluserBo; +import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -16,7 +16,7 @@ public class UserManagementService implements UserDetailsService{ ApplicationContext appContext = ApplicationContextProvider.getApplicationContext(); - LocaluserBo localuserBo = (LocaluserBo) appContext.getBean("localuserBo"); + UserBo userBo = (UserBo) appContext.getBean("userBo"); @Autowired private Assembler assembler; @@ -26,7 +26,7 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { try { - Localuser userEntity = localuserBo.findByName(username); + User userEntity = userBo.findByName(username); return assembler.buildUserFromUserEntity(userEntity); } catch (UserNotFoundException ex) { throw new UsernameNotFoundException("user not found"); diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java index 59cbf8f..3ea083c 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java @@ -1,8 +1,8 @@ package org.fiware.apps.marketplace.security.auth; -import org.fiware.apps.marketplace.bo.LocaluserBo; +import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.security.core.context.SecurityContextHolder; @@ -10,7 +10,7 @@ public class AuthUtils { // Avoid users to instantiate this class private AuthUtils() { - this.localuserBo = (LocaluserBo) ApplicationContextProvider.getApplicationContext().getBean("localuserBo"); + this.localuserBo = (UserBo) ApplicationContextProvider.getApplicationContext().getBean("userBo"); } public static AuthUtils getAuthUtils() { @@ -21,9 +21,9 @@ public static AuthUtils getAuthUtils() { private static AuthUtils singleton = new AuthUtils(); //Instance attributes - private LocaluserBo localuserBo; + private UserBo localuserBo; - public Localuser getLoggedUser() throws UserNotFoundException { + public User getLoggedUser() throws UserNotFoundException { return localuserBo.findByName(SecurityContextHolder.getContext().getAuthentication().getName()); } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java index a2981b0..b9c5911 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java @@ -1,6 +1,6 @@ package org.fiware.apps.marketplace.security.auth; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Service; @@ -8,7 +8,7 @@ public class OfferingRegistrationAuth extends RegistrationAuth { @Override - protected Localuser getEntityOwner(Service service) { + protected User getEntityOwner(Service service) { return service.getCreator(); } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java index 36c0238..dac4cf1 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java @@ -1,7 +1,7 @@ package org.fiware.apps.marketplace.security.auth; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; public abstract class RegistrationAuth { @@ -10,7 +10,7 @@ public abstract class RegistrationAuth { * @param entity The entity whose owner the developer wants to know * @return The owner of the entity */ - protected abstract Localuser getEntityOwner(T entity); + protected abstract User getEntityOwner(T entity); /** * Method to know if the logged user is the owner of the entity @@ -21,7 +21,7 @@ protected boolean isLoggedUserTheOwner(T entity) { boolean canAccess = false; try { - Localuser loggedUser = AuthUtils.getAuthUtils().getLoggedUser(); + User loggedUser = AuthUtils.getAuthUtils().getLoggedUser(); // logged User can be null if the user is not logged in... if (loggedUser != null && loggedUser.equals(this.getEntityOwner(entity))) { canAccess = true; diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java index 4e25a34..eff6a17 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java @@ -1,6 +1,6 @@ package org.fiware.apps.marketplace.security.auth; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Store; import org.springframework.stereotype.Service; @@ -8,7 +8,7 @@ public class StoreRegistrationAuth extends RegistrationAuth { @Override - protected Localuser getEntityOwner(Store store) { + protected User getEntityOwner(Store store) { return store.getCreator(); } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java index a74f165..a192ff4 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java @@ -1,13 +1,13 @@ package org.fiware.apps.marketplace.security.auth; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.springframework.stereotype.Service; @Service("userRegistrationAuth") -public class UserRegistrationAuth extends RegistrationAuth { +public class UserRegistrationAuth extends RegistrationAuth { @Override - protected Localuser getEntityOwner(Localuser user) { + protected User getEntityOwner(User user) { return user; } From 1d6727e25a527a0928251f2957f0abd1558ef02e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 1 Dec 2014 17:05:19 +0100 Subject: [PATCH 17/69] Remove unneeded code --- .../org/fiware/apps/marketplace/dao/UserDao.java | 2 +- .../apps/marketplace/dao/impl/StoreDaoImpl.java | 9 +-------- .../apps/marketplace/dao/impl/UserDaoImpl.java | 14 ++++++-------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java b/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java index 66d3ee2..fdcc32e 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java @@ -10,5 +10,5 @@ public interface UserDao { void update(User localuser); void delete(User localuser); User findByName(String username) throws UserNotFoundException; - List findLocalusers(); + List getAllUsers(); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java index 9660923..209b6d5 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java @@ -1,6 +1,5 @@ package org.fiware.apps.marketplace.dao.impl; -import java.util.ArrayList; import java.util.List; import org.fiware.apps.marketplace.dao.StoreDao; @@ -41,13 +40,7 @@ public Store findByName(String name) throws StoreNotFoundException { @Override public List findStores() { - List list = getHibernateTemplate().loadAll(Store.class); - - if (list.size()==0){ - list = new ArrayList(); - } - - return list; + return getHibernateTemplate().loadAll(Store.class); } } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java index a5ce5cf..91f4459 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java @@ -3,10 +3,14 @@ import java.util.ArrayList; import java.util.List; +import javax.mail.Session; + import org.fiware.apps.marketplace.dao.UserDao; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; +import org.hibernate.Criteria; +import org.hibernate.criterion.DetachedCriteria; import org.springframework.stereotype.Repository; @Repository("userDao") @@ -40,14 +44,8 @@ public User findByName(String username) throws UserNotFoundException{ } @Override - public List findLocalusers() { - List list = getHibernateTemplate().loadAll(User.class); - - if (list.size() == 0){ - list = new ArrayList(); - } - - return list; + public List getAllUsers() { + return getHibernateTemplate().loadAll(User.class); } } From fc81d0946bc3ec290258ed0f00b9b581c3a8e242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 1 Dec 2014 17:50:25 +0100 Subject: [PATCH 18/69] Add Users Pagination --- .../java/org/fiware/apps/marketplace/bo/UserBo.java | 3 ++- .../fiware/apps/marketplace/bo/impl/UserBoImpl.java | 9 +++++++-- .../java/org/fiware/apps/marketplace/dao/UserDao.java | 1 + .../fiware/apps/marketplace/dao/impl/UserDaoImpl.java | 11 +++++++---- .../marketplace/rest/UserRegistrationService.java | 7 +++++-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java index faafd8f..1df0b8b 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java @@ -11,6 +11,7 @@ public interface UserBo { void update(User localuser); void delete(User localuser); User findByName(String username) throws UserNotFoundException; - List findLocalusers(); + List getUsersPage(int offset, int max); + List listUsers(); } diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java index b3aa291..35ea50f 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java @@ -42,10 +42,15 @@ public void delete(User localuser) { public User findByName(String username) throws UserNotFoundException { return userDao.findByName(username); } + + @Override + public List getUsersPage(int offset, int max) { + return userDao.getUsersPage(offset, max); + } @Override - public List findLocalusers() { - return userDao.findLocalusers(); + public List listUsers() { + return userDao.getAllUsers(); } } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java b/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java index fdcc32e..333de97 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java @@ -10,5 +10,6 @@ public interface UserDao { void update(User localuser); void delete(User localuser); User findByName(String username) throws UserNotFoundException; + List getUsersPage(int offset, int max); List getAllUsers(); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java index 91f4459..884fba5 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java @@ -1,15 +1,11 @@ package org.fiware.apps.marketplace.dao.impl; -import java.util.ArrayList; import java.util.List; -import javax.mail.Session; - import org.fiware.apps.marketplace.dao.UserDao; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; -import org.hibernate.Criteria; import org.hibernate.criterion.DetachedCriteria; import org.springframework.stereotype.Repository; @@ -42,6 +38,13 @@ public User findByName(String username) throws UserNotFoundException{ return (User) list.get(0); } } + + @SuppressWarnings("unchecked") + @Override + public List getUsersPage(int offset, int max) { + return (List) getHibernateTemplate().findByCriteria( + DetachedCriteria.forClass(User.class), offset, max); + } @Override public List getAllUsers() { diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 1eb058e..b2befd7 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -5,12 +5,14 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -140,12 +142,13 @@ public Response findUser(@PathParam("username") String username) { @GET @Produces({"application/xml", "application/json"}) @Path("/") - public Response listUsers() { + public Response listUsers(@DefaultValue("0") @QueryParam("offset") int offset, + @DefaultValue("100") @QueryParam("max") int max) { Response response; try { if (userRegistrationAuth.canList()) { - List users = userBo.findLocalusers(); + List users = userBo.getUsersPage(offset, max); return Response.status(Status.OK).entity(new Users(users)).build(); } else { response = ERROR_UTILS.unauthorizedResponse("list users"); From 42e8d38ef4102cbc569aa125a459206ad99d6f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 2 Dec 2014 12:27:31 +0100 Subject: [PATCH 19/69] Return and Error when Offset and/or max parameters are not correct --- .../apps/marketplace/rest/ErrorUtils.java | 5 ++++ .../rest/UserRegistrationService.java | 25 +++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java index 9a10043..55b9e66 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java @@ -29,6 +29,11 @@ public Response badRequestResponse(DataAccessException ex) { new APIError(ErrorType.BAD_REQUEST, message)).build(); } + public Response badRequestResponse(String message) { + return Response.status(Status.BAD_REQUEST).entity( + new APIError(ErrorType.BAD_REQUEST, message)).build(); + } + public Response entityNotFoundResponse(Exception ex) { return Response.status(Status.NOT_FOUND).entity( new APIError(ErrorType.NOT_FOUND, ex.getMessage())).build(); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index b2befd7..2d34e28 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -144,17 +144,22 @@ public Response findUser(@PathParam("username") String username) { @Path("/") public Response listUsers(@DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("100") @QueryParam("max") int max) { - Response response; - try { - if (userRegistrationAuth.canList()) { - List users = userBo.getUsersPage(offset, max); - return Response.status(Status.OK).entity(new Users(users)).build(); - } else { - response = ERROR_UTILS.unauthorizedResponse("list users"); - } - } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + + if (offset < 0 || max <= 0) { + // Offset and Max should be checked + response = ERROR_UTILS.badRequestResponse("offset and/or max are not valid"); + } else { + try { + if (userRegistrationAuth.canList()) { + List users = userBo.getUsersPage(offset, max); + return Response.status(Status.OK).entity(new Users(users)).build(); + } else { + response = ERROR_UTILS.unauthorizedResponse("list users"); + } + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } } return response; From 98f898fa9363e9aca7321f54e723a3b0b272dd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 2 Dec 2014 13:13:02 +0100 Subject: [PATCH 20/69] Pagination for Stores --- .../fiware/apps/marketplace/bo/StoreBo.java | 3 +- .../fiware/apps/marketplace/bo/UserBo.java | 2 +- .../bo/impl/MaintenanceBoImpl.java | 4 +- .../apps/marketplace/bo/impl/StoreBoImpl.java | 9 ++- .../apps/marketplace/bo/impl/UserBoImpl.java | 4 +- .../fiware/apps/marketplace/dao/StoreDao.java | 3 +- .../marketplace/dao/impl/StoreDaoImpl.java | 10 ++- .../rest/StoreRegistrationService.java | 62 +++++++++++-------- 8 files changed, 60 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java b/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java index 4a062e4..8200fc8 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java @@ -11,6 +11,7 @@ public interface StoreBo { void update(Store store); void delete(Store store); Store findByName(String name) throws StoreNotFoundException; - List findStores(); + List getStoresPage(int offset, int max); + List getAllStores(); } diff --git a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java index 1df0b8b..3d66eb0 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java @@ -12,6 +12,6 @@ public interface UserBo { void delete(User localuser); User findByName(String username) throws UserNotFoundException; List getUsersPage(int offset, int max); - List listUsers(); + List getAllUsers(); } diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java index 46215da..383a3c2 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java @@ -71,7 +71,7 @@ private boolean initializeAttributeTypes() { attributeTypeBo.save(attributeType); } } - for (Store store : storeBo.findStores()) { + for (Store store : storeBo.getAllStores()) { for (Service service : store.getServices()) { for (ServiceAttributeType attributeType : AttributeTypeResolver.resolveAttributeTypesFromUri(service.getUrl())) { attributeTypeBo.save(attributeType); @@ -90,7 +90,7 @@ private boolean initializeAttributeTypes() { private boolean initializeOfferings() { try { long start = System.currentTimeMillis(); - for (Offering offering : OfferingResolver.resolveOfferingsFromStores(storeBo.findStores())) { + for (Offering offering : OfferingResolver.resolveOfferingsFromStores(storeBo.getAllStores())) { offeringBo.save(offering); } long end = System.currentTimeMillis(); diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java index 08dcfae..212275d 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java @@ -47,7 +47,12 @@ public Store findByName(String name) throws StoreNotFoundException { } @Override - public List findStores() { - return storeDao.findStores(); + public List getStoresPage(int offset, int max) { + return storeDao.getStoresPage(offset, max); + } + + @Override + public List getAllStores() { + return storeDao.getAllStores(); } } diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java index 35ea50f..3290693 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java @@ -14,7 +14,7 @@ public class UserBoImpl implements UserBo { @Autowired - UserDao userDao; + private UserDao userDao; public void setStoreDao (UserDao localuser){ this.userDao = localuser; @@ -49,7 +49,7 @@ public List getUsersPage(int offset, int max) { } @Override - public List listUsers() { + public List getAllUsers() { return userDao.getAllUsers(); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java b/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java index cbda5bc..58ef4f7 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java @@ -10,6 +10,7 @@ public interface StoreDao { void update(Store store); void delete(Store store); Store findByName(String url) throws StoreNotFoundException; - List findStores(); + List getStoresPage(int offset, int max); + List getAllStores(); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java index 209b6d5..975e11e 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java @@ -6,6 +6,7 @@ import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; +import org.hibernate.criterion.DetachedCriteria; import org.springframework.stereotype.Repository; @Repository("storeDao") @@ -38,8 +39,15 @@ public Store findByName(String name) throws StoreNotFoundException { } + @SuppressWarnings("unchecked") @Override - public List findStores() { + public List getStoresPage(int offset, int max) { + return (List) getHibernateTemplate().findByCriteria( + DetachedCriteria.forClass(Store.class), offset, max); + } + + @Override + public List getAllStores() { return getHibernateTemplate().loadAll(Store.class); } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 8e2c0f6..422e232 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -5,12 +5,14 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -34,7 +36,7 @@ public class StoreRegistrationService { private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); private StoreBo storeBo = (StoreBo) context.getBean("storeBo"); private StoreRegistrationAuth storeRegistrationAuth = (StoreRegistrationAuth) context.getBean("storeRegistrationAuth"); - + // CLASS ATTRIBUTES // private static final AuthUtils AUTH_UTILS = AuthUtils.getAuthUtils(); private static final ErrorUtils ERROR_UTILS = new ErrorUtils( @@ -46,16 +48,16 @@ public class StoreRegistrationService { @Path("/") public Response createStore(Store store) { Response response; - + if (storeRegistrationAuth.canCreate()) { try { // Get the current user User currentUser = AUTH_UTILS.getLoggedUser(); - + store.setRegistrationDate(new Date()); store.setCreator(currentUser); store.setLasteditor(currentUser); - + // Save the new Store and return CREATED storeBo.save(store); response = Response.status(Status.CREATED).build(); @@ -67,9 +69,9 @@ public Response createStore(Store store) { response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } } else { - response = ERROR_UTILS.unauthorizedResponse("create store"); + response = ERROR_UTILS.unauthorizedResponse("create store"); } - + return response; } @@ -79,19 +81,19 @@ public Response createStore(Store store) { @Path("/{storeName}") public Response updateStore(@PathParam("storeName") String storeName, Store store) throws UserNotFoundException { Response response; - + try { Store storeDB = storeBo.findByName(storeName); if (storeRegistrationAuth.canUpdate(storeDB)) { storeDB.setName(store.getName()); storeDB.setUrl(store.getUrl()); store.setLasteditor(AUTH_UTILS.getLoggedUser()); - + // Save the new Store and Return OK storeBo.update(storeDB); response = Response.status(Status.OK).build(); } else { - response = ERROR_UTILS.unauthorizedResponse("update store " + storeName); + response = ERROR_UTILS.unauthorizedResponse("update store " + storeName); } } catch (UserNotFoundException ex) { response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); @@ -102,7 +104,7 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor } catch (Exception ex) { response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - + return response; } @@ -110,16 +112,16 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor @Path("/{storeName}") public Response deleteStore(@PathParam("storeName") String storeName) { Response response; - + try { //Retrieve the Store from the database Store store = storeBo.findByName(storeName); - + if (storeRegistrationAuth.canDelete(store)) { storeBo.delete(store); response = Response.status(Status.OK).build(); // Return OK } else { - response = ERROR_UTILS.unauthorizedResponse("delete store " + storeName); + response = ERROR_UTILS.unauthorizedResponse("delete store " + storeName); } } catch (StoreNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); @@ -135,11 +137,11 @@ public Response deleteStore(@PathParam("storeName") String storeName) { @Path("/{storeName}") public Response getStore(@PathParam("storeName") String storeName) { Response response; - + try { // Retrieve the Store from the database Store store = storeBo.findByName(storeName); - + if (storeRegistrationAuth.canGet(store)) { response = Response.status(Status.OK).entity(store).build(); //Return the Store } else { @@ -150,27 +152,33 @@ public Response getStore(@PathParam("storeName") String storeName) { } catch (Exception ex) { response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - + return response; } @GET @Produces({"application/xml", "application/json"}) @Path("/") - public Response listStores() { + public Response listStores(@DefaultValue("0") @QueryParam("offset") int offset, + @DefaultValue("100") @QueryParam("max") int max) { Response response; - - try { - if (storeRegistrationAuth.canList()) { - List stores = storeBo.findStores(); - response = Response.status(Status.OK).entity(new Stores(stores)).build(); - } else { - response = ERROR_UTILS.unauthorizedResponse("list stores"); + + if (offset < 0 || max <= 0) { + // Offset and Max should be checked + response = ERROR_UTILS.badRequestResponse("offset and/or max are not valid"); + } else { + try { + if (storeRegistrationAuth.canList()) { + List stores = storeBo.getStoresPage(offset, max); + response = Response.status(Status.OK).entity(new Stores(stores)).build(); + } else { + response = ERROR_UTILS.unauthorizedResponse("list stores"); + } + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - + return response; } } From c448a7ba1799b4bcd5b2160e567c8b2be09a7fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 2 Dec 2014 13:27:19 +0100 Subject: [PATCH 21/69] Add JSON Property to improve the JSON API --- src/main/java/org/fiware/apps/marketplace/model/Services.java | 3 +++ src/main/java/org/fiware/apps/marketplace/model/Stores.java | 3 +++ src/main/java/org/fiware/apps/marketplace/model/Users.java | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/main/java/org/fiware/apps/marketplace/model/Services.java b/src/main/java/org/fiware/apps/marketplace/model/Services.java index fc64f27..ce522a5 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Services.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Services.java @@ -6,6 +6,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.codehaus.jackson.annotate.JsonProperty; + @XmlRootElement(name = "services") public class Services { @@ -20,6 +22,7 @@ public Services(List services) { } @XmlElement(name = "service") + @JsonProperty("services") public List getServices() { return this.services; } diff --git a/src/main/java/org/fiware/apps/marketplace/model/Stores.java b/src/main/java/org/fiware/apps/marketplace/model/Stores.java index 5576ab0..dd79073 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Stores.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Stores.java @@ -6,6 +6,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.codehaus.jackson.annotate.JsonProperty; + @XmlRootElement(name = "stores") public class Stores { @@ -20,6 +22,7 @@ public Stores(List stores) { } @XmlElement(name = "store") + @JsonProperty("stores") public List getStores() { return this.stores; } diff --git a/src/main/java/org/fiware/apps/marketplace/model/Users.java b/src/main/java/org/fiware/apps/marketplace/model/Users.java index cef4a51..bda75bb 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Users.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Users.java @@ -6,6 +6,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.codehaus.jackson.annotate.JsonProperty; + @XmlRootElement(name = "users") public class Users { @@ -20,6 +22,7 @@ public Users(List users) { } @XmlElement(name = "user") + @JsonProperty("users") public List getUsers() { return this.users; } From 58d890cfff126eea241ff206c1d82cea767af7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 2 Dec 2014 14:29:57 +0100 Subject: [PATCH 22/69] Allow users to create the same offering in different Stores --- src/main/java/org/fiware/apps/marketplace/model/Service.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/model/Service.java b/src/main/java/org/fiware/apps/marketplace/model/Service.java index 699c5e4..7233d78 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Service.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Service.java @@ -19,7 +19,7 @@ import javax.xml.bind.annotation.XmlTransient; @Entity -@Table(name = "Services", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "store" }) }) // each service name has to unique for a store context +@Table(name = "Services", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "store", "url" }) }) // each service name has to unique for a store context @XmlRootElement(name = "resource") public class Service { @@ -55,7 +55,7 @@ public void setName(String name) { } @XmlElement - @Column(name = "url", unique = true, nullable = false) + @Column(name = "url", nullable = false) public String getUrl() { return url; } From 4be088ee23df6dfac4980c9bcd2a9a533bec6ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 3 Dec 2014 09:52:11 +0100 Subject: [PATCH 23/69] Offerings pagination --- .../fiware/apps/marketplace/model/Store.java | 4 +- .../rest/OfferingRegistrationService.java | 52 ++++++++++++++----- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/model/Store.java b/src/main/java/org/fiware/apps/marketplace/model/Store.java index 0122e34..cc3bfda 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Store.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Store.java @@ -24,10 +24,10 @@ @Entity @Table(name = "Stores") -@XmlRootElement(name = "resource") +@XmlRootElement(name = "store") public class Store { - private Integer id; + private Integer id; private String url; private String name; private String description; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index 744af4d..578a607 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -1,15 +1,18 @@ package org.fiware.apps.marketplace.rest; import java.util.Date; +import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -18,9 +21,9 @@ import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.Services; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Service; -import org.fiware.apps.marketplace.model.Services; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.security.auth.AuthUtils; import org.fiware.apps.marketplace.security.auth.OfferingRegistrationAuth; @@ -176,22 +179,43 @@ public Response getService(@PathParam("storeName") String storeName, @GET @Produces({"application/xml", "application/json"}) @Path("/") - public Response listServices(@PathParam("storeName") String storeName) { + public Response listServices(@PathParam("storeName") String storeName, + @DefaultValue("0") @QueryParam("offset") int offset, + @DefaultValue("100") @QueryParam("max") int max) { Response response; - - if (offeringRegistrationAuth.canList()) { - try { - Store store = storeBo.findByName(storeName); - response = Response.status(Status.OK).entity(new Services(store.getServices())).build(); - } catch (StoreNotFoundException ex) { - response = ERROR_UTILS.entityNotFoundResponse(ex); - } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); - } + + if (offset < 0 || max <= 0) { + // Offset and Max should be checked + response = ERROR_UTILS.badRequestResponse("offset and/or max are not valid"); } else { - response = ERROR_UTILS.unauthorizedResponse("list offerings"); + if (offeringRegistrationAuth.canList()) { + try { + int toIndex; + Store store = storeBo.findByName(storeName); + Services returnedServices = new Services(); + List allServices = store.getServices(); + + // Otherwise (if offset > allServices.size() - 1) an empty list will be returned + if (offset <= allServices.size() - 1) { + if (offset + max > allServices.size()) { + toIndex = allServices.size(); + } else { + toIndex = offset + max; + } + returnedServices.setServices(store.getServices().subList(offset, toIndex)); + } + + response = Response.status(Status.OK).entity(returnedServices).build(); + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } + } else { + response = ERROR_UTILS.unauthorizedResponse("list offerings"); + } } - + return response; } From 2abb24441d960ba96e9bf952b3410041f8280ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 3 Dec 2014 12:31:02 +0100 Subject: [PATCH 24/69] Validate users --- .../exceptions/ValidationException.java | 11 +++ .../model/validators/GenericValidator.java | 75 +++++++++++++++++++ .../model/validators/UserValidator.java | 48 ++++++++++++ .../rest/UserRegistrationService.java | 70 +++++++++++------ 4 files changed, 182 insertions(+), 22 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/exceptions/ValidationException.java create mode 100644 src/main/java/org/fiware/apps/marketplace/model/validators/GenericValidator.java create mode 100644 src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java diff --git a/src/main/java/org/fiware/apps/marketplace/exceptions/ValidationException.java b/src/main/java/org/fiware/apps/marketplace/exceptions/ValidationException.java new file mode 100644 index 0000000..0b59f93 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/exceptions/ValidationException.java @@ -0,0 +1,11 @@ +package org.fiware.apps.marketplace.exceptions; + +public class ValidationException extends Exception { + + private static final long serialVersionUID = 1L; + + public ValidationException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/GenericValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/GenericValidator.java new file mode 100644 index 0000000..1059930 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/GenericValidator.java @@ -0,0 +1,75 @@ +package org.fiware.apps.marketplace.model.validators; + +import java.util.regex.Pattern; + +import org.apache.commons.validator.routines.UrlValidator; + +public class GenericValidator { + + private Pattern emailPattern; + private UrlValidator urlValidator; + + private static final int NAME_MIN_LENGTH = 5; + private static final int NAME_MAX_LENGTH = 15; + private static final int DESCRIPTION_MIN_LENGTH = 0; + private static final int DESCRIPTION_MAX_LENGTH = 200; + private static final String EMAIL_PATTERN = + "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; + + private static GenericValidator INSTANCE = new GenericValidator(); + + private GenericValidator() { + this.emailPattern = Pattern.compile(EMAIL_PATTERN); + this.urlValidator = new UrlValidator(); + } + + public static GenericValidator getInstance() { + return INSTANCE; + } + + public static int getNameMaxLength() { + return NAME_MAX_LENGTH; + } + + public static int getDescriptionMaxLength() { + return DESCRIPTION_MAX_LENGTH; + } + + public static int getNameMinLength() { + return NAME_MIN_LENGTH; + } + + public static int getDescriptionMinLength() { + return DESCRIPTION_MIN_LENGTH; + } + + public String getLengthErrorMessage(String field, int minLength, int maxLength) { + return field + " is not valid. (min length: " + + minLength + ", max length: " + maxLength + ")"; + } + + public boolean validateLength(String value, int minLength, int maxLength) { + boolean minAccomplished = minLength <= 0 ? true : value.length() >= minLength; + boolean maxAccomplished = value.length() <= maxLength; + + return minAccomplished && maxAccomplished; + } + + public boolean validateName(String name) { + return validateLength(name, NAME_MIN_LENGTH, NAME_MAX_LENGTH); + } + + public boolean validateDescription(String description) { + return validateLength(description, DESCRIPTION_MIN_LENGTH, DESCRIPTION_MAX_LENGTH); + } + + public boolean validateEMail(String email) { + return emailPattern.matcher(email).matches(); + } + + public boolean validateURL(String url) { + return urlValidator.isValid(url); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java new file mode 100644 index 0000000..fef4553 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java @@ -0,0 +1,48 @@ +package org.fiware.apps.marketplace.model.validators; + +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.fiware.apps.marketplace.model.User; +import org.springframework.stereotype.Service; + +@Service("usersValidator") +public class UserValidator { + + private static final int COMPANY_MIN_LENGTH = 3; //For example: UPM, TID, SAP, ENG,... + private static final int COMPANY_MAX_LENGTH = 30; + //Just for the future... + //private static final int PASSWORD_MIN_LENGTH = 5; + //private static final int PASSWORD_MAX_LENGTH = 30; + private static final int DISPLAY_NAME_MIN_LENGTH = 5; + private static final int DISPLAY_NAME_MAX_LENGTH = 30; + + private static final GenericValidator GENERIC_VALIDATOR = GenericValidator.getInstance(); + + public boolean validateUser(User user) throws ValidationException { + + if (user.getUserName() != null && !GENERIC_VALIDATOR.validateName(user.getUserName())) { + int minUserNameLength = GenericValidator.getNameMinLength(); + int maxUserNameLength = GenericValidator.getNameMaxLength(); + throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("userName", + minUserNameLength, maxUserNameLength)); + } + + if (user.getDisplayName() != null && !GENERIC_VALIDATOR.validateLength(user.getDisplayName(), + DISPLAY_NAME_MIN_LENGTH, DISPLAY_NAME_MAX_LENGTH)) { + throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("displayName", + DISPLAY_NAME_MIN_LENGTH, DISPLAY_NAME_MAX_LENGTH)); + } + + if (user.getEmail() != null && !GENERIC_VALIDATOR.validateEMail(user.getEmail())) { + throw new ValidationException("email is not valid"); + } + + if (user.getCompany() != null && !GENERIC_VALIDATOR.validateLength(user.getCompany(), + COMPANY_MIN_LENGTH, COMPANY_MAX_LENGTH)) { + throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("company", + COMPANY_MIN_LENGTH, COMPANY_MAX_LENGTH)); + } + + return true; + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 2d34e28..753eee4 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -18,8 +18,10 @@ import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.exceptions.ValidationException; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Users; +import org.fiware.apps.marketplace.model.validators.UserValidator; import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.context.ApplicationContext; @@ -28,37 +30,40 @@ @Path("/user") public class UserRegistrationService { - + // OBJECT ATTRIBUTES // private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); private UserBo userBo = (UserBo) context.getBean("userBo"); private UserRegistrationAuth userRegistrationAuth = (UserRegistrationAuth) context.getBean("userRegistrationAuth"); - + private UserValidator usersValidator = (UserValidator) context.getBean("usersValidator"); + // CLASS ATTRIBUTES // private static final ErrorUtils ERROR_UTILS = new ErrorUtils( "The user and/or the email introduced are already registered in the system"); - + // OBJECT METHODS // @POST @Consumes({"application/xml", "application/json"}) @Path("/") - public Response createUser(User localUser) { - + public Response createUser(User user) { + Response response; try { - if (userRegistrationAuth.canCreate()) { - localUser.setRegistrationDate(new Date()); - userBo.save(localUser); + if (userRegistrationAuth.canCreate() && usersValidator.validateUser(user)) { + user.setRegistrationDate(new Date()); + userBo.save(user); response = Response.status(Status.CREATED).build(); } else { response = ERROR_UTILS.unauthorizedResponse("create user"); } + } catch (ValidationException ex) { + response = ERROR_UTILS.badRequestResponse(ex.getMessage()); } catch (DataAccessException ex) { response = ERROR_UTILS.badRequestResponse(ex); } catch (Exception ex) { response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - + return response; } @@ -66,22 +71,43 @@ public Response createUser(User localUser) { @PUT @Consumes({"application/xml", "application/json"}) @Path("/{username}") - public Response updateUser(@PathParam("username") String username, User localUser) { - + public Response updateUser(@PathParam("username") String username, User user) { + Response response; try { User userToBeUpdated = userBo.findByName(username); - - if (userRegistrationAuth.canUpdate(userToBeUpdated)) { - userToBeUpdated.setCompany(localUser.getCompany()); - userToBeUpdated.setPassword(localUser.getPassword()); - userToBeUpdated.setEmail(localUser.getEmail()); - userToBeUpdated.setUserName(localUser.getUserName()); + + if (userRegistrationAuth.canUpdate(userToBeUpdated) + && usersValidator.validateUser(user)) { + if (user.getCompany() != null) { + userToBeUpdated.setCompany(user.getCompany()); + } + + if (user.getPassword() != null) { + userToBeUpdated.setPassword(user.getPassword()); + } + + if (user.getEmail() != null) { + userToBeUpdated.setEmail(user.getEmail()); + } + + if (user.getDisplayName() != null) { + userToBeUpdated.setDisplayName(user.getDisplayName()); + } + + // At this moment, user name cannot be changed to avoid error with sessions... + // userToBeUpdated.setUserName(user.getUserName()); + if (user.getUserName() != null && user.getUserName() != userToBeUpdated.getUserName()) { + throw new ValidationException("userName cannot be changed"); + } + userBo.update(userToBeUpdated); response = Response.status(Status.OK).build(); } else { response = ERROR_UTILS.unauthorizedResponse("update user " + username); } + } catch (ValidationException ex) { + response = ERROR_UTILS.badRequestResponse(ex.getMessage()); } catch (DataAccessException ex) { response = ERROR_UTILS.badRequestResponse(ex); } catch (UserNotFoundException ex) { @@ -89,7 +115,7 @@ public Response updateUser(@PathParam("username") String username, User localUse } catch (Exception ex) { response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - + return response; } @@ -112,7 +138,7 @@ public Response deleteUser(@PathParam("username") String username) { } catch (Exception ex) { response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - + return response; } @@ -135,7 +161,7 @@ public Response findUser(@PathParam("username") String username) { } catch (Exception ex) { response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } - + return response; } @@ -145,7 +171,7 @@ public Response findUser(@PathParam("username") String username) { public Response listUsers(@DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("100") @QueryParam("max") int max) { Response response; - + if (offset < 0 || max <= 0) { // Offset and Max should be checked response = ERROR_UTILS.badRequestResponse("offset and/or max are not valid"); @@ -161,7 +187,7 @@ public Response listUsers(@DefaultValue("0") @QueryParam("offset") int offset, response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } } - + return response; } } From dfd62ded95cf9663b3cf9986578a35c89503fb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 3 Dec 2014 12:35:26 +0100 Subject: [PATCH 25/69] Minor improvement --- .../apps/marketplace/model/validators/UserValidator.java | 2 +- .../apps/marketplace/rest/UserRegistrationService.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java index fef4553..e4de061 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java @@ -4,7 +4,7 @@ import org.fiware.apps.marketplace.model.User; import org.springframework.stereotype.Service; -@Service("usersValidator") +@Service("userValidator") public class UserValidator { private static final int COMPANY_MIN_LENGTH = 3; //For example: UPM, TID, SAP, ENG,... diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 753eee4..ec08693 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -35,7 +35,7 @@ public class UserRegistrationService { private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); private UserBo userBo = (UserBo) context.getBean("userBo"); private UserRegistrationAuth userRegistrationAuth = (UserRegistrationAuth) context.getBean("userRegistrationAuth"); - private UserValidator usersValidator = (UserValidator) context.getBean("usersValidator"); + private UserValidator userValidator = (UserValidator) context.getBean("userValidator"); // CLASS ATTRIBUTES // private static final ErrorUtils ERROR_UTILS = new ErrorUtils( @@ -49,7 +49,7 @@ public Response createUser(User user) { Response response; try { - if (userRegistrationAuth.canCreate() && usersValidator.validateUser(user)) { + if (userRegistrationAuth.canCreate() && userValidator.validateUser(user)) { user.setRegistrationDate(new Date()); userBo.save(user); response = Response.status(Status.CREATED).build(); @@ -78,7 +78,7 @@ public Response updateUser(@PathParam("username") String username, User user) { User userToBeUpdated = userBo.findByName(username); if (userRegistrationAuth.canUpdate(userToBeUpdated) - && usersValidator.validateUser(user)) { + && userValidator.validateUser(user)) { if (user.getCompany() != null) { userToBeUpdated.setCompany(user.getCompany()); } From f6ce96263da5bd075f056bc693f2710a50eb6451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 3 Dec 2014 12:53:08 +0100 Subject: [PATCH 26/69] Improve efficiency --- .../marketplace/rest/UserRegistrationService.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index ec08693..e252422 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -79,6 +79,13 @@ public Response updateUser(@PathParam("username") String username, User user) { if (userRegistrationAuth.canUpdate(userToBeUpdated) && userValidator.validateUser(user)) { + + // At this moment, user name cannot be changed to avoid error with sessions... + // userToBeUpdated.setUserName(user.getUserName()); + if (user.getUserName() != null && user.getUserName() != userToBeUpdated.getUserName()) { + throw new ValidationException("userName cannot be changed"); + } + if (user.getCompany() != null) { userToBeUpdated.setCompany(user.getCompany()); } @@ -95,12 +102,6 @@ public Response updateUser(@PathParam("username") String username, User user) { userToBeUpdated.setDisplayName(user.getDisplayName()); } - // At this moment, user name cannot be changed to avoid error with sessions... - // userToBeUpdated.setUserName(user.getUserName()); - if (user.getUserName() != null && user.getUserName() != userToBeUpdated.getUserName()) { - throw new ValidationException("userName cannot be changed"); - } - userBo.update(userToBeUpdated); response = Response.status(Status.OK).build(); } else { From 710b88e04b5b5f3fa56dba205c86ba82c25f0426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 3 Dec 2014 13:05:46 +0100 Subject: [PATCH 27/69] Store Validation --- .../model/validators/StoreValidator.java | 35 +++++++++++++++ .../rest/StoreRegistrationService.java | 45 +++++++++++++------ 2 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java new file mode 100644 index 0000000..38eb74b --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java @@ -0,0 +1,35 @@ +package org.fiware.apps.marketplace.model.validators; + +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.fiware.apps.marketplace.model.Store; +import org.springframework.stereotype.Service; + +@Service("storeValidator") +public class StoreValidator { + + private static final GenericValidator GENERIC_VALIDATOR = GenericValidator.getInstance(); + + public boolean validateStore(Store store) throws ValidationException { + + if (store.getName() != null && !GENERIC_VALIDATOR.validateName(store.getName())) { + int minNameLength = GenericValidator.getNameMinLength(); + int maxNameLength = GenericValidator.getNameMaxLength(); + throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("name", + minNameLength, maxNameLength)); + } + + if (store.getUrl() != null && !GENERIC_VALIDATOR.validateURL(store.getUrl())) { + throw new ValidationException("url is not valid"); + } + + if (store.getDescription() != null && !GENERIC_VALIDATOR.validateDescription(store.getDescription())) { + int minDescriptionLength = GenericValidator.getDescriptionMinLength(); + int maxDescriptionLength = GenericValidator.getDescriptionMaxLength(); + throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("description", + minDescriptionLength, maxDescriptionLength)); + } + + return true; + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 422e232..fb8424c 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -19,9 +19,11 @@ import org.fiware.apps.marketplace.bo.StoreBo; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.exceptions.ValidationException; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.model.Stores; +import org.fiware.apps.marketplace.model.validators.StoreValidator; import org.fiware.apps.marketplace.security.auth.AuthUtils; import org.fiware.apps.marketplace.security.auth.StoreRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; @@ -36,12 +38,15 @@ public class StoreRegistrationService { private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); private StoreBo storeBo = (StoreBo) context.getBean("storeBo"); private StoreRegistrationAuth storeRegistrationAuth = (StoreRegistrationAuth) context.getBean("storeRegistrationAuth"); + private StoreValidator storeValidator = (StoreValidator) context.getBean("storeValidator"); + // CLASS ATTRIBUTES // private static final AuthUtils AUTH_UTILS = AuthUtils.getAuthUtils(); private static final ErrorUtils ERROR_UTILS = new ErrorUtils( "There is already a Store with that name/URL registered in the system"); + // OBJECT METHODS // @POST @Consumes({"application/xml", "application/json"}) @@ -49,8 +54,8 @@ public class StoreRegistrationService { public Response createStore(Store store) { Response response; - if (storeRegistrationAuth.canCreate()) { - try { + try { + if (storeRegistrationAuth.canCreate() && storeValidator.validateStore(store)) { // Get the current user User currentUser = AUTH_UTILS.getLoggedUser(); @@ -61,15 +66,17 @@ public Response createStore(Store store) { // Save the new Store and return CREATED storeBo.save(store); response = Response.status(Status.CREATED).build(); - } catch (UserNotFoundException ex) { - response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); - } catch (DataAccessException ex) { - response = ERROR_UTILS.badRequestResponse(ex); - } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } else { + response = ERROR_UTILS.unauthorizedResponse("create store"); } - } else { - response = ERROR_UTILS.unauthorizedResponse("create store"); + } catch (ValidationException ex) { + response = ERROR_UTILS.badRequestResponse(ex.getMessage()); + } catch (UserNotFoundException ex) { + response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); + } catch (DataAccessException ex) { + response = ERROR_UTILS.badRequestResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } return response; @@ -84,9 +91,19 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor try { Store storeDB = storeBo.findByName(storeName); - if (storeRegistrationAuth.canUpdate(storeDB)) { - storeDB.setName(store.getName()); - storeDB.setUrl(store.getUrl()); + if (storeRegistrationAuth.canUpdate(storeDB) && storeValidator.validateStore(store)) { + if (store.getName() != null) { + storeDB.setName(store.getName()); + } + + if (store.getUrl() != null) { + storeDB.setUrl(store.getUrl()); + } + + if (store.getDescription() != null) { + storeDB.setDescription(store.getDescription()); + } + store.setLasteditor(AUTH_UTILS.getLoggedUser()); // Save the new Store and Return OK @@ -95,6 +112,8 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor } else { response = ERROR_UTILS.unauthorizedResponse("update store " + storeName); } + } catch (ValidationException ex) { + response = ERROR_UTILS.badRequestResponse(ex.getMessage()); } catch (UserNotFoundException ex) { response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); } catch (DataAccessException ex) { From c263e66632f8aaa2e25a53c73f984709a49222b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 3 Dec 2014 14:47:00 +0100 Subject: [PATCH 28/69] Validate services --- .../model/validators/ServiceValidator.java | 39 +++++++++++ .../model/validators/StoreValidator.java | 5 ++ .../model/validators/UserValidator.java | 5 ++ .../rest/OfferingRegistrationService.java | 67 ++++++++++++------- 4 files changed, 93 insertions(+), 23 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java new file mode 100644 index 0000000..bed5a08 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java @@ -0,0 +1,39 @@ +package org.fiware.apps.marketplace.model.validators; + +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.springframework.stereotype.Service; + +@Service("serviceValidator") +public class ServiceValidator { + + private static final GenericValidator GENERIC_VALIDATOR = GenericValidator.getInstance(); + + /** + * @param service Service to be checked + * @return True if the service is valid. Otherwise ValidationException will be thrown + * @throws ValidationException If service is not valid + */ + public boolean validateService(org.fiware.apps.marketplace.model.Service service) throws ValidationException { + + if (service.getName() != null && !GENERIC_VALIDATOR.validateName(service.getName())) { + int minNameLength = GenericValidator.getNameMinLength(); + int maxNameLength = GenericValidator.getNameMaxLength(); + throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("name", + minNameLength, maxNameLength)); + } + + if (service.getUrl() != null && !GENERIC_VALIDATOR.validateURL(service.getUrl())) { + throw new ValidationException("url is not valid"); + } + + if (service.getDescription() != null && !GENERIC_VALIDATOR.validateDescription(service.getDescription())) { + int minDescriptionLength = GenericValidator.getDescriptionMinLength(); + int maxDescriptionLength = GenericValidator.getDescriptionMaxLength(); + throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("description", + minDescriptionLength, maxDescriptionLength)); + } + + return true; + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java index 38eb74b..995566c 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java @@ -9,6 +9,11 @@ public class StoreValidator { private static final GenericValidator GENERIC_VALIDATOR = GenericValidator.getInstance(); + /** + * @param store Store to be checked + * @return True if the store is valid. Otherwise ValidationException will be thrown + * @throws ValidationException If store is not valid + */ public boolean validateStore(Store store) throws ValidationException { if (store.getName() != null && !GENERIC_VALIDATOR.validateName(store.getName())) { diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java index e4de061..95fa002 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java @@ -17,6 +17,11 @@ public class UserValidator { private static final GenericValidator GENERIC_VALIDATOR = GenericValidator.getInstance(); + /** + * @param user User to be checked + * @return True if the user is valid. Otherwise ValidationException will be thrown + * @throws ValidationException If user is not valid + */ public boolean validateUser(User user) throws ValidationException { if (user.getUserName() != null && !GENERIC_VALIDATOR.validateName(user.getUserName())) { diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index 578a607..9458bf4 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -21,10 +21,12 @@ import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.exceptions.ValidationException; import org.fiware.apps.marketplace.model.Services; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.model.validators.ServiceValidator; import org.fiware.apps.marketplace.security.auth.AuthUtils; import org.fiware.apps.marketplace.security.auth.OfferingRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; @@ -40,6 +42,7 @@ public class OfferingRegistrationService { private ServiceBo serviceBo = (ServiceBo) context.getBean("serviceBo"); private OfferingRegistrationAuth offeringRegistrationAuth = (OfferingRegistrationAuth) context.getBean("offeringRegistrationAuth"); + private ServiceValidator serviceValidator = (ServiceValidator) context.getBean("serviceValidator"); // CLASS ATTRIBUTES // private static final AuthUtils AUTH_UTILS = AuthUtils.getAuthUtils(); @@ -52,8 +55,9 @@ public class OfferingRegistrationService { public Response saveService(@PathParam("storeName") String storeName, Service service) { Response response; - if (offeringRegistrationAuth.canCreate()) { - try { + try { + if (offeringRegistrationAuth.canCreate() && serviceValidator.validateService(service)) { + User user = AUTH_UTILS.getLoggedUser(); Store store = storeBo.findByName(storeName); service.setRegistrationDate(new Date()); @@ -63,19 +67,22 @@ public Response saveService(@PathParam("storeName") String storeName, Service se serviceBo.save(service); response = Response.status(Status.CREATED).build(); - } catch (StoreNotFoundException ex) { - //The Store is an URL... If the Store does not exist a 404 - //should be returned instead of a 400 - response = ERROR_UTILS.entityNotFoundResponse(ex); - } catch (UserNotFoundException ex) { - response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); - } catch (DataAccessException ex) { - response = ERROR_UTILS.badRequestResponse(ex); - } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + } else { + response = ERROR_UTILS.unauthorizedResponse("create offering"); } - } else { - response = ERROR_UTILS.unauthorizedResponse("create offering"); + } catch (ValidationException ex) { + response = ERROR_UTILS.badRequestResponse(ex.getMessage()); + } catch (StoreNotFoundException ex) { + //The Store is an URL... If the Store does not exist a 404 + //should be returned instead of a 400 + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (UserNotFoundException ex) { + response = ERROR_UTILS.internalServerError( + "There was an error retrieving the user from the database"); + } catch (DataAccessException ex) { + response = ERROR_UTILS.badRequestResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); } return response; @@ -95,23 +102,38 @@ public Response updateService(@PathParam("storeName") String storeName, Store store = storeBo.findByName(storeName); //Check that the Store exists Service service = serviceBo.findByNameAndStore(serviceName, storeName); - if (offeringRegistrationAuth.canUpdate(service)) { - service.setName(serviceInfo.getName()); - service.setUrl(serviceInfo.getUrl()); + if (offeringRegistrationAuth.canUpdate(service) + && serviceValidator.validateService(serviceInfo)) { + + if (serviceInfo.getName() != null) { + service.setName(serviceInfo.getName()); + } + + if (serviceInfo.getUrl() != null) { + service.setUrl(serviceInfo.getUrl()); + } + + if (serviceInfo.getDescription() != null) { + service.setDescription(serviceInfo.getDescription()); + } + service.setLasteditor(AUTH_UTILS.getLoggedUser()); - //TODO: merger in model serviceBo.update(service); response = Response.status(Status.OK).build(); } else { - response = ERROR_UTILS.unauthorizedResponse("update offering " + serviceName); + response = ERROR_UTILS.unauthorizedResponse( + "update offering " + serviceName); } + } catch (ValidationException ex) { + response = ERROR_UTILS.badRequestResponse(ex.getMessage()); } catch (ServiceNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (StoreNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (UserNotFoundException ex) { - response = ERROR_UTILS.internalServerError("There was an error retrieving the user from the database"); + response = ERROR_UTILS.internalServerError( + "There was an error retrieving the user from the database"); } catch (DataAccessException ex) { response = ERROR_UTILS.badRequestResponse(ex); } catch (Exception ex) { @@ -123,7 +145,8 @@ public Response updateService(@PathParam("storeName") String storeName, @DELETE @Path("/{serviceName}") - public Response deleteService(@PathParam("storeName") String storeName, @PathParam("serviceName") String serviceName) { + public Response deleteService(@PathParam("storeName") String storeName, + @PathParam("serviceName") String serviceName) { Response response; try { @@ -219,6 +242,4 @@ public Response listServices(@PathParam("storeName") String storeName, return response; } - - } From 3c40c4a986a173ee5bbee573b41d84b6d1c05bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Fri, 5 Dec 2014 10:57:44 +0100 Subject: [PATCH 29/69] Support for OAuth2 --- pom.xml | 107 +++++++++++------ .../fiware/apps/marketplace/bo/UserBo.java | 6 +- .../apps/marketplace/oauth2/FIWAREApi.java | 35 ++++++ .../oauth2/FIWAREAttributesDefinition.java | 17 +++ .../apps/marketplace/oauth2/FIWAREClient.java | 113 ++++++++++++++++++ .../marketplace/oauth2/FIWAREProfile.java | 24 ++++ src/main/resources/spring/config/security.xml | 2 +- .../spring/config/securityOAuth2.xml | 76 ++++++++++++ src/main/webapp/WEB-INF/web.xml | 55 +-------- 9 files changed, 344 insertions(+), 91 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREApi.java create mode 100644 src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java create mode 100644 src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java create mode 100644 src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java create mode 100644 src/main/resources/spring/config/securityOAuth2.xml diff --git a/pom.xml b/pom.xml index aa367d3..368694f 100644 --- a/pom.xml +++ b/pom.xml @@ -21,21 +21,43 @@ OAuth Repository http://oauth.googlecode.com/svn/code/maven + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + scribe-java-mvn-repo + https://raw.github.com/fernandezpablo85/scribe-java/mvn-repo/ + + true + always + + + net.oauth.core oauth 20090825 + net.oauth.core oauth-httpclient4 20090617 - junit junit @@ -44,14 +66,13 @@ - + org.jboss.resteasy resteasy-jaxrs 3.0.10.Final - org.jboss.resteasy resteasy-jackson-provider @@ -70,24 +91,20 @@ 3.0.10.Final - - org.jboss.resteasy resteasy-oauth 3.0.10.Final - - - - + org.apache.httpcomponents httpclient 4.3.5 compile + org.apache.httpcomponents httpmime @@ -95,17 +112,6 @@ compile - - javax.activation - activation - 1.1.1 - - - com.hp.hpl.jena - arq - 2.8.8 - - org.springframework @@ -113,7 +119,6 @@ 4.1.1.RELEASE - org.springframework spring-context @@ -136,28 +141,21 @@ org.springframework.security spring-security-core - 3.2.5.RELEASE + 3.2.2.RELEASE - + org.springframework.security spring-security-web - 3.2.5.RELEASE + 3.2.2.RELEASE - + org.springframework.security spring-security-config - 3.2.5.RELEASE - - - - org.codehaus.spring-security-oauth - spring-security-oauth - 3.19.SS3 + 3.2.2.RELEASE - cglib @@ -173,7 +171,6 @@ - org.hibernate hibernate-core @@ -186,7 +183,6 @@ 3.18.2-GA - dom4j @@ -206,12 +202,53 @@ 4.0 + + + commons-validator + commons-validator + 1.4.0 + + org.antlr antlr4 4.3 + + javax.activation + activation + 1.1.1 + + + com.hp.hpl.jena + arq + 2.8.8 + + + + + org.pac4j + spring-security-pac4j + 1.2.4 + + + org.springframework.security + spring-security-web + + + org.springframework.security + spring-security-config + + + + + + org.pac4j + pac4j-oauth + 1.6.0 + + diff --git a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java index 3d66eb0..e689ce6 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java @@ -7,9 +7,9 @@ public interface UserBo { - void save(User localuser); - void update(User localuser); - void delete(User localuser); + void save(User user); + void update(User user); + void delete(User luser); User findByName(String username) throws UserNotFoundException; List getUsersPage(int offset, int max); List getAllUsers(); diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREApi.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREApi.java new file mode 100644 index 0000000..198e24e --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREApi.java @@ -0,0 +1,35 @@ +package org.fiware.apps.marketplace.oauth2; + +import org.scribe.builder.api.DefaultApi20; +import org.scribe.extractors.AccessTokenExtractor; +import org.scribe.extractors.JsonTokenExtractor; +import org.scribe.model.OAuthConfig; +import org.scribe.model.Verb; +import org.scribe.utils.OAuthEncoder; + +public class FIWAREApi extends DefaultApi20 { + + private static final String AUTHORIZATION_URL = "https://account.lab.fi-ware.org/authorize" + + "?client_id=%s&redirect_uri=%s&scope=%s&response_type=code"; + + @Override + public String getAccessTokenEndpoint() { + return "https://account.lab.fi-ware.org/token"; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + return String.format(AUTHORIZATION_URL, config.getApiKey(), + OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } +} diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java new file mode 100644 index 0000000..1622cdf --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java @@ -0,0 +1,17 @@ +package org.fiware.apps.marketplace.oauth2; + +import org.pac4j.core.profile.converter.Converters; +import org.pac4j.oauth.profile.OAuthAttributesDefinition; + +public class FIWAREAttributesDefinition extends OAuthAttributesDefinition { + + public static final String USER_NAME = "nickName"; + public static final String DISPLAY_NAME = "displayName"; + public static final String EMAIL = "email"; + + public FIWAREAttributesDefinition() { + addAttribute(DISPLAY_NAME, Converters.stringConverter); + addAttribute(EMAIL, Converters.stringConverter); + addAttribute(USER_NAME, Converters.stringConverter); + } +} \ No newline at end of file diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java new file mode 100644 index 0000000..1426fe2 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java @@ -0,0 +1,113 @@ +package org.fiware.apps.marketplace.oauth2; + +import java.util.Date; + +import org.fiware.apps.marketplace.bo.UserBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.User; +import org.fiware.apps.marketplace.utils.ApplicationContextProvider; +import org.pac4j.core.client.BaseClient; +import org.pac4j.core.context.WebContext; +import org.pac4j.oauth.client.BaseOAuth20Client; +import org.pac4j.oauth.client.exception.OAuthCredentialsException; +import org.pac4j.oauth.credentials.OAuthCredentials; +import org.pac4j.oauth.profile.JsonHelper; +import org.scribe.model.OAuthConfig; +import org.scribe.model.Token; +import org.scribe.model.SignatureType; +import org.scribe.oauth.ProxyOAuth20ServiceImpl; +import org.springframework.context.ApplicationContext; + +import com.fasterxml.jackson.databind.JsonNode; + + +public class FIWAREClient extends BaseOAuth20Client{ + + // To store users information + private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); + private UserBo userBo = (UserBo) context.getBean("userBo"); + + private String scopeValue = ""; + + @Override + protected void internalInit() { + super.internalInit(); + + this.scopeValue = ""; + this.service = new ProxyOAuth20ServiceImpl(new FIWAREApi(), + new OAuthConfig(this.key, this.secret, + this.callbackUrl, + SignatureType.Header, + this.scopeValue, null), + this.connectTimeout, this.readTimeout, this.proxyHost, + this.proxyPort, false, true); + } + + @Override + protected boolean requiresStateParameter() { + return false; + } + + @Override + protected FIWAREProfile extractUserProfile(String body) { + FIWAREProfile profile = new FIWAREProfile(); + + final JsonNode json = JsonHelper.getFirstNode(body); + if (json != null) { + profile.setId(JsonHelper.get(json, "id")); + for (final String attribute : new FIWAREAttributesDefinition().getPrincipalAttributes()) { + profile.addAttribute(attribute, JsonHelper.get(json, attribute)); + } + } + + // FIXME: By default, we are adding the default Role... + profile.addRole("ROLE_USER"); + + // User information should be stored in the local users table // + User user; + String username = (String) profile.getAttribute(profile.getUsername()); + String email = (String) profile.getAttribute(profile.getEmail()); + String displayName = (String) profile.getAttribute(profile.getDisplayName()); + + try { + user = userBo.findByName(username); + } catch (UserNotFoundException e) { + user = new User(); + user.setRegistrationDate(new Date()); + } + + // Set field values + user.setUserName(username); + user.setEmail(email); + user.setPassword(""); // Password cannot be NULL + user.setDisplayName(displayName); + + // Save the new user + userBo.save(user); + + return profile; + } + + @Override + protected String getProfileUrl(Token arg0) { + return "https://account.lab.fi-ware.org/user"; + } + + @Override + protected boolean hasBeenCancelled(WebContext context) { + final String error = context.getRequestParameter(OAuthCredentialsException.ERROR); + + // user has denied permissions + if ("access_denied".equals(error)) { + return true; + } else { + return false; + } + } + + @Override + protected BaseClient newClient() { + FIWAREClient newClient = new FIWAREClient(); + return newClient; + } +} diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java new file mode 100644 index 0000000..bc55e3e --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java @@ -0,0 +1,24 @@ +package org.fiware.apps.marketplace.oauth2; + +import org.pac4j.oauth.profile.OAuth20Profile; + +public class FIWAREProfile extends OAuth20Profile{ + + private static final long serialVersionUID = 1L; + + @Override + public String getDisplayName() { + return "displayName"; + } + + @Override + public String getEmail() { + return "email"; + } + + @Override + public String getUsername() { + return "nickName"; + } + +} diff --git a/src/main/resources/spring/config/security.xml b/src/main/resources/spring/config/security.xml index 842d25c..b8bcea1 100644 --- a/src/main/resources/spring/config/security.xml +++ b/src/main/resources/spring/config/security.xml @@ -11,7 +11,7 @@ - + diff --git a/src/main/resources/spring/config/securityOAuth2.xml b/src/main/resources/spring/config/securityOAuth2.xml new file mode 100644 index 0000000..6a355b1 --- /dev/null +++ b/src/main/resources/spring/config/securityOAuth2.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 1089b81..4d37e9e 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -16,55 +16,6 @@ /* - - - CORS - com.thetransactioncompany.cors.CORSFilter - - - - cors.allowGenericHttpRequests - true - - - - cors.allowOrigin - * - - - - cors.supportedMethods - GET, HEAD, POST, OPTIONS, PUT, DELETE - - - - cors.supportedHeaders - Content-Type, X-Requested-With - - - - cors.exposedHeaders - X-Test-1, X-Test-2 - - - - cors.supportsCredentials - true - - - - cors.maxAge - 3600 - - - - - - CORS - * - - resteasy.resources org.fiware.apps.marketplace.rest.StoreRegistrationService, @@ -80,7 +31,7 @@ resteasy.servlet.mapping.prefix - /v1 + /api @@ -98,14 +49,14 @@ resteasy-servlet - /v1/* + /api/* contextConfigLocation /WEB-INF/classes/spring/config/BeanLocations.xml - /WEB-INF/classes/spring/config/security.xml + /WEB-INF/classes/spring/config/securityOAuth2.xml From 0c39618169692f42883c12378ff9e816beb48ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 15 Dec 2014 17:22:56 +0100 Subject: [PATCH 30/69] Get userName in AuthUtils when OAuth2 is being used --- .../model/validators/ServiceValidator.java | 4 +++ .../model/validators/StoreValidator.java | 4 +++ .../model/validators/UserValidator.java | 4 +++ .../oauth2/FIWAREAttributesDefinition.java | 3 +- .../apps/marketplace/oauth2/FIWAREClient.java | 10 ++++--- .../marketplace/oauth2/FIWAREProfile.java | 10 +++---- .../rest/OfferingRegistrationService.java | 6 ++-- .../rest/StoreRegistrationService.java | 10 +++---- .../marketplace/security/auth/AuthUtils.java | 30 ++++++++++--------- .../security/auth/RegistrationAuth.java | 8 +++-- 10 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java index bed5a08..5baae4f 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java @@ -15,6 +15,10 @@ public class ServiceValidator { */ public boolean validateService(org.fiware.apps.marketplace.model.Service service) throws ValidationException { + if (service.getName() == null || service.getUrl() == null) { + throw new ValidationException("name and/or url cannot be null"); + } + if (service.getName() != null && !GENERIC_VALIDATOR.validateName(service.getName())) { int minNameLength = GenericValidator.getNameMinLength(); int maxNameLength = GenericValidator.getNameMaxLength(); diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java index 995566c..391b18c 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java @@ -16,6 +16,10 @@ public class StoreValidator { */ public boolean validateStore(Store store) throws ValidationException { + if (store.getName() == null || store.getUrl() == null) { + throw new ValidationException("name and/or url cannot be null"); + } + if (store.getName() != null && !GENERIC_VALIDATOR.validateName(store.getName())) { int minNameLength = GenericValidator.getNameMinLength(); int maxNameLength = GenericValidator.getNameMaxLength(); diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java index 95fa002..cedf734 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java @@ -24,6 +24,10 @@ public class UserValidator { */ public boolean validateUser(User user) throws ValidationException { + if (user.getUserName() == null || user.getEmail() == null || user.getPassword() == null) { + throw new ValidationException("name, email and/or password cannot be null"); + } + if (user.getUserName() != null && !GENERIC_VALIDATOR.validateName(user.getUserName())) { int minUserNameLength = GenericValidator.getNameMinLength(); int maxUserNameLength = GenericValidator.getNameMaxLength(); diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java index 1622cdf..ae6f273 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java @@ -5,12 +5,13 @@ public class FIWAREAttributesDefinition extends OAuthAttributesDefinition { + public static final String NAME = "name"; public static final String USER_NAME = "nickName"; public static final String DISPLAY_NAME = "displayName"; public static final String EMAIL = "email"; public FIWAREAttributesDefinition() { - addAttribute(DISPLAY_NAME, Converters.stringConverter); + addAttribute(DISPLAY_NAME, Converters.stringConverter); addAttribute(EMAIL, Converters.stringConverter); addAttribute(USER_NAME, Converters.stringConverter); } diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java index 1426fe2..ff11cac 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java @@ -54,7 +54,7 @@ protected FIWAREProfile extractUserProfile(String body) { final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { - profile.setId(JsonHelper.get(json, "id")); + profile.setId(JsonHelper.get(json, "nickName")); for (final String attribute : new FIWAREAttributesDefinition().getPrincipalAttributes()) { profile.addAttribute(attribute, JsonHelper.get(json, attribute)); } @@ -65,13 +65,15 @@ protected FIWAREProfile extractUserProfile(String body) { // User information should be stored in the local users table // User user; - String username = (String) profile.getAttribute(profile.getUsername()); - String email = (String) profile.getAttribute(profile.getEmail()); - String displayName = (String) profile.getAttribute(profile.getDisplayName()); + String username = (String) profile.getUsername(); + String email = (String) profile.getEmail(); + String displayName = (String) profile.getDisplayName(); try { + // Modify the existing user user = userBo.findByName(username); } catch (UserNotFoundException e) { + // Create a new user user = new User(); user.setRegistrationDate(new Date()); } diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java index bc55e3e..c29324b 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java @@ -8,17 +8,17 @@ public class FIWAREProfile extends OAuth20Profile{ @Override public String getDisplayName() { - return "displayName"; + return (String) this.getAttribute("displayName"); } @Override - public String getEmail() { - return "email"; + public String getUsername() { + return (String) this.getAttribute("nickName"); } @Override - public String getUsername() { - return "nickName"; + public String getTypedId() { + return super.getTypedId(); } } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index 9458bf4..b3d7c2e 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -43,9 +43,9 @@ public class OfferingRegistrationService { private OfferingRegistrationAuth offeringRegistrationAuth = (OfferingRegistrationAuth) context.getBean("offeringRegistrationAuth"); private ServiceValidator serviceValidator = (ServiceValidator) context.getBean("serviceValidator"); + private AuthUtils authUtils = (AuthUtils) context.getBean("authUtils"); // CLASS ATTRIBUTES // - private static final AuthUtils AUTH_UTILS = AuthUtils.getAuthUtils(); private static final ErrorUtils ERROR_UTILS = new ErrorUtils( "There is already an Offering in this Store with that name/URL"); @@ -58,7 +58,7 @@ public Response saveService(@PathParam("storeName") String storeName, Service se try { if (offeringRegistrationAuth.canCreate() && serviceValidator.validateService(service)) { - User user = AUTH_UTILS.getLoggedUser(); + User user = authUtils.getLoggedUser(); Store store = storeBo.findByName(storeName); service.setRegistrationDate(new Date()); service.setStore(store); @@ -117,7 +117,7 @@ public Response updateService(@PathParam("storeName") String storeName, service.setDescription(serviceInfo.getDescription()); } - service.setLasteditor(AUTH_UTILS.getLoggedUser()); + service.setLasteditor(authUtils.getLoggedUser()); serviceBo.update(service); response = Response.status(Status.OK).build(); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index fb8424c..749b429 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -27,6 +27,7 @@ import org.fiware.apps.marketplace.security.auth.AuthUtils; import org.fiware.apps.marketplace.security.auth.StoreRegistrationAuth; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.dao.DataAccessException; @@ -39,14 +40,13 @@ public class StoreRegistrationService { private StoreBo storeBo = (StoreBo) context.getBean("storeBo"); private StoreRegistrationAuth storeRegistrationAuth = (StoreRegistrationAuth) context.getBean("storeRegistrationAuth"); private StoreValidator storeValidator = (StoreValidator) context.getBean("storeValidator"); - + private AuthUtils authUtils = (AuthUtils) context.getBean("authUtils"); // CLASS ATTRIBUTES // - private static final AuthUtils AUTH_UTILS = AuthUtils.getAuthUtils(); + @Autowired private static final ErrorUtils ERROR_UTILS = new ErrorUtils( "There is already a Store with that name/URL registered in the system"); - // OBJECT METHODS // @POST @Consumes({"application/xml", "application/json"}) @@ -57,7 +57,7 @@ public Response createStore(Store store) { try { if (storeRegistrationAuth.canCreate() && storeValidator.validateStore(store)) { // Get the current user - User currentUser = AUTH_UTILS.getLoggedUser(); + User currentUser = authUtils.getLoggedUser(); store.setRegistrationDate(new Date()); store.setCreator(currentUser); @@ -104,7 +104,7 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor storeDB.setDescription(store.getDescription()); } - store.setLasteditor(AUTH_UTILS.getLoggedUser()); + store.setLasteditor(authUtils.getLoggedUser()); // Save the new Store and Return OK storeBo.update(storeDB); diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java index 3ea083c..7e32345 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java @@ -4,27 +4,29 @@ import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.utils.ApplicationContextProvider; +import org.pac4j.springframework.security.authentication.ClientAuthenticationToken; +import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +@Service("authUtils") public class AuthUtils { - // Avoid users to instantiate this class - private AuthUtils() { - this.localuserBo = (UserBo) ApplicationContextProvider.getApplicationContext().getBean("userBo"); - } - - public static AuthUtils getAuthUtils() { - return singleton; - } - - //Singleton - private static AuthUtils singleton = new AuthUtils(); - //Instance attributes - private UserBo localuserBo; + private UserBo localuserBo = (UserBo) ApplicationContextProvider.getApplicationContext().getBean("userBo"); public User getLoggedUser() throws UserNotFoundException { - return localuserBo.findByName(SecurityContextHolder.getContext().getAuthentication().getName()); + String userName; + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + + // When OAuth2 is being used, we should cast the authentication to read the correct user name + if (authentication instanceof ClientAuthenticationToken) { + userName = ((ClientAuthenticationToken) authentication).getUserProfile().getId(); + } else { + userName = SecurityContextHolder.getContext().getAuthentication().getName(); + } + + return localuserBo.findByName(userName); } } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java index dac4cf1..e132f42 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java @@ -2,9 +2,13 @@ import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; +import org.springframework.beans.factory.annotation.Autowired; public abstract class RegistrationAuth { + @Autowired + private AuthUtils authUtils; + /** * Method to return the Localuser who is owner of the entity * @param entity The entity whose owner the developer wants to know @@ -21,7 +25,7 @@ protected boolean isLoggedUserTheOwner(T entity) { boolean canAccess = false; try { - User loggedUser = AuthUtils.getAuthUtils().getLoggedUser(); + User loggedUser = authUtils.getLoggedUser(); // logged User can be null if the user is not logged in... if (loggedUser != null && loggedUser.equals(this.getEntityOwner(entity))) { canAccess = true; @@ -42,7 +46,7 @@ protected boolean isLoggedIn() { boolean isLoggedIn = false; try { - isLoggedIn = AuthUtils.getAuthUtils().getLoggedUser() != null; + isLoggedIn = authUtils.getLoggedUser() != null; } catch (UserNotFoundException ex) { //Nothing to do... False will be returned } From 76508f5e92c5f69f295e96b96f3753bb5e93ca6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 15 Dec 2014 18:08:23 +0100 Subject: [PATCH 31/69] Add tests for OfferingRegistrationAuth --- .../auth/OfferingRegistrationAuthTest.java | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java new file mode 100644 index 0000000..7124744 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java @@ -0,0 +1,152 @@ +package org.fiware.apps.marketplace.security.auth; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.Service; +import org.fiware.apps.marketplace.model.User; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + + + +public class OfferingRegistrationAuthTest { + + public static class FinalTest extends OfferingRegistrationAuthTest { + + @Mock private AuthUtils authUtils; + @InjectMocks private static OfferingRegistrationAuth authHelper; + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private User createBasicUser(int id) { + User user = new User(); + user.setId(id); + return user; + } + + private Service setUpTestUpdateAndDelete(User creator, User updater) { + // Set up the test + Service service = new Service(); + service.setCreator(creator); + + try { + when(authUtils.getLoggedUser()).thenReturn(updater); + } catch (UserNotFoundException e) { + // never happens + } + + return service; + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST CREATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void canCreateOffering() throws UserNotFoundException { + when(authUtils.getLoggedUser()).thenReturn(new User()); + assertThat(authHelper.canCreate()).isTrue(); + } + + @Test + public void canNotCreateOffering() throws UserNotFoundException { + doThrow(new UserNotFoundException("")).when(authUtils).getLoggedUser(); + assertThat(authHelper.canCreate()).isFalse(); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private void testUpdate(User creator, User updater, boolean canUpdate) { + Service service = setUpTestUpdateAndDelete(creator, updater); + + // Execute the test + boolean result = authHelper.canUpdate(service); + + // Check the result + assertThat(result).isEqualTo(canUpdate); + + } + + @Test + public void canUpdateOffering() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testUpdate(creator, updater, true); + } + + @Test + public void canNotUpdateOfferingNotSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testUpdate(creator, updater, false); + } + + @Test + public void canNotUpdateOfferingNotLoggedIn() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = null; + testUpdate(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST DELETE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + private void testDelete(User creator, User updater, boolean canDelete) { + Service service = setUpTestUpdateAndDelete(creator, updater); + + // Execute the test + boolean result = authHelper.canDelete(service); + + // Check the result + assertThat(result).isEqualTo(canDelete); + + } + + @Test + public void canDeleteOffering() { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testDelete(creator, updater, true); + } + + @Test + public void canNotDeleteOfferingNotSameUser() { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testDelete(creator, updater, false); + } + + @Test + public void canNotDeleteOfferingNotLoggedIn() { + User creator = createBasicUser(1); + User updater = null; + testDelete(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST LIST ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + @Test + public void canList() { + assertThat(authHelper.canList()).isTrue(); + } + } + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } +} From 7d8917541018c8a01f2733fd85ce7b37a7c12e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 16 Dec 2014 14:26:57 +0100 Subject: [PATCH 32/69] Check functions used to auth users for manage users and stores --- .../auth/OfferingRegistrationAuthTest.java | 16 +- .../auth/StoreRegistrationAuthTest.java | 164 ++++++++++++++++++ .../auth/UserRegistrationAuthTest.java | 150 ++++++++++++++++ 3 files changed, 328 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java create mode 100644 src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java index 7124744..e403555 100644 --- a/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java @@ -16,7 +16,7 @@ public class OfferingRegistrationAuthTest { - public static class FinalTest extends OfferingRegistrationAuthTest { + public static class OfferingAuthTest extends OfferingRegistrationAuthTest { @Mock private AuthUtils authUtils; @InjectMocks private static OfferingRegistrationAuth authHelper; @@ -78,6 +78,12 @@ private void testUpdate(User creator, User updater, boolean canUpdate) { } + @Test + public void canUpdateOfferingSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + testUpdate(creator, creator, true); + } + @Test public void canUpdateOffering() throws UserNotFoundException { User creator = createBasicUser(1); @@ -114,6 +120,12 @@ private void testDelete(User creator, User updater, boolean canDelete) { } + @Test + public void canDeleteOfferingSameUser() { + User creator = createBasicUser(1); + testDelete(creator, creator, true); + } + @Test public void canDeleteOffering() { User creator = createBasicUser(1); @@ -137,7 +149,7 @@ public void canNotDeleteOfferingNotLoggedIn() { /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST LIST ///////////////////////////////////// + ////////////////////////////////////// TEST LIST ////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// @Test public void canList() { diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java new file mode 100644 index 0000000..8b0abaa --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java @@ -0,0 +1,164 @@ +package org.fiware.apps.marketplace.security.auth; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.model.User; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + + + +public class StoreRegistrationAuthTest { + + public static class StoreAuthTest extends StoreRegistrationAuthTest { + + @Mock private AuthUtils authUtils; + @InjectMocks private static StoreRegistrationAuth authHelper; + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private User createBasicUser(int id) { + User user = new User(); + user.setId(id); + return user; + } + + private Store setUpTestUpdateAndDelete(User creator, User updater) { + // Set up the test + Store store = new Store(); + store.setCreator(creator); + + try { + when(authUtils.getLoggedUser()).thenReturn(updater); + } catch (UserNotFoundException e) { + // never happens + } + + return store; + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST CREATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void canCreateStore() throws UserNotFoundException { + when(authUtils.getLoggedUser()).thenReturn(new User()); + assertThat(authHelper.canCreate()).isTrue(); + } + + @Test + public void canNotCreateStore() throws UserNotFoundException { + doThrow(new UserNotFoundException("")).when(authUtils).getLoggedUser(); + assertThat(authHelper.canCreate()).isFalse(); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private void testUpdate(User creator, User updater, boolean canUpdate) { + Store store = setUpTestUpdateAndDelete(creator, updater); + + // Execute the test + boolean result = authHelper.canUpdate(store); + + // Check the result + assertThat(result).isEqualTo(canUpdate); + + } + + @Test + public void canUpdateStoreSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + testUpdate(creator, creator, true); + } + + @Test + public void canUpdateStore() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testUpdate(creator, updater, true); + } + + @Test + public void canNotUpdateStoreNotSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testUpdate(creator, updater, false); + } + + @Test + public void canNotUpdateStoreNotLoggedIn() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = null; + testUpdate(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST DELETE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + private void testDelete(User creator, User updater, boolean canDelete) { + Store store = setUpTestUpdateAndDelete(creator, updater); + + // Execute the test + boolean result = authHelper.canDelete(store); + + // Check the result + assertThat(result).isEqualTo(canDelete); + + } + + @Test + public void canDeleteStoreSameUser() { + User creator = createBasicUser(1); + testDelete(creator, creator, true); + } + + @Test + public void canDeleteStore() { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testDelete(creator, updater, true); + } + + @Test + public void canNotDeleteStoreNotSameUser() { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testDelete(creator, updater, false); + } + + @Test + public void canNotDeleteStoreNotLoggedIn() { + User creator = createBasicUser(1); + User updater = null; + testDelete(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////// TEST LIST ////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + @Test + public void canList() { + assertThat(authHelper.canList()).isTrue(); + } + } + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } +} diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java new file mode 100644 index 0000000..f03db40 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java @@ -0,0 +1,150 @@ +package org.fiware.apps.marketplace.security.auth; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.User; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + + + +public class UserRegistrationAuthTest { + + public static class UserAuthTest extends UserRegistrationAuthTest { + + @Mock private AuthUtils authUtils; + @InjectMocks private static UserRegistrationAuth authHelper; + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private User createBasicUser(int id) { + User user = new User(); + user.setId(id); + return user; + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST CREATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void canCreateUser() throws UserNotFoundException { + assertThat(authHelper.canCreate()).isTrue(); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private void testUpdate(User creator, User updater, boolean canUpdate) { + try { + when(authUtils.getLoggedUser()).thenReturn(updater); + } catch (UserNotFoundException e) { + // Nothing to do... + } + + // Execute the test + boolean result = authHelper.canUpdate(creator); + + // Check the result + assertThat(result).isEqualTo(canUpdate); + + } + + @Test + public void canUpdateUserSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + testUpdate(creator, creator, true); + } + + @Test + public void canUpdateUser() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testUpdate(creator, updater, true); + } + + @Test + public void canNotUpdateUserNotSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testUpdate(creator, updater, false); + } + + @Test + public void canNotUpdateUserNotLoggedIn() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = null; + testUpdate(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST DELETE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + private void testDelete(User creator, User updater, boolean canDelete) { + try { + when(authUtils.getLoggedUser()).thenReturn(updater); + } catch (UserNotFoundException e) { + // Nothing to do... + } + + // Execute the test + boolean result = authHelper.canDelete(creator); + + // Check the result + assertThat(result).isEqualTo(canDelete); + + } + + @Test + public void canDeleteUserSameUser() { + User creator = createBasicUser(1); + testDelete(creator, creator, true); + } + + @Test + public void canDeleteUser() { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testDelete(creator, updater, true); + } + + @Test + public void canNotDeleteUserNotSameUser() { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testDelete(creator, updater, false); + } + + @Test + public void canNotDeleteUserNotLoggedIn() { + User creator = createBasicUser(1); + User updater = null; + testDelete(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////// TEST LIST ////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + @Test + public void canList() { + assertThat(authHelper.canList()).isTrue(); + } + } + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } +} From f71b1eca6ab34f318b72a7421f9c89019dffbeb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 16 Dec 2014 14:34:01 +0100 Subject: [PATCH 33/69] Add dependencies to POM --- pom.xml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 368694f..5309acd 100644 --- a/pom.xml +++ b/pom.xml @@ -65,6 +65,18 @@ test + + org.assertj + assertj-core + 1.7.0 + test + + + + org.mockito + mockito-core + 1.10.8 + @@ -143,7 +155,7 @@ spring-security-core 3.2.2.RELEASE - + org.springframework.security spring-security-web From 0395bbdb4d65a32009aec9f0fae7a1a32e6debb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 16 Dec 2014 15:02:26 +0100 Subject: [PATCH 34/69] Test users validatior --- .../model/validators/UserValidatorTest.java | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java new file mode 100644 index 0000000..f5c45a8 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java @@ -0,0 +1,150 @@ +package org.fiware.apps.marketplace.model.validators; + +import static org.assertj.core.api.Assertions.*; + +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.fiware.apps.marketplace.model.User; +import org.junit.Test; + +public class UserValidatorTest { + + private UserValidator userValidator = new UserValidator(); + + private static final String MISSING_FILEDS_MSG = "name, email and/or password cannot be null"; + private static final String INVALID_LENGTH_BASIC = "%s is not valid. (min length: %d, max length: %d)"; + + private User generateValidUser() { + User user = new User(); + user.setUserName("userName"); + user.setPassword("1234"); + user.setEmail("example@example.com"); + user.setCompany("EXAMPLE"); + user.setDisplayName("Example Name"); + + return user; + } + + private void assertInvalidUser(User user, String expectedMsg) { + try { + userValidator.validateUser(user); + failBecauseExceptionWasNotThrown(ValidationException.class); + } catch (ValidationException ex) { + assertThat(ex).hasMessage(expectedMsg); + } + } + + @Test + public void testValidBasicUser() throws ValidationException { + User user = new User(); + user.setUserName("userName"); + user.setPassword("1234"); + user.setEmail("example@example.com"); + + assertThat(userValidator.validateUser(user)).isTrue(); + } + + @Test + public void testValidComplexUser() throws ValidationException { + User user = generateValidUser(); + assertThat(userValidator.validateUser(user)).isTrue(); + } + + @Test + public void testMissingUserName() { + // Generate a user without username + User user = generateValidUser(); + user.setUserName(null); + + assertInvalidUser(user, MISSING_FILEDS_MSG); + } + + @Test + public void testMissingPassword() { + // Generate a user without password + User user = generateValidUser(); + user.setPassword(null); + + assertInvalidUser(user, MISSING_FILEDS_MSG); + } + + @Test + public void testMissingMail() { + // Generate a user without mail + User user = generateValidUser(); + user.setEmail(null); + + assertInvalidUser(user, MISSING_FILEDS_MSG); + } + + @Test + public void testUserNameTooShort() { + User user = generateValidUser(); + user.setUserName("a"); + + assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "userName", 5, 15)); + } + + @Test + public void testUserNameTooLong() { + User user = generateValidUser(); + user.setUserName("1234567890123456"); + + assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "userName", 5, 15)); + } + + @Test + public void testDisplayNameTooShort() { + User user = generateValidUser(); + user.setDisplayName("a"); + + assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "displayName", 5, 30)); + } + + @Test + public void testDisplayNameTooLong() { + User user = generateValidUser(); + user.setDisplayName("1234567890123456789012345678901"); + + assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "displayName", 5, 30)); + } + + @Test + public void testInvalidMail1() { + User user = generateValidUser(); + user.setEmail("test"); + + assertInvalidUser(user, "email is not valid"); + } + + @Test + public void testInvalidMail2() { + User user = generateValidUser(); + user.setEmail("test@test"); + + assertInvalidUser(user, "email is not valid"); + } + + @Test + public void testInvalidMail3() { + User user = generateValidUser(); + user.setEmail("@test.com"); + + assertInvalidUser(user, "email is not valid"); + } + + @Test + public void testCompanyTooShort() { + User user = generateValidUser(); + user.setCompany("a"); + + assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "company", 3, 30)); + } + + @Test + public void testCompanyTooLong() { + User user = generateValidUser(); + user.setCompany("1234567890123456789012345678901"); + + assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "company", 3, 30)); + } +} From aecf587c6cd5abb272b7dd9006c9babda947c5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 16 Dec 2014 15:04:55 +0100 Subject: [PATCH 35/69] Minor fix --- .../model/validators/UserValidatorTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java index f5c45a8..8b33cdc 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java @@ -11,7 +11,7 @@ public class UserValidatorTest { private UserValidator userValidator = new UserValidator(); private static final String MISSING_FILEDS_MSG = "name, email and/or password cannot be null"; - private static final String INVALID_LENGTH_BASIC = "%s is not valid. (min length: %d, max length: %d)"; + private static final String INVALID_LENGTH_PATTERN = "%s is not valid. (min length: %d, max length: %d)"; private User generateValidUser() { User user = new User(); @@ -81,7 +81,7 @@ public void testUserNameTooShort() { User user = generateValidUser(); user.setUserName("a"); - assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "userName", 5, 15)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "userName", 5, 15)); } @Test @@ -89,7 +89,7 @@ public void testUserNameTooLong() { User user = generateValidUser(); user.setUserName("1234567890123456"); - assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "userName", 5, 15)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "userName", 5, 15)); } @Test @@ -97,7 +97,7 @@ public void testDisplayNameTooShort() { User user = generateValidUser(); user.setDisplayName("a"); - assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "displayName", 5, 30)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "displayName", 5, 30)); } @Test @@ -105,7 +105,7 @@ public void testDisplayNameTooLong() { User user = generateValidUser(); user.setDisplayName("1234567890123456789012345678901"); - assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "displayName", 5, 30)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "displayName", 5, 30)); } @Test @@ -137,7 +137,7 @@ public void testCompanyTooShort() { User user = generateValidUser(); user.setCompany("a"); - assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "company", 3, 30)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "company", 3, 30)); } @Test @@ -145,6 +145,6 @@ public void testCompanyTooLong() { User user = generateValidUser(); user.setCompany("1234567890123456789012345678901"); - assertInvalidUser(user, String.format(INVALID_LENGTH_BASIC, "company", 3, 30)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "company", 3, 30)); } } From a84a92f2e961f6b0f0969c89641a4c3dfe45610e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 16 Dec 2014 15:59:31 +0100 Subject: [PATCH 36/69] Test for Store Validator --- .../model/validators/StoreValidatorTest.java | 151 ++++++++++++++++++ .../model/validators/UserValidatorTest.java | 27 +++- 2 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java new file mode 100644 index 0000000..1f3af17 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java @@ -0,0 +1,151 @@ +package org.fiware.apps.marketplace.model.validators; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; + +import java.util.Date; + +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.model.User; +import org.junit.Test; + +public class StoreValidatorTest { + + private StoreValidator storeValidator = new StoreValidator(); + + private static final String MISSING_FIELDS = "name and/or url cannot be null"; + private static final String INVALID_LENGTH_PATTERN = "%s is not valid. (min length: %d, max length: %d)"; + private static final String INVALID_URL = "url is not valid"; + + private static Store generateValidStore() { + Store store = new Store(); + store.setCreator(new User()); + store.setDescription("This is a basic description"); + store.setLasteditor(store.getCreator()); + store.setName("store"); + store.setUrl("https://store.lab.fi-ware.org"); + store.setRegistrationDate(new Date()); + + return store; + } + + private void assertInvalidStore(Store store, String expectedMsg) { + try { + storeValidator.validateStore(store); + failBecauseExceptionWasNotThrown(ValidationException.class); + } catch (ValidationException ex) { + assertThat(ex).hasMessage(expectedMsg); + } + } + + @Test + public void testValidBasicStore() throws ValidationException { + Store store = new Store(); + store.setName("store"); + store.setUrl("https://store.lab.fi-ware.org"); + + assertThat(storeValidator.validateStore(store)).isTrue(); + } + + @Test + public void testValidComplexStore() throws ValidationException { + Store store = generateValidStore(); + assertThat(storeValidator.validateStore(store)).isTrue(); + } + + @Test + public void testMissingName() { + Store store = generateValidStore(); + store.setName(null); + + assertInvalidStore(store, MISSING_FIELDS); + } + + @Test + public void testMissingUrl() { + Store store = generateValidStore(); + store.setUrl(null); + + assertInvalidStore(store, MISSING_FIELDS); + } + + @Test + public void testMissingDescription() throws ValidationException { + Store store = generateValidStore(); + store.setDescription(null); + + assertThat(storeValidator.validateStore(store)).isTrue(); + } + + @Test + public void testNameTooShort() { + Store store = generateValidStore(); + store.setName("a"); + + assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15)); + } + + @Test + public void testUserNameTooLong() { + Store store = generateValidStore(); + store.setName("1234567890123456"); + + assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15)); + } + + @Test + public void testInvalidURL1() { + Store store = generateValidStore(); + store.setUrl("http://"); + + assertInvalidStore(store, INVALID_URL); + } + + @Test + public void testInvalidURL2() { + Store store = generateValidStore(); + store.setUrl("store.lab.fi-ware.org"); + + assertInvalidStore(store, INVALID_URL); + } + + @Test + public void testInvalidURL3() { + Store store = generateValidStore(); + store.setUrl("https://store.lab.fi-ware.org:222222"); + + assertInvalidStore(store, INVALID_URL); + } + + @Test + public void testInvalidURL4() { + Store store = generateValidStore(); + store.setUrl("store"); + + assertInvalidStore(store, INVALID_URL); + } + + @Test + public void testEmptyDescription() throws ValidationException { + Store store = generateValidStore(); + store.setDescription(""); + + // Empty descriptions are allowed + assertThat(storeValidator.validateStore(store)).isTrue(); + } + + @Test + public void testDescriptionTooLong() throws ValidationException { + Store store = generateValidStore(); + + //240 characters (80 * 3) + store.setDescription("12345678901234567890123456789012345678901234567890123456789012345678901234567890" + + "12345678901234567890123456789012345678901234567890123456789012345678901234567890" + + "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); + + // Empty descriptions are allowed + assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "description", 0, 200)); + } + +} diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java index 8b33cdc..1c29b25 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java @@ -12,8 +12,9 @@ public class UserValidatorTest { private static final String MISSING_FILEDS_MSG = "name, email and/or password cannot be null"; private static final String INVALID_LENGTH_PATTERN = "%s is not valid. (min length: %d, max length: %d)"; + private static final String INVALID_EMAIL = "email is not valid"; - private User generateValidUser() { + private static User generateValidUser() { User user = new User(); user.setUserName("userName"); user.setPassword("1234"); @@ -76,6 +77,24 @@ public void testMissingMail() { assertInvalidUser(user, MISSING_FILEDS_MSG); } + @Test + public void testMissingDisplayName() throws ValidationException { + User user = generateValidUser(); + user.setDisplayName(null); + + // Display name can be set to null + assertThat(userValidator.validateUser(user)).isTrue(); + } + + @Test + public void testMissingCompany() throws ValidationException { + User user = generateValidUser(); + user.setCompany(null); + + // Company name can be set to null + assertThat(userValidator.validateUser(user)).isTrue(); + } + @Test public void testUserNameTooShort() { User user = generateValidUser(); @@ -113,7 +132,7 @@ public void testInvalidMail1() { User user = generateValidUser(); user.setEmail("test"); - assertInvalidUser(user, "email is not valid"); + assertInvalidUser(user, INVALID_EMAIL); } @Test @@ -121,7 +140,7 @@ public void testInvalidMail2() { User user = generateValidUser(); user.setEmail("test@test"); - assertInvalidUser(user, "email is not valid"); + assertInvalidUser(user, INVALID_EMAIL); } @Test @@ -129,7 +148,7 @@ public void testInvalidMail3() { User user = generateValidUser(); user.setEmail("@test.com"); - assertInvalidUser(user, "email is not valid"); + assertInvalidUser(user, INVALID_EMAIL); } @Test From 4f75aa7232f6977837c100f44cf4bb606a7694fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 17 Dec 2014 10:08:25 +0100 Subject: [PATCH 37/69] Add tests for service validator --- .../validators/ServiceValidatorTest.java | 144 ++++++++++++++++++ .../model/validators/StoreValidatorTest.java | 1 - 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java new file mode 100644 index 0000000..f1641f1 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java @@ -0,0 +1,144 @@ +package org.fiware.apps.marketplace.model.validators; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; + +import java.util.Date; +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.fiware.apps.marketplace.model.Service; +import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.model.User; +import org.junit.Test; + +public class ServiceValidatorTest { + + private ServiceValidator serviceValidator = new ServiceValidator(); + + private static final String MISSING_FIELDS = "name and/or url cannot be null"; + private static final String INVALID_LENGTH_PATTERN = "%s is not valid. (min length: %d, max length: %d)"; + private static final String INVALID_URL = "url is not valid"; + + private static Service generateValidService() { + // Additional classes + User creator = new User(); + creator.setId(1); + + Service service = new Service(); + service.setName("service1"); + service.setUrl("https://repo.lab.fi-ware.org/services/service1.rdf"); + service.setDescription("This is an example description"); + service.setRegistrationDate(new Date()); + service.setStore(new Store()); + service.setCreator(creator); + service.setLasteditor(creator); + + return service; + } + + + private void assertInvalidService(Service service, String expectedMsg) { + try { + serviceValidator.validateService(service); + failBecauseExceptionWasNotThrown(ValidationException.class); + } catch (ValidationException ex) { + assertThat(ex).hasMessage(expectedMsg); + } + } + + @Test + public void testValidBasicService() throws ValidationException { + Service service = new Service(); + service.setName("service1"); + service.setUrl("https://repo.lab.fi-ware.org/services/service1.rdf"); + + assertThat(serviceValidator.validateService(service)).isTrue(); + } + + @Test + public void testValidComplexService() throws ValidationException { + Service service = generateValidService(); + assertThat(serviceValidator.validateService(service)).isTrue(); + } + + @Test + public void testMissingName() { + Service service = generateValidService(); + service.setName(null); + assertInvalidService(service, MISSING_FIELDS); + } + + @Test + public void testMissingUrl() { + Service service = generateValidService(); + service.setUrl(null); + assertInvalidService(service, MISSING_FIELDS); + } + + @Test + public void testNameTooShort() { + Service service = generateValidService(); + service.setName("a"); + assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15)); + } + + @Test + public void testNameTooLong() { + Service service = generateValidService(); + service.setName("1234567890123456"); + assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15)); + } + + @Test + public void testInvalidURL1() { + Service service = generateValidService(); + service.setUrl("http://"); + + assertInvalidService(service, INVALID_URL); + } + + @Test + public void testInvalidURL2() { + Service service = generateValidService(); + service.setUrl("repo.lab.fi-ware.org/services/service1.rdf"); + + assertInvalidService(service, INVALID_URL); + } + + @Test + public void testInvalidURL3() { + Service service = generateValidService(); + service.setUrl("https://repo.lab.fi-ware.org:222222/services/service1.rdf"); + + assertInvalidService(service, INVALID_URL); + } + + @Test + public void testInvalidURL4() { + Service service = generateValidService(); + service.setUrl("service"); + + assertInvalidService(service, INVALID_URL); + } + + @Test + public void testEmptyDescription() throws ValidationException { + Service service = generateValidService(); + service.setDescription(""); + + // Empty descriptions are allowed + assertThat(serviceValidator.validateService(service)).isTrue(); + } + + @Test + public void testDescriptionTooLong() throws ValidationException { + Service service = generateValidService(); + + //240 characters (80 * 3) + service.setDescription("12345678901234567890123456789012345678901234567890123456789012345678901234567890" + + "12345678901234567890123456789012345678901234567890123456789012345678901234567890" + + "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); + + // Empty descriptions are allowed + assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "description", 0, 200)); + } +} diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java index 1f3af17..164b871 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java @@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; import java.util.Date; - import org.fiware.apps.marketplace.exceptions.ValidationException; import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.model.User; From 843c522e344723c2e1cd4cc7cab9ffc1eba382fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 17 Dec 2014 10:23:30 +0100 Subject: [PATCH 38/69] Execute Auth tests when 'mvn test' is run --- .../auth/OfferingRegistrationAuthTest.java | 255 +++++++++--------- .../auth/StoreRegistrationAuthTest.java | 255 +++++++++--------- .../auth/UserRegistrationAuthTest.java | 234 ++++++++-------- 3 files changed, 370 insertions(+), 374 deletions(-) diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java index e403555..2622a24 100644 --- a/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java @@ -16,149 +16,148 @@ public class OfferingRegistrationAuthTest { - public static class OfferingAuthTest extends OfferingRegistrationAuthTest { - - @Mock private AuthUtils authUtils; - @InjectMocks private static OfferingRegistrationAuth authHelper; - - /////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////// BASIC METHODS //////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - private User createBasicUser(int id) { - User user = new User(); - user.setId(id); - return user; - } - - private Service setUpTestUpdateAndDelete(User creator, User updater) { - // Set up the test - Service service = new Service(); - service.setCreator(creator); - - try { - when(authUtils.getLoggedUser()).thenReturn(updater); - } catch (UserNotFoundException e) { - // never happens - } - - return service; - } - - - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST CREATE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - @Test - public void canCreateOffering() throws UserNotFoundException { - when(authUtils.getLoggedUser()).thenReturn(new User()); - assertThat(authHelper.canCreate()).isTrue(); - } - @Test - public void canNotCreateOffering() throws UserNotFoundException { - doThrow(new UserNotFoundException("")).when(authUtils).getLoggedUser(); - assertThat(authHelper.canCreate()).isFalse(); + @Mock private AuthUtils authUtils; + @InjectMocks private static OfferingRegistrationAuth authHelper; + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private User createBasicUser(int id) { + User user = new User(); + user.setId(id); + return user; + } + + private Service setUpTestUpdateAndDelete(User creator, User updater) { + // Set up the test + Service service = new Service(); + service.setCreator(creator); + + try { + when(authUtils.getLoggedUser()).thenReturn(updater); + } catch (UserNotFoundException e) { + // never happens } + return service; + } - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - private void testUpdate(User creator, User updater, boolean canUpdate) { - Service service = setUpTestUpdateAndDelete(creator, updater); + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } - // Execute the test - boolean result = authHelper.canUpdate(service); - // Check the result - assertThat(result).isEqualTo(canUpdate); + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST CREATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// - } + @Test + public void canCreateOffering() throws UserNotFoundException { + when(authUtils.getLoggedUser()).thenReturn(new User()); + assertThat(authHelper.canCreate()).isTrue(); + } - @Test - public void canUpdateOfferingSameUser() throws UserNotFoundException { - User creator = createBasicUser(1); - testUpdate(creator, creator, true); - } - - @Test - public void canUpdateOffering() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = createBasicUser(1); - testUpdate(creator, updater, true); - } + @Test + public void canNotCreateOffering() throws UserNotFoundException { + doThrow(new UserNotFoundException("")).when(authUtils).getLoggedUser(); + assertThat(authHelper.canCreate()).isFalse(); + } - @Test - public void canNotUpdateOfferingNotSameUser() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = createBasicUser(2); - testUpdate(creator, updater, false); - } - - @Test - public void canNotUpdateOfferingNotLoggedIn() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = null; - testUpdate(creator, updater, false); - } - - - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST DELETE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - private void testDelete(User creator, User updater, boolean canDelete) { - Service service = setUpTestUpdateAndDelete(creator, updater); - // Execute the test - boolean result = authHelper.canDelete(service); + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// - // Check the result - assertThat(result).isEqualTo(canDelete); + private void testUpdate(User creator, User updater, boolean canUpdate) { + Service service = setUpTestUpdateAndDelete(creator, updater); - } - - @Test - public void canDeleteOfferingSameUser() { - User creator = createBasicUser(1); - testDelete(creator, creator, true); - } - - @Test - public void canDeleteOffering() { - User creator = createBasicUser(1); - User updater = createBasicUser(1); - testDelete(creator, updater, true); - } + // Execute the test + boolean result = authHelper.canUpdate(service); - @Test - public void canNotDeleteOfferingNotSameUser() { - User creator = createBasicUser(1); - User updater = createBasicUser(2); - testDelete(creator, updater, false); - } - - @Test - public void canNotDeleteOfferingNotLoggedIn() { - User creator = createBasicUser(1); - User updater = null; - testDelete(creator, updater, false); - } + // Check the result + assertThat(result).isEqualTo(canUpdate); - - /////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////// TEST LIST ////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - @Test - public void canList() { - assertThat(authHelper.canList()).isTrue(); - } } - @Before - public void initMocks() { - MockitoAnnotations.initMocks(this); + @Test + public void canUpdateOfferingSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + testUpdate(creator, creator, true); + } + + @Test + public void canUpdateOffering() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testUpdate(creator, updater, true); + } + + @Test + public void canNotUpdateOfferingNotSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testUpdate(creator, updater, false); + } + + @Test + public void canNotUpdateOfferingNotLoggedIn() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = null; + testUpdate(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST DELETE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + private void testDelete(User creator, User updater, boolean canDelete) { + Service service = setUpTestUpdateAndDelete(creator, updater); + + // Execute the test + boolean result = authHelper.canDelete(service); + + // Check the result + assertThat(result).isEqualTo(canDelete); + + } + + @Test + public void canDeleteOfferingSameUser() { + User creator = createBasicUser(1); + testDelete(creator, creator, true); + } + + @Test + public void canDeleteOffering() { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testDelete(creator, updater, true); + } + + @Test + public void canNotDeleteOfferingNotSameUser() { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testDelete(creator, updater, false); } + + @Test + public void canNotDeleteOfferingNotLoggedIn() { + User creator = createBasicUser(1); + User updater = null; + testDelete(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////// TEST LIST ////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + @Test + public void canList() { + assertThat(authHelper.canList()).isTrue(); + } + } diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java index 8b0abaa..dffed85 100644 --- a/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java @@ -16,149 +16,148 @@ public class StoreRegistrationAuthTest { - public static class StoreAuthTest extends StoreRegistrationAuthTest { - - @Mock private AuthUtils authUtils; - @InjectMocks private static StoreRegistrationAuth authHelper; - - /////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////// BASIC METHODS //////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - private User createBasicUser(int id) { - User user = new User(); - user.setId(id); - return user; - } - - private Store setUpTestUpdateAndDelete(User creator, User updater) { - // Set up the test - Store store = new Store(); - store.setCreator(creator); - - try { - when(authUtils.getLoggedUser()).thenReturn(updater); - } catch (UserNotFoundException e) { - // never happens - } - - return store; - } - - - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST CREATE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - @Test - public void canCreateStore() throws UserNotFoundException { - when(authUtils.getLoggedUser()).thenReturn(new User()); - assertThat(authHelper.canCreate()).isTrue(); - } - @Test - public void canNotCreateStore() throws UserNotFoundException { - doThrow(new UserNotFoundException("")).when(authUtils).getLoggedUser(); - assertThat(authHelper.canCreate()).isFalse(); + @Mock private AuthUtils authUtils; + @InjectMocks private static StoreRegistrationAuth authHelper; + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private User createBasicUser(int id) { + User user = new User(); + user.setId(id); + return user; + } + + private Store setUpTestUpdateAndDelete(User creator, User updater) { + // Set up the test + Store store = new Store(); + store.setCreator(creator); + + try { + when(authUtils.getLoggedUser()).thenReturn(updater); + } catch (UserNotFoundException e) { + // never happens } + return store; + } - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - private void testUpdate(User creator, User updater, boolean canUpdate) { - Store store = setUpTestUpdateAndDelete(creator, updater); + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } - // Execute the test - boolean result = authHelper.canUpdate(store); - // Check the result - assertThat(result).isEqualTo(canUpdate); + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST CREATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// - } + @Test + public void canCreateStore() throws UserNotFoundException { + when(authUtils.getLoggedUser()).thenReturn(new User()); + assertThat(authHelper.canCreate()).isTrue(); + } - @Test - public void canUpdateStoreSameUser() throws UserNotFoundException { - User creator = createBasicUser(1); - testUpdate(creator, creator, true); - } - - @Test - public void canUpdateStore() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = createBasicUser(1); - testUpdate(creator, updater, true); - } + @Test + public void canNotCreateStore() throws UserNotFoundException { + doThrow(new UserNotFoundException("")).when(authUtils).getLoggedUser(); + assertThat(authHelper.canCreate()).isFalse(); + } - @Test - public void canNotUpdateStoreNotSameUser() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = createBasicUser(2); - testUpdate(creator, updater, false); - } - - @Test - public void canNotUpdateStoreNotLoggedIn() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = null; - testUpdate(creator, updater, false); - } - - - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST DELETE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - private void testDelete(User creator, User updater, boolean canDelete) { - Store store = setUpTestUpdateAndDelete(creator, updater); - // Execute the test - boolean result = authHelper.canDelete(store); + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// - // Check the result - assertThat(result).isEqualTo(canDelete); + private void testUpdate(User creator, User updater, boolean canUpdate) { + Store store = setUpTestUpdateAndDelete(creator, updater); - } - - @Test - public void canDeleteStoreSameUser() { - User creator = createBasicUser(1); - testDelete(creator, creator, true); - } - - @Test - public void canDeleteStore() { - User creator = createBasicUser(1); - User updater = createBasicUser(1); - testDelete(creator, updater, true); - } + // Execute the test + boolean result = authHelper.canUpdate(store); - @Test - public void canNotDeleteStoreNotSameUser() { - User creator = createBasicUser(1); - User updater = createBasicUser(2); - testDelete(creator, updater, false); - } - - @Test - public void canNotDeleteStoreNotLoggedIn() { - User creator = createBasicUser(1); - User updater = null; - testDelete(creator, updater, false); - } + // Check the result + assertThat(result).isEqualTo(canUpdate); - - /////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////// TEST LIST ////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - @Test - public void canList() { - assertThat(authHelper.canList()).isTrue(); - } } - @Before - public void initMocks() { - MockitoAnnotations.initMocks(this); + @Test + public void canUpdateStoreSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + testUpdate(creator, creator, true); + } + + @Test + public void canUpdateStore() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testUpdate(creator, updater, true); + } + + @Test + public void canNotUpdateStoreNotSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testUpdate(creator, updater, false); + } + + @Test + public void canNotUpdateStoreNotLoggedIn() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = null; + testUpdate(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST DELETE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + private void testDelete(User creator, User updater, boolean canDelete) { + Store store = setUpTestUpdateAndDelete(creator, updater); + + // Execute the test + boolean result = authHelper.canDelete(store); + + // Check the result + assertThat(result).isEqualTo(canDelete); + + } + + @Test + public void canDeleteStoreSameUser() { + User creator = createBasicUser(1); + testDelete(creator, creator, true); + } + + @Test + public void canDeleteStore() { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testDelete(creator, updater, true); + } + + @Test + public void canNotDeleteStoreNotSameUser() { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testDelete(creator, updater, false); } + + @Test + public void canNotDeleteStoreNotLoggedIn() { + User creator = createBasicUser(1); + User updater = null; + testDelete(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////// TEST LIST ////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + @Test + public void canList() { + assertThat(authHelper.canList()).isTrue(); + } + } diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java index f03db40..a384f8d 100644 --- a/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java @@ -15,136 +15,134 @@ public class UserRegistrationAuthTest { - public static class UserAuthTest extends UserRegistrationAuthTest { - - @Mock private AuthUtils authUtils; - @InjectMocks private static UserRegistrationAuth authHelper; - - /////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////// BASIC METHODS //////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - private User createBasicUser(int id) { - User user = new User(); - user.setId(id); - return user; - } - - - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST CREATE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - @Test - public void canCreateUser() throws UserNotFoundException { - assertThat(authHelper.canCreate()).isTrue(); - } + @Mock private AuthUtils authUtils; + @InjectMocks private static UserRegistrationAuth authHelper; - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - - private void testUpdate(User creator, User updater, boolean canUpdate) { - try { - when(authUtils.getLoggedUser()).thenReturn(updater); - } catch (UserNotFoundException e) { - // Nothing to do... - } - - // Execute the test - boolean result = authHelper.canUpdate(creator); + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// - // Check the result - assertThat(result).isEqualTo(canUpdate); + private User createBasicUser(int id) { + User user = new User(); + user.setId(id); + return user; + } + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } - } - @Test - public void canUpdateUserSameUser() throws UserNotFoundException { - User creator = createBasicUser(1); - testUpdate(creator, creator, true); - } - - @Test - public void canUpdateUser() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = createBasicUser(1); - testUpdate(creator, updater, true); - } + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST CREATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// - @Test - public void canNotUpdateUserNotSameUser() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = createBasicUser(2); - testUpdate(creator, updater, false); - } - - @Test - public void canNotUpdateUserNotLoggedIn() throws UserNotFoundException { - User creator = createBasicUser(1); - User updater = null; - testUpdate(creator, updater, false); - } - - - /////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// TEST DELETE ///////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - private void testDelete(User creator, User updater, boolean canDelete) { - try { - when(authUtils.getLoggedUser()).thenReturn(updater); - } catch (UserNotFoundException e) { - // Nothing to do... - } - - // Execute the test - boolean result = authHelper.canDelete(creator); - - // Check the result - assertThat(result).isEqualTo(canDelete); + @Test + public void canCreateUser() throws UserNotFoundException { + assertThat(authHelper.canCreate()).isTrue(); + } - } - - @Test - public void canDeleteUserSameUser() { - User creator = createBasicUser(1); - testDelete(creator, creator, true); - } - - @Test - public void canDeleteUser() { - User creator = createBasicUser(1); - User updater = createBasicUser(1); - testDelete(creator, updater, true); - } - @Test - public void canNotDeleteUserNotSameUser() { - User creator = createBasicUser(1); - User updater = createBasicUser(2); - testDelete(creator, updater, false); - } - - @Test - public void canNotDeleteUserNotLoggedIn() { - User creator = createBasicUser(1); - User updater = null; - testDelete(creator, updater, false); + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST UPDATE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private void testUpdate(User creator, User updater, boolean canUpdate) { + try { + when(authUtils.getLoggedUser()).thenReturn(updater); + } catch (UserNotFoundException e) { + // Nothing to do... } - - /////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////// TEST LIST ////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////// - @Test - public void canList() { - assertThat(authHelper.canList()).isTrue(); + // Execute the test + boolean result = authHelper.canUpdate(creator); + + // Check the result + assertThat(result).isEqualTo(canUpdate); + + } + + @Test + public void canUpdateUserSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + testUpdate(creator, creator, true); + } + + @Test + public void canUpdateUser() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testUpdate(creator, updater, true); + } + + @Test + public void canNotUpdateUserNotSameUser() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testUpdate(creator, updater, false); + } + + @Test + public void canNotUpdateUserNotLoggedIn() throws UserNotFoundException { + User creator = createBasicUser(1); + User updater = null; + testUpdate(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// TEST DELETE ///////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + private void testDelete(User creator, User updater, boolean canDelete) { + try { + when(authUtils.getLoggedUser()).thenReturn(updater); + } catch (UserNotFoundException e) { + // Nothing to do... } + + // Execute the test + boolean result = authHelper.canDelete(creator); + + // Check the result + assertThat(result).isEqualTo(canDelete); + } - @Before - public void initMocks() { - MockitoAnnotations.initMocks(this); + @Test + public void canDeleteUserSameUser() { + User creator = createBasicUser(1); + testDelete(creator, creator, true); + } + + @Test + public void canDeleteUser() { + User creator = createBasicUser(1); + User updater = createBasicUser(1); + testDelete(creator, updater, true); + } + + @Test + public void canNotDeleteUserNotSameUser() { + User creator = createBasicUser(1); + User updater = createBasicUser(2); + testDelete(creator, updater, false); + } + + @Test + public void canNotDeleteUserNotLoggedIn() { + User creator = createBasicUser(1); + User updater = null; + testDelete(creator, updater, false); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////// TEST LIST ////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + @Test + public void canList() { + assertThat(authHelper.canList()).isTrue(); } } From b147deb8a1605e8df03b9558abbe9885d6fd6109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 17 Dec 2014 17:01:56 +0100 Subject: [PATCH 39/69] Enable @AutoWired in RestEasy --- pom.xml | 4 +++- .../fiware/apps/marketplace/model/Service.java | 3 +++ .../fiware/apps/marketplace/model/Services.java | 2 ++ .../fiware/apps/marketplace/model/Store.java | 3 +++ .../fiware/apps/marketplace/model/Stores.java | 2 ++ .../org/fiware/apps/marketplace/model/User.java | 2 ++ .../fiware/apps/marketplace/model/Users.java | 2 ++ .../rest/OfferingRegistrationService.java | 17 ++++++++--------- .../rest/StoreRegistrationService.java | 15 ++++++--------- .../rest/UserRegistrationService.java | 13 ++++++------- src/main/webapp/WEB-INF/web.xml | 16 +++++++--------- 11 files changed, 44 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index 5309acd..7b5f4ae 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ 20090617 + junit junit @@ -105,10 +106,11 @@ org.jboss.resteasy - resteasy-oauth + resteasy-spring 3.0.10.Final + org.apache.httpcomponents diff --git a/src/main/java/org/fiware/apps/marketplace/model/Service.java b/src/main/java/org/fiware/apps/marketplace/model/Service.java index 7233d78..b67a836 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Service.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Service.java @@ -18,9 +18,12 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; + @Entity @Table(name = "Services", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "store", "url" }) }) // each service name has to unique for a store context @XmlRootElement(name = "resource") +@IgnoreMediaTypes("application/*+json") public class Service { private Integer id; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Services.java b/src/main/java/org/fiware/apps/marketplace/model/Services.java index ce522a5..0c87e65 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Services.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Services.java @@ -7,8 +7,10 @@ import javax.xml.bind.annotation.XmlRootElement; import org.codehaus.jackson.annotate.JsonProperty; +import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; @XmlRootElement(name = "services") +@IgnoreMediaTypes("application/*+json") public class Services { private List services = null; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Store.java b/src/main/java/org/fiware/apps/marketplace/model/Store.java index cc3bfda..7073c8b 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Store.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Store.java @@ -21,10 +21,13 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; + @Entity @Table(name = "Stores") @XmlRootElement(name = "store") +@IgnoreMediaTypes("application/*+json") public class Store { private Integer id; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Stores.java b/src/main/java/org/fiware/apps/marketplace/model/Stores.java index dd79073..cbaa5a3 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Stores.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Stores.java @@ -7,8 +7,10 @@ import javax.xml.bind.annotation.XmlRootElement; import org.codehaus.jackson.annotate.JsonProperty; +import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; @XmlRootElement(name = "stores") +@IgnoreMediaTypes("application/*+json") public class Stores { private List stores = null; diff --git a/src/main/java/org/fiware/apps/marketplace/model/User.java b/src/main/java/org/fiware/apps/marketplace/model/User.java index 5d7c8c1..4c1dcc9 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/User.java +++ b/src/main/java/org/fiware/apps/marketplace/model/User.java @@ -18,10 +18,12 @@ import org.fiware.apps.marketplace.utils.xmladapters.HiddenFieldsXMLAdapter; import org.fiware.apps.marketplace.utils.xmladapters.PasswordXMLAdapter; +import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; @Entity @Table(name = "Users") @XmlRootElement(name = "user") +@IgnoreMediaTypes("application/*+json") public class User { private Integer id; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Users.java b/src/main/java/org/fiware/apps/marketplace/model/Users.java index bda75bb..332ef5b 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Users.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Users.java @@ -7,8 +7,10 @@ import javax.xml.bind.annotation.XmlRootElement; import org.codehaus.jackson.annotate.JsonProperty; +import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; @XmlRootElement(name = "users") +@IgnoreMediaTypes("application/*+json") public class Users { private List users = null; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index b3d7c2e..7d81dff 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -29,21 +29,20 @@ import org.fiware.apps.marketplace.model.validators.ServiceValidator; import org.fiware.apps.marketplace.security.auth.AuthUtils; import org.fiware.apps.marketplace.security.auth.OfferingRegistrationAuth; -import org.fiware.apps.marketplace.utils.ApplicationContextProvider; -import org.springframework.context.ApplicationContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Component; +@Component @Path("/store/{storeName}/offering") public class OfferingRegistrationService { // OBJECT ATTRIBUTES // - private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); - private StoreBo storeBo = (StoreBo) context.getBean("storeBo"); - private ServiceBo serviceBo = (ServiceBo) context.getBean("serviceBo"); - private OfferingRegistrationAuth offeringRegistrationAuth = (OfferingRegistrationAuth) - context.getBean("offeringRegistrationAuth"); - private ServiceValidator serviceValidator = (ServiceValidator) context.getBean("serviceValidator"); - private AuthUtils authUtils = (AuthUtils) context.getBean("authUtils"); + @Autowired private StoreBo storeBo; + @Autowired private ServiceBo serviceBo; + @Autowired private OfferingRegistrationAuth offeringRegistrationAuth; + @Autowired private ServiceValidator serviceValidator; + @Autowired private AuthUtils authUtils; // CLASS ATTRIBUTES // private static final ErrorUtils ERROR_UTILS = new ErrorUtils( diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 749b429..958b6db 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -26,24 +26,21 @@ import org.fiware.apps.marketplace.model.validators.StoreValidator; import org.fiware.apps.marketplace.security.auth.AuthUtils; import org.fiware.apps.marketplace.security.auth.StoreRegistrationAuth; -import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Component; - +@Component @Path("/store") public class StoreRegistrationService { // OBJECT ATTRIBUTES // - private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); - private StoreBo storeBo = (StoreBo) context.getBean("storeBo"); - private StoreRegistrationAuth storeRegistrationAuth = (StoreRegistrationAuth) context.getBean("storeRegistrationAuth"); - private StoreValidator storeValidator = (StoreValidator) context.getBean("storeValidator"); - private AuthUtils authUtils = (AuthUtils) context.getBean("authUtils"); + @Autowired private StoreBo storeBo; + @Autowired private StoreRegistrationAuth storeRegistrationAuth; + @Autowired private StoreValidator storeValidator; + @Autowired private AuthUtils authUtils; // CLASS ATTRIBUTES // - @Autowired private static final ErrorUtils ERROR_UTILS = new ErrorUtils( "There is already a Store with that name/URL registered in the system"); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index e252422..1964f80 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -23,19 +23,18 @@ import org.fiware.apps.marketplace.model.Users; import org.fiware.apps.marketplace.model.validators.UserValidator; import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; -import org.fiware.apps.marketplace.utils.ApplicationContextProvider; -import org.springframework.context.ApplicationContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Component; - +@Component @Path("/user") public class UserRegistrationService { // OBJECT ATTRIBUTES // - private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); - private UserBo userBo = (UserBo) context.getBean("userBo"); - private UserRegistrationAuth userRegistrationAuth = (UserRegistrationAuth) context.getBean("userRegistrationAuth"); - private UserValidator userValidator = (UserValidator) context.getBean("userValidator"); + @Autowired private UserBo userBo; + @Autowired private UserRegistrationAuth userRegistrationAuth; + @Autowired private UserValidator userValidator; // CLASS ATTRIBUTES // private static final ErrorUtils ERROR_UTILS = new ErrorUtils( diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 4d37e9e..f119502 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -35,16 +35,17 @@ - - org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap - + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap - + + + org.jboss.resteasy.plugins.spring.SpringContextLoaderListener + + resteasy-servlet - org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher - + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher @@ -60,9 +61,6 @@ - - org.springframework.web.context.ContextLoaderListener - \ No newline at end of file From df04fe50fb5fced9d5d90f0c4a18461698b820ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 17 Dec 2014 17:17:42 +0100 Subject: [PATCH 40/69] Improve code readibility --- .../marketplace/rest/OfferingRegistrationService.java | 11 ++++++++--- .../marketplace/rest/StoreRegistrationService.java | 10 ++++++++-- .../marketplace/rest/UserRegistrationService.java | 10 +++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index 7d81dff..14cef6e 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -55,7 +55,10 @@ public Response saveService(@PathParam("storeName") String storeName, Service se Response response; try { - if (offeringRegistrationAuth.canCreate() && serviceValidator.validateService(service)) { + if (offeringRegistrationAuth.canCreate()) { + + // Validate service (exception is thrown if the service is not valid) + serviceValidator.validateService(service); User user = authUtils.getLoggedUser(); Store store = storeBo.findByName(storeName); @@ -101,8 +104,10 @@ public Response updateService(@PathParam("storeName") String storeName, Store store = storeBo.findByName(storeName); //Check that the Store exists Service service = serviceBo.findByNameAndStore(serviceName, storeName); - if (offeringRegistrationAuth.canUpdate(service) - && serviceValidator.validateService(serviceInfo)) { + if (offeringRegistrationAuth.canUpdate(service)) { + + // Validate service (exception is thrown if the service is not valid) + serviceValidator.validateService(serviceInfo); if (serviceInfo.getName() != null) { service.setName(serviceInfo.getName()); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 958b6db..1654a56 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -52,7 +52,10 @@ public Response createStore(Store store) { Response response; try { - if (storeRegistrationAuth.canCreate() && storeValidator.validateStore(store)) { + if (storeRegistrationAuth.canCreate()) { + //Validate the Store (exception is thrown if the Store is not valid) + storeValidator.validateStore(store); + // Get the current user User currentUser = authUtils.getLoggedUser(); @@ -88,7 +91,10 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor try { Store storeDB = storeBo.findByName(storeName); - if (storeRegistrationAuth.canUpdate(storeDB) && storeValidator.validateStore(store)) { + if (storeRegistrationAuth.canUpdate(storeDB)) { + //Validate the Store (exception is thrown if the Store is not valid) + storeValidator.validateStore(store); + if (store.getName() != null) { storeDB.setName(store.getName()); } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 1964f80..d224869 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -48,7 +48,10 @@ public Response createUser(User user) { Response response; try { - if (userRegistrationAuth.canCreate() && userValidator.validateUser(user)) { + if (userRegistrationAuth.canCreate()) { + // Validate the user (exception is thrown if the user is not valid) + userValidator.validateUser(user); + user.setRegistrationDate(new Date()); userBo.save(user); response = Response.status(Status.CREATED).build(); @@ -76,8 +79,9 @@ public Response updateUser(@PathParam("username") String username, User user) { try { User userToBeUpdated = userBo.findByName(username); - if (userRegistrationAuth.canUpdate(userToBeUpdated) - && userValidator.validateUser(user)) { + if (userRegistrationAuth.canUpdate(userToBeUpdated)) { + // Validate the user (exception is thrown when the user is not valid) + userValidator.validateUser(user); // At this moment, user name cannot be changed to avoid error with sessions... // userToBeUpdated.setUserName(user.getUserName()); From 3a93232ce225afb58232b15328abfe1f2941bd89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 18 Dec 2014 11:09:45 +0100 Subject: [PATCH 41/69] Check passwords. Allow users to modify resources without setting the basic fields. --- .../apps/marketplace/model/Service.java | 2 +- .../fiware/apps/marketplace/model/User.java | 3 +- .../model/validators/ServiceValidator.java | 25 +++--- .../model/validators/StoreValidator.java | 10 ++- .../model/validators/UserValidator.java | 20 +++-- .../rest/OfferingRegistrationService.java | 4 +- .../rest/StoreRegistrationService.java | 4 +- .../rest/UserRegistrationService.java | 12 ++- .../utils/xmladapters/PasswordXMLAdapter.java | 17 ---- .../validators/ServiceValidatorTest.java | 62 +++++++++---- .../model/validators/StoreValidatorTest.java | 60 +++++++++---- .../model/validators/UserValidatorTest.java | 89 ++++++++++++++----- 12 files changed, 206 insertions(+), 102 deletions(-) delete mode 100644 src/main/java/org/fiware/apps/marketplace/utils/xmladapters/PasswordXMLAdapter.java diff --git a/src/main/java/org/fiware/apps/marketplace/model/Service.java b/src/main/java/org/fiware/apps/marketplace/model/Service.java index b67a836..1adc636 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Service.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Service.java @@ -22,7 +22,7 @@ @Entity @Table(name = "Services", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "store", "url" }) }) // each service name has to unique for a store context -@XmlRootElement(name = "resource") +@XmlRootElement(name = "service") @IgnoreMediaTypes("application/*+json") public class Service { diff --git a/src/main/java/org/fiware/apps/marketplace/model/User.java b/src/main/java/org/fiware/apps/marketplace/model/User.java index 4c1dcc9..5a39416 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/User.java +++ b/src/main/java/org/fiware/apps/marketplace/model/User.java @@ -17,7 +17,6 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.fiware.apps.marketplace.utils.xmladapters.HiddenFieldsXMLAdapter; -import org.fiware.apps.marketplace.utils.xmladapters.PasswordXMLAdapter; import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; @Entity @@ -82,7 +81,7 @@ public void setEmail(String email) { @XmlElement // Avoid returning the password in the API // Encrypt the password received through the API - @XmlJavaTypeAdapter(PasswordXMLAdapter.class) + @XmlJavaTypeAdapter(HiddenFieldsXMLAdapter.class) @Column(name = "password", nullable = false) public String getPassword() { return password; diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java index 5baae4f..ea281db 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java @@ -5,38 +5,43 @@ @Service("serviceValidator") public class ServiceValidator { - + private static final GenericValidator GENERIC_VALIDATOR = GenericValidator.getInstance(); - + /** * @param service Service to be checked + * @param isBeingCreated true if the user is being created. In this case, the system will check if + * the basic fields (name, url) are included. * @return True if the service is valid. Otherwise ValidationException will be thrown * @throws ValidationException If service is not valid */ - public boolean validateService(org.fiware.apps.marketplace.model.Service service) throws ValidationException { - - if (service.getName() == null || service.getUrl() == null) { - throw new ValidationException("name and/or url cannot be null"); + public boolean validateService(org.fiware.apps.marketplace.model.Service service, + boolean isBeingCreated) throws ValidationException { + + if (isBeingCreated) { + if (service.getName() == null || service.getUrl() == null) { + throw new ValidationException("name and/or url cannot be null"); + } } - + if (service.getName() != null && !GENERIC_VALIDATOR.validateName(service.getName())) { int minNameLength = GenericValidator.getNameMinLength(); int maxNameLength = GenericValidator.getNameMaxLength(); throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("name", minNameLength, maxNameLength)); } - + if (service.getUrl() != null && !GENERIC_VALIDATOR.validateURL(service.getUrl())) { throw new ValidationException("url is not valid"); } - + if (service.getDescription() != null && !GENERIC_VALIDATOR.validateDescription(service.getDescription())) { int minDescriptionLength = GenericValidator.getDescriptionMinLength(); int maxDescriptionLength = GenericValidator.getDescriptionMaxLength(); throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("description", minDescriptionLength, maxDescriptionLength)); } - + return true; } diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java index 391b18c..ee7d6b4 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java @@ -11,13 +11,17 @@ public class StoreValidator { /** * @param store Store to be checked + * @param isBeingCreated true if the user is being created. In this case, the system will check if + * the basic fields (name, url) are included. * @return True if the store is valid. Otherwise ValidationException will be thrown * @throws ValidationException If store is not valid */ - public boolean validateStore(Store store) throws ValidationException { + public boolean validateStore(Store store, boolean isBeingCreated) throws ValidationException { - if (store.getName() == null || store.getUrl() == null) { - throw new ValidationException("name and/or url cannot be null"); + if (isBeingCreated) { + if (store.getName() == null || store.getUrl() == null) { + throw new ValidationException("name and/or url cannot be null"); + } } if (store.getName() != null && !GENERIC_VALIDATOR.validateName(store.getName())) { diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java index cedf734..70d3352 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java @@ -10,8 +10,8 @@ public class UserValidator { private static final int COMPANY_MIN_LENGTH = 3; //For example: UPM, TID, SAP, ENG,... private static final int COMPANY_MAX_LENGTH = 30; //Just for the future... - //private static final int PASSWORD_MIN_LENGTH = 5; - //private static final int PASSWORD_MAX_LENGTH = 30; + private static final int PASSWORD_MIN_LENGTH = 8; + private static final int PASSWORD_MAX_LENGTH = 30; private static final int DISPLAY_NAME_MIN_LENGTH = 5; private static final int DISPLAY_NAME_MAX_LENGTH = 30; @@ -19,13 +19,17 @@ public class UserValidator { /** * @param user User to be checked + * @param isBeingCreated true if the user is being created. In this case, the system will check if + * the basic fields (name, mail, pass) are included. * @return True if the user is valid. Otherwise ValidationException will be thrown * @throws ValidationException If user is not valid */ - public boolean validateUser(User user) throws ValidationException { + public boolean validateUser(User user, boolean isBeingCreated) throws ValidationException { - if (user.getUserName() == null || user.getEmail() == null || user.getPassword() == null) { - throw new ValidationException("name, email and/or password cannot be null"); + if (isBeingCreated) { + if (user.getUserName() == null || user.getEmail() == null || user.getPassword() == null) { + throw new ValidationException("name, email and/or password cannot be null"); + } } if (user.getUserName() != null && !GENERIC_VALIDATOR.validateName(user.getUserName())) { @@ -41,6 +45,12 @@ public boolean validateUser(User user) throws ValidationException { DISPLAY_NAME_MIN_LENGTH, DISPLAY_NAME_MAX_LENGTH)); } + if (user.getPassword() != null && !GENERIC_VALIDATOR.validateLength(user.getPassword(), + PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH)) { + throw new ValidationException(GENERIC_VALIDATOR.getLengthErrorMessage("password", + PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH)); + } + if (user.getEmail() != null && !GENERIC_VALIDATOR.validateEMail(user.getEmail())) { throw new ValidationException("email is not valid"); } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index 14cef6e..bb7385d 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -58,7 +58,7 @@ public Response saveService(@PathParam("storeName") String storeName, Service se if (offeringRegistrationAuth.canCreate()) { // Validate service (exception is thrown if the service is not valid) - serviceValidator.validateService(service); + serviceValidator.validateService(service, true); User user = authUtils.getLoggedUser(); Store store = storeBo.findByName(storeName); @@ -107,7 +107,7 @@ public Response updateService(@PathParam("storeName") String storeName, if (offeringRegistrationAuth.canUpdate(service)) { // Validate service (exception is thrown if the service is not valid) - serviceValidator.validateService(serviceInfo); + serviceValidator.validateService(serviceInfo, false); if (serviceInfo.getName() != null) { service.setName(serviceInfo.getName()); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 1654a56..f03b655 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -54,7 +54,7 @@ public Response createStore(Store store) { try { if (storeRegistrationAuth.canCreate()) { //Validate the Store (exception is thrown if the Store is not valid) - storeValidator.validateStore(store); + storeValidator.validateStore(store, true); // Get the current user User currentUser = authUtils.getLoggedUser(); @@ -93,7 +93,7 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor Store storeDB = storeBo.findByName(storeName); if (storeRegistrationAuth.canUpdate(storeDB)) { //Validate the Store (exception is thrown if the Store is not valid) - storeValidator.validateStore(store); + storeValidator.validateStore(store, false); if (store.getName() != null) { storeDB.setName(store.getName()); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index d224869..6a9d4da 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -25,6 +25,7 @@ import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; @Component @@ -35,6 +36,8 @@ public class UserRegistrationService { @Autowired private UserBo userBo; @Autowired private UserRegistrationAuth userRegistrationAuth; @Autowired private UserValidator userValidator; + // Encoder must be the same in all the platform: use the bean + @Autowired private PasswordEncoder enconder; // CLASS ATTRIBUTES // private static final ErrorUtils ERROR_UTILS = new ErrorUtils( @@ -50,9 +53,12 @@ public Response createUser(User user) { try { if (userRegistrationAuth.canCreate()) { // Validate the user (exception is thrown if the user is not valid) - userValidator.validateUser(user); + userValidator.validateUser(user, true); + // Encode password. Set registration date... + user.setPassword(enconder.encode(user.getPassword())); user.setRegistrationDate(new Date()); + userBo.save(user); response = Response.status(Status.CREATED).build(); } else { @@ -81,7 +87,7 @@ public Response updateUser(@PathParam("username") String username, User user) { if (userRegistrationAuth.canUpdate(userToBeUpdated)) { // Validate the user (exception is thrown when the user is not valid) - userValidator.validateUser(user); + userValidator.validateUser(user, false); // At this moment, user name cannot be changed to avoid error with sessions... // userToBeUpdated.setUserName(user.getUserName()); @@ -94,7 +100,7 @@ public Response updateUser(@PathParam("username") String username, User user) { } if (user.getPassword() != null) { - userToBeUpdated.setPassword(user.getPassword()); + userToBeUpdated.setPassword(enconder.encode(user.getPassword())); } if (user.getEmail() != null) { diff --git a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/PasswordXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/PasswordXMLAdapter.java deleted file mode 100644 index 92ced12..0000000 --- a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/PasswordXMLAdapter.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.fiware.apps.marketplace.utils.xmladapters; - -import org.fiware.apps.marketplace.utils.ApplicationContextProvider; -import org.springframework.security.crypto.password.PasswordEncoder; - -public class PasswordXMLAdapter extends HiddenFieldsXMLAdapter{ - - // Encoder must be the same in all the platform: use the bean - private static final PasswordEncoder ENCODER = (PasswordEncoder) - ApplicationContextProvider.getApplicationContext().getBean("encoder"); - - @Override - public String unmarshal(String password) throws Exception { - return ENCODER.encode(password); - } - -} diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java index f1641f1..df34dbf 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java @@ -36,9 +36,9 @@ private static Service generateValidService() { } - private void assertInvalidService(Service service, String expectedMsg) { + private void assertInvalidService(Service service, String expectedMsg, boolean creating) { try { - serviceValidator.validateService(service); + serviceValidator.validateService(service, creating); failBecauseExceptionWasNotThrown(ValidationException.class); } catch (ValidationException ex) { assertThat(ex).hasMessage(expectedMsg); @@ -51,41 +51,71 @@ public void testValidBasicService() throws ValidationException { service.setName("service1"); service.setUrl("https://repo.lab.fi-ware.org/services/service1.rdf"); - assertThat(serviceValidator.validateService(service)).isTrue(); + assertThat(serviceValidator.validateService(service, true)).isTrue(); } @Test public void testValidComplexService() throws ValidationException { Service service = generateValidService(); - assertThat(serviceValidator.validateService(service)).isTrue(); + assertThat(serviceValidator.validateService(service, true)).isTrue(); } @Test - public void testMissingName() { + public void testMissingNameOnCreation() { Service service = generateValidService(); service.setName(null); - assertInvalidService(service, MISSING_FIELDS); + assertInvalidService(service, MISSING_FIELDS, true); } @Test - public void testMissingUrl() { + public void testMissingNameOnUpdate() throws ValidationException { + Service service = generateValidService(); + service.setName(null); + assertThat(serviceValidator.validateService(service, false)).isTrue(); + } + + @Test + public void testMissingUrlOnCreation() { + Service service = generateValidService(); + service.setUrl(null); + assertInvalidService(service, MISSING_FIELDS, true); + } + + @Test + public void testMissingUrlOnUpdate() throws ValidationException { Service service = generateValidService(); service.setUrl(null); - assertInvalidService(service, MISSING_FIELDS); + assertThat(serviceValidator.validateService(service, false)).isTrue(); + } + + @Test + public void testMissingDescriptionOnCreation() throws ValidationException { + Service service = generateValidService(); + service.setDescription(null); + + assertThat(serviceValidator.validateService(service, true)).isTrue(); + } + + @Test + public void testMissingDescriptionOnUpdate() throws ValidationException { + Service service = generateValidService(); + service.setDescription(null); + + assertThat(serviceValidator.validateService(service, false)).isTrue(); } @Test public void testNameTooShort() { Service service = generateValidService(); service.setName("a"); - assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15)); + assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15), false); } @Test public void testNameTooLong() { Service service = generateValidService(); service.setName("1234567890123456"); - assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15)); + assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15), false); } @Test @@ -93,7 +123,7 @@ public void testInvalidURL1() { Service service = generateValidService(); service.setUrl("http://"); - assertInvalidService(service, INVALID_URL); + assertInvalidService(service, INVALID_URL, false); } @Test @@ -101,7 +131,7 @@ public void testInvalidURL2() { Service service = generateValidService(); service.setUrl("repo.lab.fi-ware.org/services/service1.rdf"); - assertInvalidService(service, INVALID_URL); + assertInvalidService(service, INVALID_URL, false); } @Test @@ -109,7 +139,7 @@ public void testInvalidURL3() { Service service = generateValidService(); service.setUrl("https://repo.lab.fi-ware.org:222222/services/service1.rdf"); - assertInvalidService(service, INVALID_URL); + assertInvalidService(service, INVALID_URL, false); } @Test @@ -117,7 +147,7 @@ public void testInvalidURL4() { Service service = generateValidService(); service.setUrl("service"); - assertInvalidService(service, INVALID_URL); + assertInvalidService(service, INVALID_URL, false); } @Test @@ -126,7 +156,7 @@ public void testEmptyDescription() throws ValidationException { service.setDescription(""); // Empty descriptions are allowed - assertThat(serviceValidator.validateService(service)).isTrue(); + assertThat(serviceValidator.validateService(service, false)).isTrue(); } @Test @@ -139,6 +169,6 @@ public void testDescriptionTooLong() throws ValidationException { "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); // Empty descriptions are allowed - assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "description", 0, 200)); + assertInvalidService(service, String.format(INVALID_LENGTH_PATTERN, "description", 0, 200), false); } } diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java index 164b871..a117516 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java @@ -29,9 +29,9 @@ private static Store generateValidStore() { return store; } - private void assertInvalidStore(Store store, String expectedMsg) { + private void assertInvalidStore(Store store, String expectedMsg, boolean creating) { try { - storeValidator.validateStore(store); + storeValidator.validateStore(store, creating); failBecauseExceptionWasNotThrown(ValidationException.class); } catch (ValidationException ex) { assertThat(ex).hasMessage(expectedMsg); @@ -44,37 +44,61 @@ public void testValidBasicStore() throws ValidationException { store.setName("store"); store.setUrl("https://store.lab.fi-ware.org"); - assertThat(storeValidator.validateStore(store)).isTrue(); + assertThat(storeValidator.validateStore(store, true)).isTrue(); } @Test public void testValidComplexStore() throws ValidationException { Store store = generateValidStore(); - assertThat(storeValidator.validateStore(store)).isTrue(); + assertThat(storeValidator.validateStore(store, true)).isTrue(); } @Test - public void testMissingName() { + public void testMissingNameOnCreation() { Store store = generateValidStore(); store.setName(null); - assertInvalidStore(store, MISSING_FIELDS); + assertInvalidStore(store, MISSING_FIELDS, true); + } + + @Test + public void testMissingNameOnUpdate() throws ValidationException { + Store store = generateValidStore(); + store.setName(null); + + assertThat(storeValidator.validateStore(store, false)).isTrue(); } @Test - public void testMissingUrl() { + public void testMissingUrlOnCreation() { Store store = generateValidStore(); store.setUrl(null); - assertInvalidStore(store, MISSING_FIELDS); + assertInvalidStore(store, MISSING_FIELDS, true); } + + @Test + public void testMissingUrlOnUpdate() throws ValidationException { + Store store = generateValidStore(); + store.setUrl(null); + assertThat(storeValidator.validateStore(store, false)).isTrue(); + } + + @Test + public void testMissingDescriptionOnCreation() throws ValidationException { + Store store = generateValidStore(); + store.setDescription(null); + + assertThat(storeValidator.validateStore(store, true)).isTrue(); + } + @Test - public void testMissingDescription() throws ValidationException { + public void testMissingDescriptionOnUpdate() throws ValidationException { Store store = generateValidStore(); store.setDescription(null); - assertThat(storeValidator.validateStore(store)).isTrue(); + assertThat(storeValidator.validateStore(store, false)).isTrue(); } @Test @@ -82,7 +106,7 @@ public void testNameTooShort() { Store store = generateValidStore(); store.setName("a"); - assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15)); + assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15), false); } @Test @@ -90,7 +114,7 @@ public void testUserNameTooLong() { Store store = generateValidStore(); store.setName("1234567890123456"); - assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15)); + assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "name", 5, 15), false); } @Test @@ -98,7 +122,7 @@ public void testInvalidURL1() { Store store = generateValidStore(); store.setUrl("http://"); - assertInvalidStore(store, INVALID_URL); + assertInvalidStore(store, INVALID_URL, false); } @Test @@ -106,7 +130,7 @@ public void testInvalidURL2() { Store store = generateValidStore(); store.setUrl("store.lab.fi-ware.org"); - assertInvalidStore(store, INVALID_URL); + assertInvalidStore(store, INVALID_URL, false); } @Test @@ -114,7 +138,7 @@ public void testInvalidURL3() { Store store = generateValidStore(); store.setUrl("https://store.lab.fi-ware.org:222222"); - assertInvalidStore(store, INVALID_URL); + assertInvalidStore(store, INVALID_URL, false); } @Test @@ -122,7 +146,7 @@ public void testInvalidURL4() { Store store = generateValidStore(); store.setUrl("store"); - assertInvalidStore(store, INVALID_URL); + assertInvalidStore(store, INVALID_URL, false); } @Test @@ -131,7 +155,7 @@ public void testEmptyDescription() throws ValidationException { store.setDescription(""); // Empty descriptions are allowed - assertThat(storeValidator.validateStore(store)).isTrue(); + assertThat(storeValidator.validateStore(store, false)).isTrue(); } @Test @@ -144,7 +168,7 @@ public void testDescriptionTooLong() throws ValidationException { "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); // Empty descriptions are allowed - assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "description", 0, 200)); + assertInvalidStore(store, String.format(INVALID_LENGTH_PATTERN, "description", 0, 200),false); } } diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java index 1c29b25..b539dde 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java @@ -17,7 +17,7 @@ public class UserValidatorTest { private static User generateValidUser() { User user = new User(); user.setUserName("userName"); - user.setPassword("1234"); + user.setPassword("12345678"); user.setEmail("example@example.com"); user.setCompany("EXAMPLE"); user.setDisplayName("Example Name"); @@ -25,9 +25,9 @@ private static User generateValidUser() { return user; } - private void assertInvalidUser(User user, String expectedMsg) { + private void assertInvalidUser(User user, String expectedMsg, boolean creating) { try { - userValidator.validateUser(user); + userValidator.validateUser(user, creating); failBecauseExceptionWasNotThrown(ValidationException.class); } catch (ValidationException ex) { assertThat(ex).hasMessage(expectedMsg); @@ -38,43 +38,70 @@ private void assertInvalidUser(User user, String expectedMsg) { public void testValidBasicUser() throws ValidationException { User user = new User(); user.setUserName("userName"); - user.setPassword("1234"); + user.setPassword("12345678"); user.setEmail("example@example.com"); - assertThat(userValidator.validateUser(user)).isTrue(); + assertThat(userValidator.validateUser(user, true)).isTrue(); } @Test public void testValidComplexUser() throws ValidationException { User user = generateValidUser(); - assertThat(userValidator.validateUser(user)).isTrue(); + assertThat(userValidator.validateUser(user, true)).isTrue(); } @Test - public void testMissingUserName() { + public void testMissingUserNameOnCreation() { // Generate a user without username User user = generateValidUser(); user.setUserName(null); - assertInvalidUser(user, MISSING_FILEDS_MSG); + assertInvalidUser(user, MISSING_FILEDS_MSG, true); } @Test - public void testMissingPassword() { + public void testMissingUserNameOnUpdate() throws ValidationException { + // Generate a user without username + User user = generateValidUser(); + user.setUserName(null); + + assertThat(userValidator.validateUser(user, false)).isTrue(); + } + + @Test + public void testMissingPasswordOnCreation() { + // Generate a user without password + User user = generateValidUser(); + user.setPassword(null); + + assertInvalidUser(user, MISSING_FILEDS_MSG, true); + } + + @Test + public void testMissingPasswordOnUpdate() throws ValidationException { // Generate a user without password User user = generateValidUser(); user.setPassword(null); - assertInvalidUser(user, MISSING_FILEDS_MSG); + assertThat(userValidator.validateUser(user, false)).isTrue(); } @Test - public void testMissingMail() { + public void testMissingMailOnCreation() { // Generate a user without mail User user = generateValidUser(); user.setEmail(null); - assertInvalidUser(user, MISSING_FILEDS_MSG); + assertInvalidUser(user, MISSING_FILEDS_MSG, true); + } + + @Test + public void testMissingMailOnUpdate() throws ValidationException { + // Generate a user without mail + User user = generateValidUser(); + user.setEmail(null); + + assertThat(userValidator.validateUser(user, false)).isTrue(); } @Test @@ -83,7 +110,7 @@ public void testMissingDisplayName() throws ValidationException { user.setDisplayName(null); // Display name can be set to null - assertThat(userValidator.validateUser(user)).isTrue(); + assertThat(userValidator.validateUser(user, false)).isTrue(); } @Test @@ -92,7 +119,7 @@ public void testMissingCompany() throws ValidationException { user.setCompany(null); // Company name can be set to null - assertThat(userValidator.validateUser(user)).isTrue(); + assertThat(userValidator.validateUser(user, false)).isTrue(); } @Test @@ -100,7 +127,7 @@ public void testUserNameTooShort() { User user = generateValidUser(); user.setUserName("a"); - assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "userName", 5, 15)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "userName", 5, 15), false); } @Test @@ -108,7 +135,23 @@ public void testUserNameTooLong() { User user = generateValidUser(); user.setUserName("1234567890123456"); - assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "userName", 5, 15)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "userName", 5, 15), false); + } + + @Test + public void testPasswordTooShort() { + User user = generateValidUser(); + user.setPassword("a"); + + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "password", 8, 30), false); + } + + @Test + public void testPasswordTooLong() { + User user = generateValidUser(); + user.setPassword("1234567890123456789012345678901"); + + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "password", 8, 30), false); } @Test @@ -116,7 +159,7 @@ public void testDisplayNameTooShort() { User user = generateValidUser(); user.setDisplayName("a"); - assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "displayName", 5, 30)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "displayName", 5, 30), false); } @Test @@ -124,7 +167,7 @@ public void testDisplayNameTooLong() { User user = generateValidUser(); user.setDisplayName("1234567890123456789012345678901"); - assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "displayName", 5, 30)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "displayName", 5, 30), false); } @Test @@ -132,7 +175,7 @@ public void testInvalidMail1() { User user = generateValidUser(); user.setEmail("test"); - assertInvalidUser(user, INVALID_EMAIL); + assertInvalidUser(user, INVALID_EMAIL, false); } @Test @@ -140,7 +183,7 @@ public void testInvalidMail2() { User user = generateValidUser(); user.setEmail("test@test"); - assertInvalidUser(user, INVALID_EMAIL); + assertInvalidUser(user, INVALID_EMAIL, false); } @Test @@ -148,7 +191,7 @@ public void testInvalidMail3() { User user = generateValidUser(); user.setEmail("@test.com"); - assertInvalidUser(user, INVALID_EMAIL); + assertInvalidUser(user, INVALID_EMAIL, false); } @Test @@ -156,7 +199,7 @@ public void testCompanyTooShort() { User user = generateValidUser(); user.setCompany("a"); - assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "company", 3, 30)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "company", 3, 30), false); } @Test @@ -164,6 +207,6 @@ public void testCompanyTooLong() { User user = generateValidUser(); user.setCompany("1234567890123456789012345678901"); - assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "company", 3, 30)); + assertInvalidUser(user, String.format(INVALID_LENGTH_PATTERN, "company", 3, 30), false); } } From 13e91c5f52c77facd879ed6dedd4a2c52f728ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 18 Dec 2014 17:36:49 +0100 Subject: [PATCH 42/69] Tests for UserRegistrationService. Minor improvements --- .../apps/marketplace/rest/ErrorUtils.java | 8 + .../rest/UserRegistrationService.java | 14 +- .../rest/UserRegistrationServiceTest.java | 662 ++++++++++++++++++ 3 files changed, 677 insertions(+), 7 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java diff --git a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java index 55b9e66..a502223 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java @@ -44,6 +44,14 @@ public Response unauthorizedResponse(String action) { new APIError(ErrorType.UNAUTHORIZED, "You are not authorized to " + action)).build(); } + public Response internalServerError(Exception exception) { + if (exception.getCause() != null) { + return internalServerError(exception.getCause().getMessage()); + } else { + return internalServerError(exception.getMessage()); + } + } + public Response internalServerError(String cause) { return Response.status(Status.INTERNAL_SERVER_ERROR).entity( new APIError(ErrorType.INTERNAL_SERVER_ERROR, cause)).build(); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 6a9d4da..5a9ba0b 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -69,7 +69,7 @@ public Response createUser(User user) { } catch (DataAccessException ex) { response = ERROR_UTILS.badRequestResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -123,7 +123,7 @@ public Response updateUser(@PathParam("username") String username, User user) { } catch (UserNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -139,14 +139,14 @@ public Response deleteUser(@PathParam("username") String username) { // Only a user can delete his/her account if (userRegistrationAuth.canDelete(userToBeDeleted)) { userBo.delete(userToBeDeleted); - response = Response.status(Status.OK).build(); + response = Response.status(Status.NO_CONTENT).build(); } else { response = ERROR_UTILS.unauthorizedResponse("delete user " + username); } } catch (UserNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -155,7 +155,7 @@ public Response deleteUser(@PathParam("username") String username) { @GET @Produces({"application/xml", "application/json"}) @Path("/{username}") - public Response findUser(@PathParam("username") String username) { + public Response getUser(@PathParam("username") String username) { Response response; try { @@ -169,7 +169,7 @@ public Response findUser(@PathParam("username") String username) { } catch (UserNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -194,7 +194,7 @@ public Response listUsers(@DefaultValue("0") @QueryParam("offset") int offset, response = ERROR_UTILS.unauthorizedResponse("list users"); } } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } } diff --git a/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java new file mode 100644 index 0000000..f12d17d --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java @@ -0,0 +1,662 @@ +package org.fiware.apps.marketplace.rest; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.fiware.apps.marketplace.bo.UserBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.fiware.apps.marketplace.model.APIError; +import org.fiware.apps.marketplace.model.ErrorType; +import org.fiware.apps.marketplace.model.User; +import org.fiware.apps.marketplace.model.Users; +import org.fiware.apps.marketplace.model.validators.UserValidator; +import org.fiware.apps.marketplace.security.auth.UserRegistrationAuth; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.security.crypto.password.PasswordEncoder; + +import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; + +public class UserRegistrationServiceTest { + + @Mock private UserBo userBoMock; + @Mock private UserRegistrationAuth userRegistrationAuhtMock; + @Mock private UserValidator userValidator; + @Mock private PasswordEncoder encoder; + + @InjectMocks private UserRegistrationService userRegistrationService; + + // User to be created... + private User user; + + // Other useful constants + private static final String OFFSET_MAX_INVALID = "offset and/or max are not valid"; + private static final String VALIDATION_ERROR = "Validation Error"; + private static final String ENCODED_PASSWORD = "ENCODED_PASSWORD"; + private static final String USER_NAME = "user_name"; + private static final String PASSWORD = "12345678"; + private static final String EMAIL = "example@example.com"; + private static final String COMPANY = "Example"; + private static final String DISPLAY_NAME = "Example Name"; + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } + + @Before + public void generateValidUser() { + user = new User(); + user.setUserName(USER_NAME); + user.setPassword(PASSWORD); + user.setEmail(EMAIL); + user.setCompany(COMPANY); + user.setDisplayName(DISPLAY_NAME); + } + + private void checkAPIError(Response res, int status, ErrorType type, String message) { + assertThat(res.getStatus()).isEqualTo(status); + APIError error = (APIError) res.getEntity(); + assertThat(error.getErrorType()).isEqualTo(type); + assertThat(error.getErrorMessage()).isEqualTo(message); + } + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// CREATE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + private void checkMocksCreateCalledOnce() { + verify(encoder).encode(PASSWORD); + verify(userBoMock).save(user); + } + + private void checkMocksCreateNotCalled() { + verify(encoder, never()).encode(anyString()); + verify(userBoMock, never()).save(user); + } + + @Test + public void testCreateNotAllowed() { + // Mocks + when(userRegistrationAuhtMock.canCreate()).thenReturn(false); + + // Call the method + Response res = userRegistrationService.createUser(user); + + // Assertions + checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to create user"); + + // Verify mocks + verify(encoder, never()).encode(PASSWORD); + verify(userBoMock, never()).save(user); + + } + + @Test + public void testCreateNoErrors() throws ValidationException { + // Mocks + when(userRegistrationAuhtMock.canCreate()).thenReturn(true); + when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); + + //Call the method + Response res = userRegistrationService.createUser(user); + + // Verify mocks + verify(userValidator).validateUser(user, true); + checkMocksCreateCalledOnce(); + + // Check + assertThat(res.getStatus()).isEqualTo(201); + assertThat(user.getRegistrationDate()).isNotNull(); + assertThat(user.getUserName()).isEqualTo(USER_NAME); + assertThat(user.getDisplayName()).isEqualTo(DISPLAY_NAME); + assertThat(user.getEmail()).isEqualTo(EMAIL); + assertThat(user.getCompany()).isEqualTo(COMPANY); + assertThat(user.getPassword()).isEqualTo(ENCODED_PASSWORD); + } + + @Test + public void testCreateValidationError() throws ValidationException { + // Mock + when(userRegistrationAuhtMock.canCreate()).thenReturn(true); + doThrow(new ValidationException(VALIDATION_ERROR)).when(userValidator).validateUser(user, true); + when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); + + // Call the method + Response res = userRegistrationService.createUser(user); + + // Check + verify(userValidator).validateUser(user, true); + checkMocksCreateNotCalled(); + checkAPIError(res, 400, ErrorType.BAD_REQUEST, VALIDATION_ERROR); + } + + private void testCreateDataAccessException(Exception exception, String message) throws ValidationException { + // Mock + when(userRegistrationAuhtMock.canCreate()).thenReturn(true); + doThrow(new DataIntegrityViolationException("", exception)).when(userBoMock).save(isA(User.class)); + when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); + + // Call the method + Response res = userRegistrationService.createUser(user); + + // Checks + verify(userValidator).validateUser(user, true); + checkMocksCreateCalledOnce(); + checkAPIError(res, 400, ErrorType.BAD_REQUEST, message); + } + + @Test + public void testNotAllowedToCreateUserAlreadyExists() throws ValidationException { + testCreateDataAccessException(new MySQLIntegrityConstraintViolationException(), + "The user and/or the email introduced are already registered in the system"); + } + + @Test + public void testNotAllowedToCreateUserOtherDataException() throws ValidationException { + Exception exception = new Exception("Too much content"); + testCreateDataAccessException(exception, exception.getMessage()); + } + + @Test + public void testCreteNotKnowException() throws ValidationException { + // Mock + String exceptionMsg = "SERVER ERROR"; + when(userRegistrationAuhtMock.canCreate()).thenReturn(true); + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).save(user); + when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); + + // Call the method + Response res = userRegistrationService.createUser(user); + + // Checks + verify(userValidator).validateUser(user, true); + checkMocksCreateCalledOnce(); + checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// UPDATE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testUpdateNotAllowed() throws UserNotFoundException { + User newUser = new User(); + + // Mocks + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(false); + + // Call the method + Response res = userRegistrationService.updateUser(USER_NAME, newUser); + + // Assertions + checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to update user " + USER_NAME); + + // Verify mocks + verify(userBoMock).findByName(USER_NAME); + verify(encoder, never()).encode(PASSWORD); + verify(userBoMock, never()).save(user); + } + + private void testUpdateGenericUserNoErrors(User newUser) { + // Mocks + String NEW_ENCODED_PASSWORD = "NEW_PASSWORD"; + when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + when(encoder.encode(PASSWORD)).thenReturn(ENCODED_PASSWORD); + when(encoder.encode(newUser.getPassword())).thenReturn(NEW_ENCODED_PASSWORD); + + try { + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + } catch (UserNotFoundException e) { + // It isn't going to happen + } + + //Call the method + Response res = userRegistrationService.updateUser(USER_NAME, newUser); + + // Verify mocks + try { + verify(userBoMock).update(user); + verify(userValidator).validateUser(newUser, false); + verify(userBoMock).findByName(USER_NAME); + } catch (Exception ex) { + // It isn't going to happen... + } + + if (newUser.getPassword() != null) { + verify(encoder).encode(newUser.getPassword()); + } else { + verify(encoder, never()).encode(anyString()); + } + + // Check + assertThat(res.getStatus()).isEqualTo(200); + + // User names cannot be changed now... + /*if (newUser.getUserName() != null) { + assertThat(user.getUserName()).isEqualTo(newUser.getUserName()); + } else { + assertThat(user.getUserName()).isEqualTo(USER_NAME); + }*/ + + if (newUser.getDisplayName() != null) { + assertThat(user.getDisplayName()).isEqualTo(newUser.getDisplayName()); + } else { + assertThat(user.getDisplayName()).isEqualTo(DISPLAY_NAME); + } + + if (newUser.getEmail() != null) { + assertThat(user.getEmail()).isEqualTo(newUser.getEmail()); + } else { + assertThat(user.getEmail()).isEqualTo(EMAIL); + } + + if (newUser.getCompany() != null) { + assertThat(user.getCompany()).isEqualTo(newUser.getCompany()); + } else { + assertThat(user.getCompany()).isEqualTo(COMPANY); + } + + if (newUser.getPassword() != null) { + assertThat(user.getPassword()).isEqualTo(NEW_ENCODED_PASSWORD); + } else { + assertThat(user.getPassword()).isEqualTo(PASSWORD); + } + } + + @Test + public void testUpdateUserName() throws UserNotFoundException { + User newUser = new User(); + newUser.setUserName("new_user_name"); + + // Mocks + when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + + try { + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + } catch (UserNotFoundException e) { + // It isn't going to happen + } + + //Call the method + Response res = userRegistrationService.updateUser(USER_NAME, newUser); + + // Checks + verify(userBoMock).findByName(USER_NAME); + verify(userBoMock, never()).update(user); + checkAPIError(res, 400, ErrorType.BAD_REQUEST, "userName cannot be changed"); + } + + @Test + public void testUpdateDisplayName() { + User newUser = new User(); + newUser.setDisplayName("New Display Name"); + testUpdateGenericUserNoErrors(newUser); + } + + @Test + public void testUpdateEmail() { + User newUser = new User(); + newUser.setEmail("newmail@newmail.com"); + testUpdateGenericUserNoErrors(newUser); + } + + @Test + public void testUpdateComapmy() { + User newUser = new User(); + newUser.setEmail("New Awesome Company"); + testUpdateGenericUserNoErrors(newUser); + } + + @Test + public void testUpdatePassword() { + User newUser = new User(); + newUser.setPassword("my_new_super_secure_password123456789"); + testUpdateGenericUserNoErrors(newUser); + } + + @Test + public void testUpdateValidationError() throws ValidationException, UserNotFoundException { + User newUser = new User(); + + // Mock + when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + doThrow(new ValidationException(VALIDATION_ERROR)).when(userValidator).validateUser(newUser, false); + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + + // Call the method + Response res = userRegistrationService.updateUser(USER_NAME, newUser); + + // Check + verify(userBoMock).findByName(USER_NAME); + verify(userValidator).validateUser(newUser, false); + verify(userBoMock, never()).update(user); + + //checkMocksUpdateNotCalled(); + checkAPIError(res, 400, ErrorType.BAD_REQUEST, VALIDATION_ERROR); + } + + @Test + public void testUpdateNonExistingUser() throws UserNotFoundException, ValidationException { + User newUser = new User(); + String userNotFoundMsg = "user_name does not exist"; + + // Mock + when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + doThrow(new UserNotFoundException(userNotFoundMsg)).when(userBoMock).findByName(USER_NAME); + + // Call the method + Response res = userRegistrationService.updateUser(USER_NAME, newUser); + + // Check mocks + verify(userBoMock).findByName(USER_NAME); + verify(userValidator, never()).validateUser(newUser, false); + verify(userBoMock, never()).update(user); + checkAPIError(res, 404, ErrorType.NOT_FOUND, userNotFoundMsg); + } + + private void testDataAccessException(Exception exception, String message) { + User newUser = new User(); + + // Mock + when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + doThrow(new DataIntegrityViolationException("", + exception)).when(userBoMock).update(user); + + try { + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + } catch (UserNotFoundException e) { + // It isn't going to happen + } + + // Call the method + Response res = userRegistrationService.updateUser(USER_NAME, newUser); + + // Checks + try { + verify(userValidator).validateUser(user, false); + verify(userBoMock).findByName(USER_NAME); + verify(userBoMock).update(user); + checkAPIError(res, 400, ErrorType.BAD_REQUEST, message); + } catch (Exception e) { + // It isn't going to happen + } + + + } + + @Test + public void testUpdateViolationIntegration() throws ValidationException { + testDataAccessException(new MySQLIntegrityConstraintViolationException(), + "The user and/or the email introduced are already registered in the system"); + } + + + @Test + public void testUpdateOtherDataException() throws ValidationException { + Exception exception = new Exception("Too much content"); + testDataAccessException(exception, exception.getMessage()); + } + + @Test + public void testUpdateNotKnowException() throws ValidationException, UserNotFoundException { + // Mock + String exceptionMsg = "SERVER ERROR"; + when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).update(user); + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + + // Call the method + Response res = userRegistrationService.updateUser(USER_NAME, user); + + // Checks + verify(userBoMock).findByName(USER_NAME); + verify(userValidator).validateUser(user, false); + verify(userBoMock).update(user); + checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// DELETE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testDeleteNotAllowed() throws UserNotFoundException { + // Mocks + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + when(userRegistrationAuhtMock.canDelete(user)).thenReturn(false); + + // Call the method + Response res = userRegistrationService.deleteUser(USER_NAME); + + // Assertions + checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to delete user " + USER_NAME); + + // Verify mocks + verify(userBoMock).findByName(USER_NAME); + verify(userBoMock, never()).delete(user); + } + + @Test + public void testDeleteNoErrors() throws UserNotFoundException { + // Mocks + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + when(userRegistrationAuhtMock.canDelete(user)).thenReturn(true); + + // Call the method + Response res = userRegistrationService.deleteUser(USER_NAME); + + // Assertions + assertThat(res.getStatus()).isEqualTo(204); + + // Verify mocks + verify(userBoMock).findByName(USER_NAME); + verify(userBoMock).delete(user); + } + + @Test + public void testDeleteNotExisting() throws UserNotFoundException { + // Mocks + String msg = "User user_name not found"; + doThrow(new UserNotFoundException(msg)).when(userBoMock).findByName(USER_NAME); + when(userRegistrationAuhtMock.canDelete(user)).thenReturn(true); + + // Call the method + Response res = userRegistrationService.deleteUser(USER_NAME); + + // Assertions + checkAPIError(res, 404, ErrorType.NOT_FOUND, msg); + + //Verify mocks + verify(userBoMock).findByName(USER_NAME); + verify(userBoMock, never()).delete(isA(User.class)); + } + + @Test + public void testDeleteException() throws UserNotFoundException { + // Mocks + String exceptionMsg = "DB is down!"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).delete(user); + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + when(userRegistrationAuhtMock.canDelete(user)).thenReturn(true); + + // Call the method + Response res = userRegistrationService.deleteUser(USER_NAME); + + // Assertions + checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + + // Verify mocks + verify(userBoMock).findByName(USER_NAME); + verify(userBoMock).delete(user); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////// FIND //////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testGetNotAllowed() throws UserNotFoundException { + // Mocks + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + when(userRegistrationAuhtMock.canGet(user)).thenReturn(false); + + // Call the method + Response res = userRegistrationService.getUser(USER_NAME); + + // Assertions + checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to get user " + USER_NAME); + } + + @Test + public void testGetNoErrors() throws UserNotFoundException { + // Mocks + when(userBoMock.findByName(USER_NAME)).thenReturn(user); + when(userRegistrationAuhtMock.canGet(user)).thenReturn(true); + + // Call the method + Response res = userRegistrationService.getUser(USER_NAME); + + // Assertions + assertThat(res.getStatus()).isEqualTo(200); + assertThat((User) res.getEntity()).isEqualTo(user); + } + + @Test + public void testGetUserNotFound() throws UserNotFoundException { + // Mocks + String msg = "User user_name not found"; + doThrow(new UserNotFoundException(msg)).when(userBoMock).findByName(USER_NAME); + when(userRegistrationAuhtMock.canGet(user)).thenReturn(true); + + // Call the method + Response res = userRegistrationService.deleteUser(USER_NAME); + + // Assertions + checkAPIError(res, 404, ErrorType.NOT_FOUND, msg); + } + + @Test + public void testGetException() throws UserNotFoundException { + // Mocks + String exceptionMsg = "DB is down!"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).findByName(USER_NAME); + when(userRegistrationAuhtMock.canGet(user)).thenReturn(true); + + // Call the method + Response res = userRegistrationService.getUser(USER_NAME); + + // Assertions + checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + + // Verify + verify(userBoMock).findByName(USER_NAME); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////// LIST //////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testListNotAllowed() { + // Mocks + when(userRegistrationAuhtMock.canList()).thenReturn(false); + + // Call the method + Response res = userRegistrationService.listUsers(0, 100); + + // Assertions + checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to list users"); + } + + private void testListInvalidParams(int offset, int max) { + // Mocks + when(userRegistrationAuhtMock.canList()).thenReturn(true); + + // Call the method + Response res = userRegistrationService.listUsers(offset, max); + + // Assertions + checkAPIError(res, 400, ErrorType.BAD_REQUEST, OFFSET_MAX_INVALID); + } + + @Test + public void testListInvalidOffset() { + testListInvalidParams(-1, 100); + } + + @Test + public void testListInvalidMax() { + testListInvalidParams(0, -1); + } + + @Test + public void testListInvalidOffsetMax() { + testListInvalidParams(-1, -1); + } + + @Test + public void testListGetNoErrors() { + List users = new ArrayList(); + for (int i = 0; i < 3; i++) { + User user = new User(); + user.setId(i); + users.add(user); + } + + // Mocks + when(userRegistrationAuhtMock.canList()).thenReturn(true); + when(userBoMock.getUsersPage(anyInt(), anyInt())).thenReturn(users); + + // Call the method + int offset = 0; + int max = 100; + Response res = userRegistrationService.listUsers(offset, max); + + // Verify + verify(userBoMock).getUsersPage(offset, max); + + // Assertations + assertThat(res.getStatus()).isEqualTo(200); + assertThat(((Users) res.getEntity()).getUsers()).isEqualTo(users); + } + + @Test + public void testListException() { + // Mocks + String exceptionMsg = "exception"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).getUsersPage(anyInt(), anyInt()); + when(userRegistrationAuhtMock.canList()).thenReturn(true); + + // Call the method + int offset = 0; + int max = 100; + Response res = userRegistrationService.listUsers(offset, max); + + // Verify + verify(userBoMock).getUsersPage(offset, max); + + // Check exception + checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + } + +} From 6dfd34dc5bdcf3c1c1ea4ac5a398e1fc76410058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 18 Dec 2014 17:37:29 +0100 Subject: [PATCH 43/69] Return 204 on delete. Handle Exceptions in a better way --- .../rest/OfferingRegistrationService.java | 12 ++++++------ .../marketplace/rest/StoreRegistrationService.java | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index bb7385d..3383c74 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -84,7 +84,7 @@ public Response saveService(@PathParam("storeName") String storeName, Service se } catch (DataAccessException ex) { response = ERROR_UTILS.badRequestResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -141,7 +141,7 @@ public Response updateService(@PathParam("storeName") String storeName, } catch (DataAccessException ex) { response = ERROR_UTILS.badRequestResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -160,7 +160,7 @@ public Response deleteService(@PathParam("storeName") String storeName, if (offeringRegistrationAuth.canUpdate(service)) { serviceBo.delete(service); - response = Response.status(Status.OK).build(); + response = Response.status(Status.NO_CONTENT).build(); } else { response = ERROR_UTILS.unauthorizedResponse("update offering " + serviceName); } @@ -169,7 +169,7 @@ public Response deleteService(@PathParam("storeName") String storeName, } catch (StoreNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -197,7 +197,7 @@ public Response getService(@PathParam("storeName") String storeName, } catch (StoreNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -236,7 +236,7 @@ public Response listServices(@PathParam("storeName") String storeName, } catch (StoreNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } } else { response = ERROR_UTILS.unauthorizedResponse("list offerings"); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index f03b655..561f079 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -76,7 +76,7 @@ public Response createStore(Store store) { } catch (DataAccessException ex) { response = ERROR_UTILS.badRequestResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -124,7 +124,7 @@ public Response updateStore(@PathParam("storeName") String storeName, Store stor } catch (StoreNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -141,7 +141,7 @@ public Response deleteStore(@PathParam("storeName") String storeName) { if (storeRegistrationAuth.canDelete(store)) { storeBo.delete(store); - response = Response.status(Status.OK).build(); // Return OK + response = Response.status(Status.NO_CONTENT).build(); // Return 204 No Content } else { response = ERROR_UTILS.unauthorizedResponse("delete store " + storeName); } @@ -172,7 +172,7 @@ public Response getStore(@PathParam("storeName") String storeName) { } catch (StoreNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } return response; @@ -197,7 +197,7 @@ public Response listStores(@DefaultValue("0") @QueryParam("offset") int offset, response = ERROR_UTILS.unauthorizedResponse("list stores"); } } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex.getCause().getMessage()); + response = ERROR_UTILS.internalServerError(ex); } } From ca135ff28fe11c3509d20519e079a66ff3a0f20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 18 Dec 2014 17:50:48 +0100 Subject: [PATCH 44/69] Fix minor typo --- .../rest/GenericRestTestUtils.java | 20 ++++ .../rest/UserRegistrationServiceTest.java | 96 +++++++++---------- 2 files changed, 64 insertions(+), 52 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/rest/GenericRestTestUtils.java diff --git a/src/test/java/org/fiware/apps/marketplace/rest/GenericRestTestUtils.java b/src/test/java/org/fiware/apps/marketplace/rest/GenericRestTestUtils.java new file mode 100644 index 0000000..d3f9414 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/rest/GenericRestTestUtils.java @@ -0,0 +1,20 @@ +package org.fiware.apps.marketplace.rest; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.ws.rs.core.Response; + +import org.fiware.apps.marketplace.model.APIError; +import org.fiware.apps.marketplace.model.ErrorType; + +public class GenericRestTestUtils { + + public static void checkAPIError(Response res, int status, ErrorType type, String message) { + assertThat(res.getStatus()).isEqualTo(status); + APIError error = (APIError) res.getEntity(); + assertThat(error.getErrorType()).isEqualTo(type); + assertThat(error.getErrorMessage()).isEqualTo(message); + } + + +} diff --git a/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java index f12d17d..49a2d1b 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java @@ -11,7 +11,6 @@ import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.exceptions.ValidationException; -import org.fiware.apps.marketplace.model.APIError; import org.fiware.apps.marketplace.model.ErrorType; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Users; @@ -30,7 +29,7 @@ public class UserRegistrationServiceTest { @Mock private UserBo userBoMock; - @Mock private UserRegistrationAuth userRegistrationAuhtMock; + @Mock private UserRegistrationAuth userRegistrationAuthMock; @Mock private UserValidator userValidator; @Mock private PasswordEncoder encoder; @@ -68,13 +67,6 @@ public void generateValidUser() { user.setDisplayName(DISPLAY_NAME); } - private void checkAPIError(Response res, int status, ErrorType type, String message) { - assertThat(res.getStatus()).isEqualTo(status); - APIError error = (APIError) res.getEntity(); - assertThat(error.getErrorType()).isEqualTo(type); - assertThat(error.getErrorMessage()).isEqualTo(message); - } - /////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// CREATE /////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// @@ -92,13 +84,13 @@ private void checkMocksCreateNotCalled() { @Test public void testCreateNotAllowed() { // Mocks - when(userRegistrationAuhtMock.canCreate()).thenReturn(false); + when(userRegistrationAuthMock.canCreate()).thenReturn(false); // Call the method Response res = userRegistrationService.createUser(user); // Assertions - checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to create user"); + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to create user"); // Verify mocks verify(encoder, never()).encode(PASSWORD); @@ -109,7 +101,7 @@ public void testCreateNotAllowed() { @Test public void testCreateNoErrors() throws ValidationException { // Mocks - when(userRegistrationAuhtMock.canCreate()).thenReturn(true); + when(userRegistrationAuthMock.canCreate()).thenReturn(true); when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); //Call the method @@ -132,7 +124,7 @@ public void testCreateNoErrors() throws ValidationException { @Test public void testCreateValidationError() throws ValidationException { // Mock - when(userRegistrationAuhtMock.canCreate()).thenReturn(true); + when(userRegistrationAuthMock.canCreate()).thenReturn(true); doThrow(new ValidationException(VALIDATION_ERROR)).when(userValidator).validateUser(user, true); when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); @@ -142,12 +134,12 @@ public void testCreateValidationError() throws ValidationException { // Check verify(userValidator).validateUser(user, true); checkMocksCreateNotCalled(); - checkAPIError(res, 400, ErrorType.BAD_REQUEST, VALIDATION_ERROR); + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, VALIDATION_ERROR); } private void testCreateDataAccessException(Exception exception, String message) throws ValidationException { // Mock - when(userRegistrationAuhtMock.canCreate()).thenReturn(true); + when(userRegistrationAuthMock.canCreate()).thenReturn(true); doThrow(new DataIntegrityViolationException("", exception)).when(userBoMock).save(isA(User.class)); when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); @@ -157,7 +149,7 @@ private void testCreateDataAccessException(Exception exception, String message) // Checks verify(userValidator).validateUser(user, true); checkMocksCreateCalledOnce(); - checkAPIError(res, 400, ErrorType.BAD_REQUEST, message); + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, message); } @Test @@ -176,7 +168,7 @@ public void testNotAllowedToCreateUserOtherDataException() throws ValidationExce public void testCreteNotKnowException() throws ValidationException { // Mock String exceptionMsg = "SERVER ERROR"; - when(userRegistrationAuhtMock.canCreate()).thenReturn(true); + when(userRegistrationAuthMock.canCreate()).thenReturn(true); doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).save(user); when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); @@ -186,7 +178,7 @@ public void testCreteNotKnowException() throws ValidationException { // Checks verify(userValidator).validateUser(user, true); checkMocksCreateCalledOnce(); - checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + GenericRestTestUtils.checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); } @@ -200,13 +192,13 @@ public void testUpdateNotAllowed() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); - when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(false); + when(userRegistrationAuthMock.canUpdate(user)).thenReturn(false); // Call the method Response res = userRegistrationService.updateUser(USER_NAME, newUser); // Assertions - checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to update user " + USER_NAME); + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to update user " + USER_NAME); // Verify mocks verify(userBoMock).findByName(USER_NAME); @@ -217,7 +209,7 @@ public void testUpdateNotAllowed() throws UserNotFoundException { private void testUpdateGenericUserNoErrors(User newUser) { // Mocks String NEW_ENCODED_PASSWORD = "NEW_PASSWORD"; - when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + when(userRegistrationAuthMock.canUpdate(user)).thenReturn(true); when(encoder.encode(PASSWORD)).thenReturn(ENCODED_PASSWORD); when(encoder.encode(newUser.getPassword())).thenReturn(NEW_ENCODED_PASSWORD); @@ -286,7 +278,7 @@ public void testUpdateUserName() throws UserNotFoundException { newUser.setUserName("new_user_name"); // Mocks - when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + when(userRegistrationAuthMock.canUpdate(user)).thenReturn(true); try { when(userBoMock.findByName(USER_NAME)).thenReturn(user); @@ -300,7 +292,7 @@ public void testUpdateUserName() throws UserNotFoundException { // Checks verify(userBoMock).findByName(USER_NAME); verify(userBoMock, never()).update(user); - checkAPIError(res, 400, ErrorType.BAD_REQUEST, "userName cannot be changed"); + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, "userName cannot be changed"); } @Test @@ -336,7 +328,7 @@ public void testUpdateValidationError() throws ValidationException, UserNotFound User newUser = new User(); // Mock - when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + when(userRegistrationAuthMock.canUpdate(user)).thenReturn(true); doThrow(new ValidationException(VALIDATION_ERROR)).when(userValidator).validateUser(newUser, false); when(userBoMock.findByName(USER_NAME)).thenReturn(user); @@ -349,7 +341,7 @@ public void testUpdateValidationError() throws ValidationException, UserNotFound verify(userBoMock, never()).update(user); //checkMocksUpdateNotCalled(); - checkAPIError(res, 400, ErrorType.BAD_REQUEST, VALIDATION_ERROR); + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, VALIDATION_ERROR); } @Test @@ -358,7 +350,7 @@ public void testUpdateNonExistingUser() throws UserNotFoundException, Validation String userNotFoundMsg = "user_name does not exist"; // Mock - when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + when(userRegistrationAuthMock.canUpdate(user)).thenReturn(true); doThrow(new UserNotFoundException(userNotFoundMsg)).when(userBoMock).findByName(USER_NAME); // Call the method @@ -368,14 +360,14 @@ public void testUpdateNonExistingUser() throws UserNotFoundException, Validation verify(userBoMock).findByName(USER_NAME); verify(userValidator, never()).validateUser(newUser, false); verify(userBoMock, never()).update(user); - checkAPIError(res, 404, ErrorType.NOT_FOUND, userNotFoundMsg); + GenericRestTestUtils.checkAPIError(res, 404, ErrorType.NOT_FOUND, userNotFoundMsg); } private void testDataAccessException(Exception exception, String message) { User newUser = new User(); // Mock - when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + when(userRegistrationAuthMock.canUpdate(user)).thenReturn(true); doThrow(new DataIntegrityViolationException("", exception)).when(userBoMock).update(user); @@ -393,7 +385,7 @@ private void testDataAccessException(Exception exception, String message) { verify(userValidator).validateUser(user, false); verify(userBoMock).findByName(USER_NAME); verify(userBoMock).update(user); - checkAPIError(res, 400, ErrorType.BAD_REQUEST, message); + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, message); } catch (Exception e) { // It isn't going to happen } @@ -418,7 +410,7 @@ public void testUpdateOtherDataException() throws ValidationException { public void testUpdateNotKnowException() throws ValidationException, UserNotFoundException { // Mock String exceptionMsg = "SERVER ERROR"; - when(userRegistrationAuhtMock.canUpdate(user)).thenReturn(true); + when(userRegistrationAuthMock.canUpdate(user)).thenReturn(true); doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).update(user); when(userBoMock.findByName(USER_NAME)).thenReturn(user); @@ -429,7 +421,7 @@ public void testUpdateNotKnowException() throws ValidationException, UserNotFoun verify(userBoMock).findByName(USER_NAME); verify(userValidator).validateUser(user, false); verify(userBoMock).update(user); - checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + GenericRestTestUtils.checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); } @@ -441,13 +433,13 @@ public void testUpdateNotKnowException() throws ValidationException, UserNotFoun public void testDeleteNotAllowed() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); - when(userRegistrationAuhtMock.canDelete(user)).thenReturn(false); + when(userRegistrationAuthMock.canDelete(user)).thenReturn(false); // Call the method Response res = userRegistrationService.deleteUser(USER_NAME); // Assertions - checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to delete user " + USER_NAME); + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to delete user " + USER_NAME); // Verify mocks verify(userBoMock).findByName(USER_NAME); @@ -458,7 +450,7 @@ public void testDeleteNotAllowed() throws UserNotFoundException { public void testDeleteNoErrors() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); - when(userRegistrationAuhtMock.canDelete(user)).thenReturn(true); + when(userRegistrationAuthMock.canDelete(user)).thenReturn(true); // Call the method Response res = userRegistrationService.deleteUser(USER_NAME); @@ -476,13 +468,13 @@ public void testDeleteNotExisting() throws UserNotFoundException { // Mocks String msg = "User user_name not found"; doThrow(new UserNotFoundException(msg)).when(userBoMock).findByName(USER_NAME); - when(userRegistrationAuhtMock.canDelete(user)).thenReturn(true); + when(userRegistrationAuthMock.canDelete(user)).thenReturn(true); // Call the method Response res = userRegistrationService.deleteUser(USER_NAME); // Assertions - checkAPIError(res, 404, ErrorType.NOT_FOUND, msg); + GenericRestTestUtils.checkAPIError(res, 404, ErrorType.NOT_FOUND, msg); //Verify mocks verify(userBoMock).findByName(USER_NAME); @@ -495,13 +487,13 @@ public void testDeleteException() throws UserNotFoundException { String exceptionMsg = "DB is down!"; doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).delete(user); when(userBoMock.findByName(USER_NAME)).thenReturn(user); - when(userRegistrationAuhtMock.canDelete(user)).thenReturn(true); + when(userRegistrationAuthMock.canDelete(user)).thenReturn(true); // Call the method Response res = userRegistrationService.deleteUser(USER_NAME); // Assertions - checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + GenericRestTestUtils.checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); // Verify mocks verify(userBoMock).findByName(USER_NAME); @@ -517,20 +509,20 @@ public void testDeleteException() throws UserNotFoundException { public void testGetNotAllowed() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); - when(userRegistrationAuhtMock.canGet(user)).thenReturn(false); + when(userRegistrationAuthMock.canGet(user)).thenReturn(false); // Call the method Response res = userRegistrationService.getUser(USER_NAME); // Assertions - checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to get user " + USER_NAME); + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to get user " + USER_NAME); } @Test public void testGetNoErrors() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); - when(userRegistrationAuhtMock.canGet(user)).thenReturn(true); + when(userRegistrationAuthMock.canGet(user)).thenReturn(true); // Call the method Response res = userRegistrationService.getUser(USER_NAME); @@ -545,13 +537,13 @@ public void testGetUserNotFound() throws UserNotFoundException { // Mocks String msg = "User user_name not found"; doThrow(new UserNotFoundException(msg)).when(userBoMock).findByName(USER_NAME); - when(userRegistrationAuhtMock.canGet(user)).thenReturn(true); + when(userRegistrationAuthMock.canGet(user)).thenReturn(true); // Call the method Response res = userRegistrationService.deleteUser(USER_NAME); // Assertions - checkAPIError(res, 404, ErrorType.NOT_FOUND, msg); + GenericRestTestUtils.checkAPIError(res, 404, ErrorType.NOT_FOUND, msg); } @Test @@ -559,13 +551,13 @@ public void testGetException() throws UserNotFoundException { // Mocks String exceptionMsg = "DB is down!"; doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).findByName(USER_NAME); - when(userRegistrationAuhtMock.canGet(user)).thenReturn(true); + when(userRegistrationAuthMock.canGet(user)).thenReturn(true); // Call the method Response res = userRegistrationService.getUser(USER_NAME); // Assertions - checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + GenericRestTestUtils.checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); // Verify verify(userBoMock).findByName(USER_NAME); @@ -579,24 +571,24 @@ public void testGetException() throws UserNotFoundException { @Test public void testListNotAllowed() { // Mocks - when(userRegistrationAuhtMock.canList()).thenReturn(false); + when(userRegistrationAuthMock.canList()).thenReturn(false); // Call the method Response res = userRegistrationService.listUsers(0, 100); // Assertions - checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to list users"); + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to list users"); } private void testListInvalidParams(int offset, int max) { // Mocks - when(userRegistrationAuhtMock.canList()).thenReturn(true); + when(userRegistrationAuthMock.canList()).thenReturn(true); // Call the method Response res = userRegistrationService.listUsers(offset, max); // Assertions - checkAPIError(res, 400, ErrorType.BAD_REQUEST, OFFSET_MAX_INVALID); + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, OFFSET_MAX_INVALID); } @Test @@ -624,7 +616,7 @@ public void testListGetNoErrors() { } // Mocks - when(userRegistrationAuhtMock.canList()).thenReturn(true); + when(userRegistrationAuthMock.canList()).thenReturn(true); when(userBoMock.getUsersPage(anyInt(), anyInt())).thenReturn(users); // Call the method @@ -645,7 +637,7 @@ public void testListException() { // Mocks String exceptionMsg = "exception"; doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).getUsersPage(anyInt(), anyInt()); - when(userRegistrationAuhtMock.canList()).thenReturn(true); + when(userRegistrationAuthMock.canList()).thenReturn(true); // Call the method int offset = 0; @@ -656,7 +648,7 @@ public void testListException() { verify(userBoMock).getUsersPage(offset, max); // Check exception - checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + GenericRestTestUtils.checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); } } From 7730a2ce45c034bd33e467c7265a1a14e1967d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Thu, 18 Dec 2014 18:22:01 +0100 Subject: [PATCH 45/69] Add tests for StoreRegistrationService (only for createStore) --- .../rest/StoreRegistrationServiceTest.java | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java diff --git a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java new file mode 100644 index 0000000..558ee04 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java @@ -0,0 +1,185 @@ +package org.fiware.apps.marketplace.rest; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import javax.ws.rs.core.Response; + +import org.fiware.apps.marketplace.bo.StoreBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.fiware.apps.marketplace.model.ErrorType; +import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.model.User; +import org.fiware.apps.marketplace.model.validators.StoreValidator; +import org.fiware.apps.marketplace.security.auth.AuthUtils; +import org.fiware.apps.marketplace.security.auth.StoreRegistrationAuth; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.dao.DataIntegrityViolationException; + +import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; + +public class StoreRegistrationServiceTest { + + @Mock private StoreBo storeBoMock; + @Mock private StoreRegistrationAuth storeRegistrationAuthMock; + @Mock private StoreValidator storeValidatorMock; + @Mock private AuthUtils authUtilsMock; + + @InjectMocks private StoreRegistrationService storeRegistrationService; + + // Default store + private User user; + private Store store; + + // Other useful constants + private static final String VALIDATION_ERROR = "Validation Exception"; + private static final String DESCRIPTION = "This is a basic description"; + private static final String NAME = "store"; + private static final String URL = "https://store.lab.fi-ware.org"; + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } + + @Before + public void generateValidStore() { + store = new Store(); + store.setDescription(DESCRIPTION); + store.setName(NAME); + store.setUrl(URL); + } + + @Before + public void initAuthUtils() throws UserNotFoundException { + when(authUtilsMock.getLoggedUser()).thenReturn(user); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// CREATE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testCreateStoreNotAllowed() { + // Mocks + when(storeRegistrationAuthMock.canCreate()).thenReturn(false); + + // Call the method + Response res = storeRegistrationService.createStore(store); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to create store"); + + // Verify mocks + verify(storeBoMock, never()).save(store); + } + + @Test + public void testCreateStoreNoErrors() throws ValidationException { + // Mocks + when(storeRegistrationAuthMock.canCreate()).thenReturn(true); + + //Call the method + Response res = storeRegistrationService.createStore(store); + + // Verify mocks + verify(storeValidatorMock).validateStore(store, true); + verify(storeBoMock).save(store); + + // Check the response + assertThat(res.getStatus()).isEqualTo(201); + + // Check that all the parameters of the Store are correct + // (some of them must have been changed by the method) + assertThat(store.getRegistrationDate()).isNotNull(); + assertThat(store.getName()).isEqualTo(NAME); + assertThat(store.getDescription()).isEqualTo(DESCRIPTION); + assertThat(store.getUrl()).isEqualTo(URL); + assertThat(store.getCreator()).isEqualTo(user); + assertThat(store.getLasteditor()).isEqualTo(user); + } + + private void testCreateStoreGenericError(int statusCode, ErrorType errorType, String errorMsg, boolean saveInvoked) { + int saveTimes = saveInvoked ? 1 : 0; + + // Call the method + Response res = storeRegistrationService.createStore(store); + + // Verify mocks + try { + verify(storeValidatorMock).validateStore(store, true); + verify(storeBoMock, times(saveTimes)).save(store); + GenericRestTestUtils.checkAPIError(res, statusCode, errorType, errorMsg); + } catch (ValidationException e) { + // Impossible... + fail("exception " + e + " not expected"); + } + } + + @Test + public void testCreateStoreValidationException() throws ValidationException { + // Mocks + when(storeRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new ValidationException(VALIDATION_ERROR)).when(storeValidatorMock).validateStore(store, true); + + testCreateStoreGenericError(400, ErrorType.BAD_REQUEST, VALIDATION_ERROR, false); + } + + @Test + public void testCreateStoreUserNotFoundException() throws ValidationException, UserNotFoundException { + // Mocks + when(storeRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new UserNotFoundException("User Not Found exception")).when(authUtilsMock).getLoggedUser(); + + testCreateStoreGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, + "There was an error retrieving the user from the database", false); + + } + + private void testCreateStoreDataAccessException(Exception exception, String message) throws ValidationException { + // Mock + when(storeRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new DataIntegrityViolationException("", exception)).when(storeBoMock).save(store); + + testCreateStoreGenericError(400, ErrorType.BAD_REQUEST, message, true); + } + + @Test + public void testNotAllowedToCreateUserAlreadyExists() throws ValidationException { + testCreateStoreDataAccessException(new MySQLIntegrityConstraintViolationException(), + "There is already a Store with that name/URL registered in the system"); + } + + @Test + public void testNotAllowedToCreateUserOtherDataException() throws ValidationException { + Exception exception = new Exception("Too much content"); + testCreateStoreDataAccessException(exception, exception.getMessage()); + } + + @Test + public void testCreteNotKnowException() throws ValidationException { + // Mock + String exceptionMsg = "SERVER ERROR"; + when(storeRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(storeBoMock).save(store); + + testCreateStoreGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg, true); + } + + + + + + + +} From 39b51d4e507b4a3ba00808f9bab15ab08aa5b9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Fri, 19 Dec 2014 15:01:46 +0100 Subject: [PATCH 46/69] Complete the tests for the StoreRegistrationService --- .../rest/StoreRegistrationService.java | 2 +- .../rest/StoreRegistrationServiceTest.java | 455 +++++++++++++++++- .../rest/UserRegistrationServiceTest.java | 78 +-- 3 files changed, 470 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 561f079..83359c1 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -86,7 +86,7 @@ public Response createStore(Store store) { @PUT @Consumes({"application/xml", "application/json"}) @Path("/{storeName}") - public Response updateStore(@PathParam("storeName") String storeName, Store store) throws UserNotFoundException { + public Response updateStore(@PathParam("storeName") String storeName, Store store) { Response response; try { diff --git a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java index 558ee04..0c18578 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java @@ -1,15 +1,21 @@ package org.fiware.apps.marketplace.rest; import static org.assertj.core.api.Assertions.*; +import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.*; +import java.util.ArrayList; +import java.util.List; + import javax.ws.rs.core.Response; import org.fiware.apps.marketplace.bo.StoreBo; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.exceptions.ValidationException; import org.fiware.apps.marketplace.model.ErrorType; import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.model.Stores; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.validators.StoreValidator; import org.fiware.apps.marketplace.security.auth.AuthUtils; @@ -24,24 +30,25 @@ import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; public class StoreRegistrationServiceTest { - + @Mock private StoreBo storeBoMock; @Mock private StoreRegistrationAuth storeRegistrationAuthMock; @Mock private StoreValidator storeValidatorMock; @Mock private AuthUtils authUtilsMock; @InjectMocks private StoreRegistrationService storeRegistrationService; - + // Default store private User user; private Store store; - + // Other useful constants + private static final String OFFSET_MAX_INVALID = "offset and/or max are not valid"; private static final String VALIDATION_ERROR = "Validation Exception"; private static final String DESCRIPTION = "This is a basic description"; private static final String NAME = "store"; private static final String URL = "https://store.lab.fi-ware.org"; - + /////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////// BASIC METHODS //////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// @@ -50,7 +57,7 @@ public class StoreRegistrationServiceTest { public void initMocks() { MockitoAnnotations.initMocks(this); } - + @Before public void generateValidStore() { store = new Store(); @@ -58,13 +65,13 @@ public void generateValidStore() { store.setName(NAME); store.setUrl(URL); } - + @Before public void initAuthUtils() throws UserNotFoundException { when(authUtilsMock.getLoggedUser()).thenReturn(user); } - - + + /////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// CREATE /////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// @@ -83,7 +90,7 @@ public void testCreateStoreNotAllowed() { // Verify mocks verify(storeBoMock, never()).save(store); } - + @Test public void testCreateStoreNoErrors() throws ValidationException { // Mocks @@ -98,7 +105,7 @@ public void testCreateStoreNoErrors() throws ValidationException { // Check the response assertThat(res.getStatus()).isEqualTo(201); - + // Check that all the parameters of the Store are correct // (some of them must have been changed by the method) assertThat(store.getRegistrationDate()).isNotNull(); @@ -108,13 +115,13 @@ public void testCreateStoreNoErrors() throws ValidationException { assertThat(store.getCreator()).isEqualTo(user); assertThat(store.getLasteditor()).isEqualTo(user); } - + private void testCreateStoreGenericError(int statusCode, ErrorType errorType, String errorMsg, boolean saveInvoked) { int saveTimes = saveInvoked ? 1 : 0; - + // Call the method Response res = storeRegistrationService.createStore(store); - + // Verify mocks try { verify(storeValidatorMock).validateStore(store, true); @@ -125,16 +132,16 @@ private void testCreateStoreGenericError(int statusCode, ErrorType errorType, St fail("exception " + e + " not expected"); } } - + @Test public void testCreateStoreValidationException() throws ValidationException { // Mocks when(storeRegistrationAuthMock.canCreate()).thenReturn(true); doThrow(new ValidationException(VALIDATION_ERROR)).when(storeValidatorMock).validateStore(store, true); - + testCreateStoreGenericError(400, ErrorType.BAD_REQUEST, VALIDATION_ERROR, false); } - + @Test public void testCreateStoreUserNotFoundException() throws ValidationException, UserNotFoundException { // Mocks @@ -143,9 +150,9 @@ public void testCreateStoreUserNotFoundException() throws ValidationException, U testCreateStoreGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, "There was an error retrieving the user from the database", false); - + } - + private void testCreateStoreDataAccessException(Exception exception, String message) throws ValidationException { // Mock when(storeRegistrationAuthMock.canCreate()).thenReturn(true); @@ -153,33 +160,431 @@ private void testCreateStoreDataAccessException(Exception exception, String mess testCreateStoreGenericError(400, ErrorType.BAD_REQUEST, message, true); } - + @Test - public void testNotAllowedToCreateUserAlreadyExists() throws ValidationException { + public void testCreateStoreAlreadyExists() throws ValidationException { testCreateStoreDataAccessException(new MySQLIntegrityConstraintViolationException(), "There is already a Store with that name/URL registered in the system"); } - + @Test - public void testNotAllowedToCreateUserOtherDataException() throws ValidationException { + public void testCreateStoreOtherDataException() throws ValidationException { Exception exception = new Exception("Too much content"); testCreateStoreDataAccessException(exception, exception.getMessage()); } - + @Test - public void testCreteNotKnowException() throws ValidationException { + public void testCreteStoreNotKnowException() throws ValidationException { // Mock String exceptionMsg = "SERVER ERROR"; when(storeRegistrationAuthMock.canCreate()).thenReturn(true); doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(storeBoMock).save(store); - + testCreateStoreGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg, true); } + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// UPDATE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testUpdateStoreNotAllowed() throws StoreNotFoundException { + Store newStore = new Store(); + + // Mocks + when(storeRegistrationAuthMock.canUpdate(store)).thenReturn(false); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + // Call the method + Response res = storeRegistrationService.updateStore(NAME, newStore); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, + "You are not authorized to update store " + NAME); + + // Verify mocks + verify(storeBoMock, never()).update(store); + } + + private void testUpdateStoreField(Store newStore) { + try { + // Mock + when(storeRegistrationAuthMock.canUpdate(store)).thenReturn(true); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + // Call the method + Response res = storeRegistrationService.updateStore(NAME, newStore); + + // Verify mocks + verify(storeValidatorMock).validateStore(newStore, false); + verify(storeBoMock).update(store); + + // Assertions + assertThat(res.getStatus()).isEqualTo(200); + + // New values + String newStoreName = newStore.getName() != null ? newStore.getName() : store.getName(); + assertThat(store.getName()).isEqualTo(newStoreName); + + String newStoreUrl = newStore.getUrl() != null ? newStore.getUrl() : store.getUrl(); + assertThat(store.getUrl()).isEqualTo(newStoreUrl); + + String newStoreDescription = newStore.getDescription() != null ? newStore.getDescription() : store.getDescription(); + assertThat(store.getDescription()).isEqualTo(newStoreDescription); + } catch (Exception ex) { + // It's not supposed to happen + fail("Exception " + ex + " is not supposed to happen"); + } + } + + @Test + public void testUpdateStoreName() { + Store newStore = new Store(); + newStore.setName("new_name"); + testUpdateStoreField(newStore); + } + + @Test + public void testUpdateStoreUrl() { + Store newStore = new Store(); + newStore.setUrl("http://fi-ware.org"); + testUpdateStoreField(newStore); + } + + @Test + public void testUpdateStoreDescription() { + Store newStore = new Store(); + newStore.setDescription("New Description"); + testUpdateStoreField(newStore); + } + + private void testUpdateStoreGenericError(Store newStore, int status, ErrorType errorType, + String message, boolean updateInvoked, boolean verifyInvoked) { + int updateTimes = updateInvoked ? 1 : 0; + int verifyTimes = verifyInvoked ? 1 : 0; + + try { + // Mocks + when(storeRegistrationAuthMock.canUpdate(store)).thenReturn(true); + + // Call the method + Response res = storeRegistrationService.updateStore(NAME, newStore); + + // Assertions + GenericRestTestUtils.checkAPIError(res, status, errorType, message); + + // Verify mocks + verify(storeValidatorMock, times(verifyTimes)).validateStore(newStore, false); + verify(storeBoMock, times(updateTimes)).update(store); + } catch (Exception ex) { + fail("Exception " + ex + " not expected."); + } + } + + @Test + public void testUpdateStoreValidationException() throws ValidationException, StoreNotFoundException { + Store newStore = new Store(); + + // Mocks + doThrow(new ValidationException(VALIDATION_ERROR)).when(storeValidatorMock).validateStore(newStore, false); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + // Test + testUpdateStoreGenericError(newStore, 400, ErrorType.BAD_REQUEST, VALIDATION_ERROR, false, true); + } + @Test + public void testUpdateStoreStoreNotFound() throws StoreNotFoundException { + Store newStore = new Store(); + + //Mocks + String exceptionMsg = "Store not Found!"; + doThrow(new StoreNotFoundException(exceptionMsg)).when(storeBoMock).findByName(NAME); + + testUpdateStoreGenericError(newStore, 404, ErrorType.NOT_FOUND, exceptionMsg, false, false); + } + + @Test + public void testUpdateStoreNotFoundException() throws UserNotFoundException, StoreNotFoundException { + Store newStore = new Store(); + + // Mocks + doThrow(new UserNotFoundException("")).when(authUtilsMock).getLoggedUser(); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + // Test + testUpdateStoreGenericError(newStore, 500, ErrorType.INTERNAL_SERVER_ERROR, + "There was an error retrieving the user from the database", false, true); + } + + private void testUpdateStoreDataAccessException(Exception exception, String message) { + Store newStore = new Store(); + + //Mocks + try { + doThrow(new DataIntegrityViolationException("", exception)).when(storeBoMock).update(store); + when(storeBoMock.findByName(NAME)).thenReturn(store); + } catch (Exception ex) { + fail("Exception " + ex + " not expected"); + } + + testUpdateStoreGenericError(newStore, 400, ErrorType.BAD_REQUEST, message, true, true); + } + + @Test + public void testUpdateStoreAlreadyExists() { + testUpdateStoreDataAccessException(new MySQLIntegrityConstraintViolationException(), + "There is already a Store with that name/URL registered in the system"); + } + + @Test + public void testUpdateStoreOtherDataException() { + Exception exception = new Exception("Too much content"); + testUpdateStoreDataAccessException(exception, exception.getMessage()); + } + + @Test + public void testUpdateStoreNotKnownException() throws StoreNotFoundException { + Store newStore = new Store(); + String exceptionMsg = "SERVER ERROR"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(storeBoMock).update(store); + when(storeBoMock.findByName(NAME)).thenReturn(store); + testUpdateStoreGenericError(newStore, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg, true, true); + } + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// DELETE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testDeleteStoreNotAllowed() throws StoreNotFoundException { + // Mocks + when(storeRegistrationAuthMock.canDelete(store)).thenReturn(false); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + // Call the method + Response res = storeRegistrationService.deleteStore(NAME); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, + "You are not authorized to delete store " + NAME); + + // Verify mocks + verify(storeBoMock, never()).delete(store); + } + + @Test + public void testDeleteStoreNoErrors() throws StoreNotFoundException { + // Mocks + when(storeRegistrationAuthMock.canDelete(store)).thenReturn(true); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + // Call the method + Response res = storeRegistrationService.deleteStore(NAME); + + // Assertions + assertThat(res.getStatus()).isEqualTo(204); + + // Verify mocks + verify(storeBoMock).delete(store); + } + + private void testDeleteStoreGenericError(int status, ErrorType errorType, + String message, boolean deleteInvoked) { + int deleteTimes = deleteInvoked ? 1 : 0; + + try { + // Mocks + when(storeRegistrationAuthMock.canDelete(store)).thenReturn(true); + + // Call the method + Response res = storeRegistrationService.deleteStore(NAME); + + // Assertions + GenericRestTestUtils.checkAPIError(res, status, errorType, message); + + // Verify mocks + verify(storeBoMock, times(deleteTimes)).delete(store); + } catch (Exception ex) { + fail("Exception " + ex + " not expected."); + } + } + + @Test + public void testDeleteStoreStoreNotFound() throws StoreNotFoundException { + // Mocks + String exceptionMsg = "Store not found"; + doThrow(new StoreNotFoundException(exceptionMsg)).when(storeBoMock).findByName(NAME); + + testDeleteStoreGenericError(404, ErrorType.NOT_FOUND, exceptionMsg, false); + } + + @Test + public void testDeleteStoreNotKnownException() throws StoreNotFoundException { + String exceptionMsg = "SERVER ERROR"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(storeBoMock).delete(store); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + testDeleteStoreGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg, true); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////// GET //////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testGetStoreNotAllowed() throws StoreNotFoundException { + // Mocks + when(storeRegistrationAuthMock.canGet(store)).thenReturn(false); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + // Call the method + Response res = storeRegistrationService.getStore(NAME); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, + "You are not authorized to get store " + NAME); + } + + @Test + public void testGetStoreNoErrors() throws StoreNotFoundException { + // Mocks + when(storeRegistrationAuthMock.canGet(store)).thenReturn(true); + when(storeBoMock.findByName(NAME)).thenReturn(store); + + // Call the method + Response res = storeRegistrationService.getStore(NAME); + + // Assertions + assertThat(res.getStatus()).isEqualTo(200); + assertThat((Store) res.getEntity()).isEqualTo(store); + } + + private void testGetStoreGenericError(int status, ErrorType errorType, String message) { + + try { + // Mocks + when(storeRegistrationAuthMock.canGet(store)).thenReturn(true); + + // Call the method + Response res = storeRegistrationService.getStore(NAME); + + // Assertions + GenericRestTestUtils.checkAPIError(res, status, errorType, message); + } catch (Exception ex) { + fail("Exception " + ex + " not expected."); + } + } + + @Test + public void testGetStoreStoreNotFound() throws StoreNotFoundException { + // Mocks + String exceptionMsg = "Store not found"; + doThrow(new StoreNotFoundException(exceptionMsg)).when(storeBoMock).findByName(NAME); + + testGetStoreGenericError(404, ErrorType.NOT_FOUND, exceptionMsg); + } + + @Test + public void testGetStoreNotKnownException() throws StoreNotFoundException { + String exceptionMsg = "SERVER ERROR"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(storeBoMock).findByName(NAME); + + testGetStoreGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////// LIST //////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testListStoresNotAllowed() { + // Mocks + when(storeRegistrationAuthMock.canList()).thenReturn(false); + + // Call the method + Response res = storeRegistrationService.listStores(0, 100); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to list stores"); + } + + + private void testListStoresInvalidParams(int offset, int max) { + // Mocks + when(storeRegistrationAuthMock.canList()).thenReturn(true); + + // Call the method + Response res = storeRegistrationService.listStores(offset, max); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, OFFSET_MAX_INVALID); + } + + @Test + public void testListStoresInvalidOffset() { + testListStoresInvalidParams(-1, 100); + } + + @Test + public void testListStoresInvalidMax() { + testListStoresInvalidParams(0, -1); + } + + @Test + public void testListStoresInvalidOffsetMax() { + testListStoresInvalidParams(-1, -1); + } + + @Test + public void testListStoresGetNoErrors() { + List stores = new ArrayList(); + for (int i = 0; i < 3; i++) { + Store store = new Store(); + store.setId(i); + stores.add(store); + } + + // Mocks + when(storeRegistrationAuthMock.canList()).thenReturn(true); + when(storeBoMock.getStoresPage(anyInt(), anyInt())).thenReturn(stores); + + // Call the method + int offset = 0; + int max = 100; + Response res = storeRegistrationService.listStores(offset, max); + + // Verify + verify(storeBoMock).getStoresPage(offset, max); + + // Assertations + assertThat(res.getStatus()).isEqualTo(200); + assertThat(((Stores) res.getEntity()).getStores()).isEqualTo(stores); + } + + @Test + public void testListStoresException() { + // Mocks + String exceptionMsg = "exception"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(storeBoMock).getStoresPage(anyInt(), anyInt()); + when(storeRegistrationAuthMock.canList()).thenReturn(true); + + // Call the method + int offset = 0; + int max = 100; + Response res = storeRegistrationService.listStores(offset, max); + + // Verify + verify(storeBoMock).getStoresPage(offset, max); + + // Check exception + GenericRestTestUtils.checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + } } diff --git a/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java index 49a2d1b..3c1b034 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java @@ -82,7 +82,7 @@ private void checkMocksCreateNotCalled() { } @Test - public void testCreateNotAllowed() { + public void testCreateUserNotAllowed() { // Mocks when(userRegistrationAuthMock.canCreate()).thenReturn(false); @@ -99,7 +99,7 @@ public void testCreateNotAllowed() { } @Test - public void testCreateNoErrors() throws ValidationException { + public void testCreateUserNoErrors() throws ValidationException { // Mocks when(userRegistrationAuthMock.canCreate()).thenReturn(true); when(encoder.encode(anyString())).thenReturn(ENCODED_PASSWORD); @@ -122,7 +122,7 @@ public void testCreateNoErrors() throws ValidationException { } @Test - public void testCreateValidationError() throws ValidationException { + public void testCreateUserValidationError() throws ValidationException { // Mock when(userRegistrationAuthMock.canCreate()).thenReturn(true); doThrow(new ValidationException(VALIDATION_ERROR)).when(userValidator).validateUser(user, true); @@ -137,7 +137,7 @@ public void testCreateValidationError() throws ValidationException { GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, VALIDATION_ERROR); } - private void testCreateDataAccessException(Exception exception, String message) throws ValidationException { + private void testCreateUserDataAccessException(Exception exception, String message) throws ValidationException { // Mock when(userRegistrationAuthMock.canCreate()).thenReturn(true); doThrow(new DataIntegrityViolationException("", exception)).when(userBoMock).save(isA(User.class)); @@ -153,19 +153,19 @@ private void testCreateDataAccessException(Exception exception, String message) } @Test - public void testNotAllowedToCreateUserAlreadyExists() throws ValidationException { - testCreateDataAccessException(new MySQLIntegrityConstraintViolationException(), + public void testCreateUserAlreadyExists() throws ValidationException { + testCreateUserDataAccessException(new MySQLIntegrityConstraintViolationException(), "The user and/or the email introduced are already registered in the system"); } @Test - public void testNotAllowedToCreateUserOtherDataException() throws ValidationException { + public void testCreateUserOtherDataException() throws ValidationException { Exception exception = new Exception("Too much content"); - testCreateDataAccessException(exception, exception.getMessage()); + testCreateUserDataAccessException(exception, exception.getMessage()); } @Test - public void testCreteNotKnowException() throws ValidationException { + public void testCreteUpdateNotKnowException() throws ValidationException { // Mock String exceptionMsg = "SERVER ERROR"; when(userRegistrationAuthMock.canCreate()).thenReturn(true); @@ -187,7 +187,7 @@ public void testCreteNotKnowException() throws ValidationException { /////////////////////////////////////////////////////////////////////////////////////// @Test - public void testUpdateNotAllowed() throws UserNotFoundException { + public void testUpdateUserNotAllowed() throws UserNotFoundException { User newUser = new User(); // Mocks @@ -296,7 +296,7 @@ public void testUpdateUserName() throws UserNotFoundException { } @Test - public void testUpdateDisplayName() { + public void testUpdateUserDisplayName() { User newUser = new User(); newUser.setDisplayName("New Display Name"); testUpdateGenericUserNoErrors(newUser); @@ -310,21 +310,21 @@ public void testUpdateEmail() { } @Test - public void testUpdateComapmy() { + public void testUpdateUserComapmy() { User newUser = new User(); newUser.setEmail("New Awesome Company"); testUpdateGenericUserNoErrors(newUser); } @Test - public void testUpdatePassword() { + public void testUpdateUserPassword() { User newUser = new User(); newUser.setPassword("my_new_super_secure_password123456789"); testUpdateGenericUserNoErrors(newUser); } @Test - public void testUpdateValidationError() throws ValidationException, UserNotFoundException { + public void testUpdateUserValidationError() throws ValidationException, UserNotFoundException { User newUser = new User(); // Mock @@ -345,7 +345,7 @@ public void testUpdateValidationError() throws ValidationException, UserNotFound } @Test - public void testUpdateNonExistingUser() throws UserNotFoundException, ValidationException { + public void testUpdateUserNonExistingUser() throws UserNotFoundException, ValidationException { User newUser = new User(); String userNotFoundMsg = "user_name does not exist"; @@ -363,7 +363,7 @@ public void testUpdateNonExistingUser() throws UserNotFoundException, Validation GenericRestTestUtils.checkAPIError(res, 404, ErrorType.NOT_FOUND, userNotFoundMsg); } - private void testDataAccessException(Exception exception, String message) { + private void testUpdateUserDataAccessException(Exception exception, String message) { User newUser = new User(); // Mock @@ -394,20 +394,20 @@ private void testDataAccessException(Exception exception, String message) { } @Test - public void testUpdateViolationIntegration() throws ValidationException { - testDataAccessException(new MySQLIntegrityConstraintViolationException(), + public void testUpdateUserViolationIntegration() throws ValidationException { + testUpdateUserDataAccessException(new MySQLIntegrityConstraintViolationException(), "The user and/or the email introduced are already registered in the system"); } @Test - public void testUpdateOtherDataException() throws ValidationException { + public void testUpdateUserOtherDataException() throws ValidationException { Exception exception = new Exception("Too much content"); - testDataAccessException(exception, exception.getMessage()); + testUpdateUserDataAccessException(exception, exception.getMessage()); } @Test - public void testUpdateNotKnowException() throws ValidationException, UserNotFoundException { + public void testUpdateUserNotKnowException() throws ValidationException, UserNotFoundException { // Mock String exceptionMsg = "SERVER ERROR"; when(userRegistrationAuthMock.canUpdate(user)).thenReturn(true); @@ -430,7 +430,7 @@ public void testUpdateNotKnowException() throws ValidationException, UserNotFoun /////////////////////////////////////////////////////////////////////////////////////// @Test - public void testDeleteNotAllowed() throws UserNotFoundException { + public void testDeleteUserNotAllowed() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); when(userRegistrationAuthMock.canDelete(user)).thenReturn(false); @@ -447,7 +447,7 @@ public void testDeleteNotAllowed() throws UserNotFoundException { } @Test - public void testDeleteNoErrors() throws UserNotFoundException { + public void testDeleteUserNoErrors() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); when(userRegistrationAuthMock.canDelete(user)).thenReturn(true); @@ -464,7 +464,7 @@ public void testDeleteNoErrors() throws UserNotFoundException { } @Test - public void testDeleteNotExisting() throws UserNotFoundException { + public void testDeleteUserNotExisting() throws UserNotFoundException { // Mocks String msg = "User user_name not found"; doThrow(new UserNotFoundException(msg)).when(userBoMock).findByName(USER_NAME); @@ -482,7 +482,7 @@ public void testDeleteNotExisting() throws UserNotFoundException { } @Test - public void testDeleteException() throws UserNotFoundException { + public void testDeleteUserException() throws UserNotFoundException { // Mocks String exceptionMsg = "DB is down!"; doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).delete(user); @@ -506,7 +506,7 @@ public void testDeleteException() throws UserNotFoundException { /////////////////////////////////////////////////////////////////////////////////////// @Test - public void testGetNotAllowed() throws UserNotFoundException { + public void testGetUserNotAllowed() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); when(userRegistrationAuthMock.canGet(user)).thenReturn(false); @@ -519,7 +519,7 @@ public void testGetNotAllowed() throws UserNotFoundException { } @Test - public void testGetNoErrors() throws UserNotFoundException { + public void testGetUserNoErrors() throws UserNotFoundException { // Mocks when(userBoMock.findByName(USER_NAME)).thenReturn(user); when(userRegistrationAuthMock.canGet(user)).thenReturn(true); @@ -533,7 +533,7 @@ public void testGetNoErrors() throws UserNotFoundException { } @Test - public void testGetUserNotFound() throws UserNotFoundException { + public void testGetUserUserNotFound() throws UserNotFoundException { // Mocks String msg = "User user_name not found"; doThrow(new UserNotFoundException(msg)).when(userBoMock).findByName(USER_NAME); @@ -547,7 +547,7 @@ public void testGetUserNotFound() throws UserNotFoundException { } @Test - public void testGetException() throws UserNotFoundException { + public void testGetUserException() throws UserNotFoundException { // Mocks String exceptionMsg = "DB is down!"; doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).findByName(USER_NAME); @@ -569,7 +569,7 @@ public void testGetException() throws UserNotFoundException { /////////////////////////////////////////////////////////////////////////////////////// @Test - public void testListNotAllowed() { + public void testListUsersNotAllowed() { // Mocks when(userRegistrationAuthMock.canList()).thenReturn(false); @@ -580,7 +580,7 @@ public void testListNotAllowed() { GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to list users"); } - private void testListInvalidParams(int offset, int max) { + private void testListUsersInvalidParams(int offset, int max) { // Mocks when(userRegistrationAuthMock.canList()).thenReturn(true); @@ -592,22 +592,22 @@ private void testListInvalidParams(int offset, int max) { } @Test - public void testListInvalidOffset() { - testListInvalidParams(-1, 100); + public void testListUsersInvalidOffset() { + testListUsersInvalidParams(-1, 100); } @Test - public void testListInvalidMax() { - testListInvalidParams(0, -1); + public void testListUsersInvalidMax() { + testListUsersInvalidParams(0, -1); } @Test - public void testListInvalidOffsetMax() { - testListInvalidParams(-1, -1); + public void testListUsersInvalidOffsetMax() { + testListUsersInvalidParams(-1, -1); } @Test - public void testListGetNoErrors() { + public void testListUsersGetNoErrors() { List users = new ArrayList(); for (int i = 0; i < 3; i++) { User user = new User(); @@ -633,7 +633,7 @@ public void testListGetNoErrors() { } @Test - public void testListException() { + public void testListUsersException() { // Mocks String exceptionMsg = "exception"; doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(userBoMock).getUsersPage(anyInt(), anyInt()); From 5956023a9740cc3b2607ea7952ebbc85c7c61484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 22 Dec 2014 14:07:22 +0100 Subject: [PATCH 47/69] Add tests for offerings API. Fix bugs --- .../rest/OfferingRegistrationService.java | 6 +- .../rest/OfferingRegistrationServiceTest.java | 686 ++++++++++++++++++ .../rest/StoreRegistrationServiceTest.java | 1 + 3 files changed, 690 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index 3383c74..9facf7e 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -51,7 +51,7 @@ public class OfferingRegistrationService { @POST @Consumes({"application/xml", "application/json"}) @Path("/") - public Response saveService(@PathParam("storeName") String storeName, Service service) { + public Response createService(@PathParam("storeName") String storeName, Service service) { Response response; try { @@ -158,11 +158,11 @@ public Response deleteService(@PathParam("storeName") String storeName, Store store = storeBo.findByName(storeName); //Check that the Store exists Service service = serviceBo.findByNameAndStore(serviceName, storeName); - if (offeringRegistrationAuth.canUpdate(service)) { + if (offeringRegistrationAuth.canDelete(service)) { serviceBo.delete(service); response = Response.status(Status.NO_CONTENT).build(); } else { - response = ERROR_UTILS.unauthorizedResponse("update offering " + serviceName); + response = ERROR_UTILS.unauthorizedResponse("delete offering " + serviceName); } } catch (ServiceNotFoundException ex) { response = ERROR_UTILS.entityNotFoundResponse(ex); diff --git a/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java new file mode 100644 index 0000000..de8559f --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java @@ -0,0 +1,686 @@ +package org.fiware.apps.marketplace.rest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.fiware.apps.marketplace.bo.ServiceBo; +import org.fiware.apps.marketplace.bo.StoreBo; +import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; +import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.exceptions.ValidationException; +import org.fiware.apps.marketplace.model.ErrorType; +import org.fiware.apps.marketplace.model.Service; +import org.fiware.apps.marketplace.model.Services; +import org.fiware.apps.marketplace.model.Store; +import org.fiware.apps.marketplace.model.User; +import org.fiware.apps.marketplace.model.validators.ServiceValidator; +import org.fiware.apps.marketplace.security.auth.AuthUtils; +import org.fiware.apps.marketplace.security.auth.OfferingRegistrationAuth; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.dao.DataIntegrityViolationException; + +import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; + +public class OfferingRegistrationServiceTest { + + @Mock private StoreBo storeBoMock; + @Mock private ServiceBo serviceBoMock; + @Mock private OfferingRegistrationAuth offeringRegistrationAuthMock; + @Mock private ServiceValidator serviceValidatorMock; + @Mock private AuthUtils authUtilsMock; + + @InjectMocks private OfferingRegistrationService offeringRegistrationService; + + // Default values + private Store store; + private Service service; + private User user; + + // Other useful constants + private static final String STORE_NAME = "WStore"; + private static final String OFFSET_MAX_INVALID = "offset and/or max are not valid"; + private static final String SERVICE_ALREADY_EXISTS = "There is already an Offering in this Store with that name/URL"; + private static final String VALIDATION_ERROR = "Validation Exception"; + private static final String DESCRIPTION = "This is a basic description"; + private static final String SERVICE_NAME = "service"; + private static final String URL = "https://repo.lab.fi-ware.org/description.rdf"; + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////// BASIC METHODS //////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } + + @Before + public void generateValidStore() { + service = new Service(); + service.setDescription(DESCRIPTION); + service.setName(SERVICE_NAME); + service.setUrl(URL); + } + + @Before + public void initAuthUtils() throws UserNotFoundException { + user = new User(); + when(authUtilsMock.getLoggedUser()).thenReturn(user); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// CREATE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testCreateServiceNotAllowed() { + // Mocks + when(offeringRegistrationAuthMock.canCreate()).thenReturn(false); + + // Call the method + Response res = offeringRegistrationService.createService(STORE_NAME, service); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to create offering"); + + // Verify mocks + verify(storeBoMock, never()).save(store); + } + + @Test + public void testCreateServiceNoErrors() throws ValidationException { + // Mocks + when(offeringRegistrationAuthMock.canCreate()).thenReturn(true); + + //Call the method + Response res = offeringRegistrationService.createService(STORE_NAME, service); + + // Verify mocks + verify(serviceValidatorMock).validateService(service, true); + verify(serviceBoMock).save(service); + + // Check the response + assertThat(res.getStatus()).isEqualTo(201); + + // Check that all the parameters of the Store are correct + // (some of them must have been changed by the method) + assertThat(service.getRegistrationDate()).isNotNull(); + assertThat(service.getName()).isEqualTo(SERVICE_NAME); + assertThat(service.getDescription()).isEqualTo(DESCRIPTION); + assertThat(service.getUrl()).isEqualTo(URL); + assertThat(service.getCreator()).isEqualTo(user); + assertThat(service.getLasteditor()).isEqualTo(user); + } + + private void testCreateServiceGenericError(int statusCode, ErrorType errorType, String errorMsg, boolean saveInvoked) { + int saveTimes = saveInvoked ? 1 : 0; + + // Call the method + Response res = offeringRegistrationService.createService(STORE_NAME, service); + + // Verify mocks + try { + verify(serviceValidatorMock).validateService(service, true); + verify(serviceBoMock, times(saveTimes)).save(service); + GenericRestTestUtils.checkAPIError(res, statusCode, errorType, errorMsg); + } catch (ValidationException e) { + // Impossible... + fail("exception " + e + " not expected"); + } + } + + @Test + public void testCreateServiceValidationException() throws ValidationException { + // Mocks + when(offeringRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new ValidationException(VALIDATION_ERROR)).when(serviceValidatorMock).validateService(service, true); + + testCreateServiceGenericError(400, ErrorType.BAD_REQUEST, VALIDATION_ERROR, false); + } + + @Test + public void testCreateServiceUserNotFoundException() throws ValidationException, UserNotFoundException { + // Mocks + when(offeringRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new UserNotFoundException("User Not Found exception")).when(authUtilsMock).getLoggedUser(); + + testCreateServiceGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, + "There was an error retrieving the user from the database", false); + + } + + @Test + public void testCreateServiceStoreNotFoundException() throws ValidationException, StoreNotFoundException { + // Mocks + String exceptionMsg = "Store Not Found!"; + when(offeringRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new StoreNotFoundException(exceptionMsg)).when(storeBoMock).findByName(STORE_NAME); + + testCreateServiceGenericError(404, ErrorType.NOT_FOUND, exceptionMsg, false); + } + + private void testCreateServiceDataAccessException(Exception exception, String message) throws ValidationException { + // Mock + when(offeringRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new DataIntegrityViolationException("", exception)).when(serviceBoMock).save(service); + + testCreateServiceGenericError(400, ErrorType.BAD_REQUEST, message, true); + } + + @Test + public void testCreateServiceAlreadyExists() throws ValidationException { + testCreateServiceDataAccessException(new MySQLIntegrityConstraintViolationException(), + SERVICE_ALREADY_EXISTS); + } + + @Test + public void testCreateServiceOtherDataException() throws ValidationException { + Exception exception = new Exception("Too much content"); + testCreateServiceDataAccessException(exception, exception.getMessage()); + } + + @Test + public void testCreteServiceNotKnowException() throws ValidationException { + // Mock + String exceptionMsg = "SERVER ERROR"; + when(offeringRegistrationAuthMock.canCreate()).thenReturn(true); + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(serviceBoMock).save(service); + + testCreateServiceGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg, true); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// UPDATE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testUpdateServiceNotAllowed() throws ServiceNotFoundException, StoreNotFoundException { + Service newService = new Service(); + + // Mocks + when(offeringRegistrationAuthMock.canUpdate(service)).thenReturn(false); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + // Call the method + Response res = offeringRegistrationService.updateService(STORE_NAME, SERVICE_NAME, newService); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, + "You are not authorized to update offering " + SERVICE_NAME); + + // Verify mocks + verify(serviceBoMock, never()).update(service); + } + + private void testUpdateServiceField(Service newService) { + try { + // Mock + when(offeringRegistrationAuthMock.canUpdate(service)).thenReturn(true); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + // Call the method + Response res = offeringRegistrationService.updateService(STORE_NAME, SERVICE_NAME, newService); + + // Verify mocks + verify(serviceValidatorMock).validateService(newService, false); + verify(serviceBoMock).update(service); + + // Assertions + assertThat(res.getStatus()).isEqualTo(200); + + // New values + String newStoreName = newService.getName() != null ? newService.getName() : service.getName(); + assertThat(service.getName()).isEqualTo(newStoreName); + + String newStoreUrl = newService.getUrl() != null ? newService.getUrl() : service.getUrl(); + assertThat(service.getUrl()).isEqualTo(newStoreUrl); + + String newStoreDescription = newService.getDescription() != null ? newService.getDescription() : service.getDescription(); + assertThat(service.getDescription()).isEqualTo(newStoreDescription); + } catch (Exception ex) { + // It's not supposed to happen + fail("Exception " + ex + " is not supposed to happen"); + } + } + + @Test + public void testUpdateServiceName() { + Service newService = new Service(); + newService.setName("new_name"); + testUpdateServiceField(newService); + } + + @Test + public void testUpdateServiceUrl() { + Service newService = new Service(); + newService.setUrl("https://repo.lab.fi-ware.org/new_description.rdf"); + testUpdateServiceField(newService); + } + + @Test + public void testUpdateServiceDescription() { + Service newService = new Service(); + newService.setDescription("New Description"); + testUpdateServiceField(newService); + } + + private void testUpdateServiceGenericError(Service newService, int status, ErrorType errorType, + String message, boolean updateInvoked, boolean verifyInvoked) { + int updateTimes = updateInvoked ? 1 : 0; + int verifyTimes = verifyInvoked ? 1 : 0; + + try { + // Mocks + when(offeringRegistrationAuthMock.canUpdate(service)).thenReturn(true); + + // Call the method + Response res = offeringRegistrationService.updateService(STORE_NAME, SERVICE_NAME, newService); + + // Assertions + GenericRestTestUtils.checkAPIError(res, status, errorType, message); + + // Verify mocks + verify(serviceValidatorMock, times(verifyTimes)).validateService(newService, false); + verify(serviceBoMock, times(updateTimes)).update(service); + } catch (Exception ex) { + fail("Exception " + ex + " not expected."); + } + } + + + @Test + public void testUpdateServiceValidationException() throws ValidationException, + StoreNotFoundException, ServiceNotFoundException { + Service newService = new Service(); + + // Mocks + doThrow(new ValidationException(VALIDATION_ERROR)).when(serviceValidatorMock).validateService( + newService, false); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + // Test + testUpdateServiceGenericError(newService, 400, ErrorType.BAD_REQUEST, + VALIDATION_ERROR, false, true); + } + + @Test + public void testUpdateServiceStoreNotFound() throws StoreNotFoundException, ServiceNotFoundException { + Service newService = new Service(); + + //Mocks + String exceptionMsg = "Store not Found!"; + doThrow(new StoreNotFoundException(exceptionMsg)).when(serviceBoMock).findByNameAndStore(SERVICE_NAME, STORE_NAME); + + testUpdateServiceGenericError(newService, 404, ErrorType.NOT_FOUND, exceptionMsg, false, false); + } + + @Test + public void testUpdateServiceServiceNotFound() throws StoreNotFoundException, ServiceNotFoundException { + Service newService = new Service(); + + //Mocks + String exceptionMsg = "Service not Found!"; + doThrow(new ServiceNotFoundException(exceptionMsg)).when(serviceBoMock).findByNameAndStore(SERVICE_NAME, STORE_NAME); + + testUpdateServiceGenericError(newService, 404, ErrorType.NOT_FOUND, exceptionMsg, false, false); + } + + @Test + public void testUpdateServiceNotFoundException() throws UserNotFoundException, StoreNotFoundException, + ServiceNotFoundException { + Service newService = new Service(); + + // Mocks + doThrow(new UserNotFoundException("")).when(authUtilsMock).getLoggedUser(); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + // Test + testUpdateServiceGenericError(newService, 500, ErrorType.INTERNAL_SERVER_ERROR, + "There was an error retrieving the user from the database", false, true); + } + + private void testUpdateServiceDataAccessException(Exception exception, String message) { + Service newService = new Service(); + + //Mocks + try { + doThrow(new DataIntegrityViolationException("", exception)).when(serviceBoMock).update(service); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + } catch (Exception ex) { + fail("Exception " + ex + " not expected"); + } + + testUpdateServiceGenericError(newService, 400, ErrorType.BAD_REQUEST, message, true, true); + } + + @Test + public void testUpdateServiceAlreadyExists() { + testUpdateServiceDataAccessException(new MySQLIntegrityConstraintViolationException(), + SERVICE_ALREADY_EXISTS); + } + + @Test + public void testUpdateServiceOtherDataException() { + Exception exception = new Exception("Too much content"); + testUpdateServiceDataAccessException(exception, exception.getMessage()); + } + + @Test + public void testUpdateServiceNotKnownException() throws StoreNotFoundException, ServiceNotFoundException { + Service newService = new Service(); + String exceptionMsg = "SERVER ERROR"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(serviceBoMock).update(service); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + testUpdateServiceGenericError(newService, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg, true, true); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////// DELETE /////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testDeleteServiceNotAllowed() throws StoreNotFoundException, ServiceNotFoundException { + // Mocks + when(offeringRegistrationAuthMock.canDelete(service)).thenReturn(false); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + // Call the method + Response res = offeringRegistrationService.deleteService(STORE_NAME, SERVICE_NAME); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, + "You are not authorized to delete offering " + SERVICE_NAME); + + // Verify mocks + verify(storeBoMock, never()).delete(store); + } + + @Test + public void testDeleteServiceNoErrors() throws StoreNotFoundException, ServiceNotFoundException { + // Mocks + when(offeringRegistrationAuthMock.canDelete(service)).thenReturn(true); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + // Call the method + Response res = offeringRegistrationService.deleteService(STORE_NAME, SERVICE_NAME); + + // Assertions + assertThat(res.getStatus()).isEqualTo(204); + + // Verify mocks + verify(serviceBoMock).delete(service); + } + + private void testDeleteServiceGenericError(int status, ErrorType errorType, + String message, boolean deleteInvoked) { + int deleteTimes = deleteInvoked ? 1 : 0; + + try { + // Mocks + when(offeringRegistrationAuthMock.canDelete(service)).thenReturn(true); + + // Call the method + Response res = offeringRegistrationService.deleteService(STORE_NAME, SERVICE_NAME); + + // Assertions + GenericRestTestUtils.checkAPIError(res, status, errorType, message); + + // Verify mocks + verify(serviceBoMock, times(deleteTimes)).delete(service); + } catch (Exception ex) { + fail("Exception " + ex + " not expected."); + } + } + + @Test + public void testDeleteServiceStoreNotFound() throws StoreNotFoundException, ServiceNotFoundException { + // Mocks + String exceptionMsg = "Store not found"; + doThrow(new StoreNotFoundException(exceptionMsg)).when(serviceBoMock).findByNameAndStore(SERVICE_NAME, STORE_NAME); + + testDeleteServiceGenericError(404, ErrorType.NOT_FOUND, exceptionMsg, false); + } + + @Test + public void testDeleteServiceServiceNotFound() throws StoreNotFoundException, ServiceNotFoundException { + // Mocks + String exceptionMsg = "Service not found"; + doThrow(new ServiceNotFoundException(exceptionMsg)).when(serviceBoMock).findByNameAndStore(SERVICE_NAME, STORE_NAME); + + testDeleteServiceGenericError(404, ErrorType.NOT_FOUND, exceptionMsg, false); + } + + @Test + public void testDeleteServiceNotKnownException() throws StoreNotFoundException, ServiceNotFoundException { + String exceptionMsg = "SERVER ERROR"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(serviceBoMock).delete(service); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + testDeleteServiceGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg, true); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////// GET //////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testGetServiceNotAllowed() throws StoreNotFoundException, ServiceNotFoundException { + // Mocks + when(offeringRegistrationAuthMock.canGet(service)).thenReturn(false); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + // Call the method + Response res = offeringRegistrationService.getService(STORE_NAME, SERVICE_NAME); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, + "You are not authorized to get offering " + SERVICE_NAME); + } + + @Test + public void testGetServiceNoErrors() throws StoreNotFoundException, ServiceNotFoundException { + // Mocks + when(offeringRegistrationAuthMock.canGet(service)).thenReturn(true); + when(serviceBoMock.findByNameAndStore(SERVICE_NAME, STORE_NAME)).thenReturn(service); + + // Call the method + Response res = offeringRegistrationService.getService(STORE_NAME, SERVICE_NAME); + + // Assertions + assertThat(res.getStatus()).isEqualTo(200); + assertThat((Service) res.getEntity()).isEqualTo(service); + } + + private void testGetServiceGenericError(int status, ErrorType errorType, String message) { + + try { + // Mocks + when(offeringRegistrationAuthMock.canGet(service)).thenReturn(true); + + // Call the method + Response res = offeringRegistrationService.getService(STORE_NAME, SERVICE_NAME); + + // Assertions + GenericRestTestUtils.checkAPIError(res, status, errorType, message); + } catch (Exception ex) { + fail("Exception " + ex + " not expected."); + } + } + + @Test + public void testGetServiceStoreNotFound() throws StoreNotFoundException, ServiceNotFoundException { + // Mocks + String exceptionMsg = "Store not found"; + doThrow(new StoreNotFoundException( + exceptionMsg)).when(serviceBoMock).findByNameAndStore(SERVICE_NAME, STORE_NAME); + + testGetServiceGenericError(404, ErrorType.NOT_FOUND, exceptionMsg); + } + + @Test + public void testGetServiceNotKnownException() throws StoreNotFoundException, ServiceNotFoundException { + String exceptionMsg = "SERVER ERROR"; + doThrow(new RuntimeException("", + new Exception(exceptionMsg))).when(serviceBoMock).findByNameAndStore(SERVICE_NAME, STORE_NAME); + + testGetServiceGenericError(500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + } + + + /////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////// LIST //////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + + @Test + public void testListServicesNotAllowed() { + // Mocks + when(offeringRegistrationAuthMock.canList()).thenReturn(false); + + // Call the method + Response res = offeringRegistrationService.listServices(STORE_NAME, 0, 100); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to list offerings"); + } + + private void testListServicesInvalidParams(int offset, int max) { + // Mocks + when(offeringRegistrationAuthMock.canList()).thenReturn(true); + + // Call the method + Response res = offeringRegistrationService.listServices(STORE_NAME, offset, max); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, OFFSET_MAX_INVALID); + } + + @Test + public void testListServicesInvalidOffset() { + testListServicesInvalidParams(-1, 100); + } + + @Test + public void testListServicesInvalidMax() { + testListServicesInvalidParams(0, 0); + } + + @Test + public void testListServicesInvalidOffsetMax() { + testListServicesInvalidParams(-1, -1); + } + + private void testListServicesNoError(List storeServices, List returnedServices, + int offset, int max) { + store = new Store(); + + // Mocks + try { + when(storeBoMock.findByName(STORE_NAME)).thenReturn(store); + when(offeringRegistrationAuthMock.canList()).thenReturn(true); + store.setServices(storeServices); + } catch(Exception ex) { + fail ("Exception " + ex + " not expected"); + } + + // Call the method + Response res = offeringRegistrationService.listServices(STORE_NAME, offset, max); + + // Assertations + assertThat(res.getStatus()).isEqualTo(200); + assertThat(((Services) res.getEntity()).getServices()).isEqualTo(returnedServices); + } + + private List generateServicesList() { + List services = new ArrayList(); + for (int i = 0; i < 10; i++) { + Service service = new Service(); + services.add(service); + } + + return services; + } + + private void testListServicesOnlyOneElement(int elementIndex) { + List storeServices = generateServicesList(); + + List returnedServices = new ArrayList(); + returnedServices.add(storeServices.get(elementIndex)); + + testListServicesNoError(storeServices, returnedServices, elementIndex, 1); + } + + @Test + public void testListServicesOnlyFirst() { + testListServicesOnlyOneElement(0); + } + + @Test + public void testListServicesOnlyFifth() { + testListServicesOnlyOneElement(5); + } + + private void testListServicesInRange(int initial, int end) { + List storeServices = generateServicesList(); + + List returnedServices = new ArrayList(); + for (int i = initial; i < end; i++) { + returnedServices.add(storeServices.get(i)); + } + + testListServicesNoError(storeServices, returnedServices, initial, end - initial); + } + + @Test + public void testListServicesFirstTwo() { + testListServicesInRange(0, 2); + } + + @Test + public void testListServicesFirstFive() { + testListServicesInRange(0, 5); + } + + @Test + public void testListServicesTwoThirdAndFoth() { + testListServicesInRange(2, 4); + } + + @Test + public void testListServicesBigMax() { + List storeServices = generateServicesList(); + testListServicesNoError(storeServices, storeServices, 0, 15); + } + + @Test + public void testListServicesBigMaxAndOffsetIsNotZero() { + List storeServices = generateServicesList(); + List returnedServices = new ArrayList(); + + for (int i = 1; i < storeServices.size(); i++) { + returnedServices.add(storeServices.get(i)); + } + + testListServicesNoError(storeServices, returnedServices, 1, 15); + } + +} diff --git a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java index 0c18578..0d49346 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java @@ -68,6 +68,7 @@ public void generateValidStore() { @Before public void initAuthUtils() throws UserNotFoundException { + user = new User(); when(authUtilsMock.getLoggedUser()).thenReturn(user); } From 24bf3b14c686a9b98a8099c6e73953b66538215b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 22 Dec 2014 15:09:07 +0100 Subject: [PATCH 48/69] Minor improvement --- .../apps/marketplace/rest/OfferingRegistrationServiceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java index de8559f..3797f13 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java @@ -614,6 +614,7 @@ private List generateServicesList() { List services = new ArrayList(); for (int i = 0; i < 10; i++) { Service service = new Service(); + service.setId(i); services.add(service); } From 4f42a4d6c5ce6ff09093df1128f446ac86887780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 22 Dec 2014 17:29:59 +0100 Subject: [PATCH 49/69] Reduce the amount of data returned in each request --- .../apps/marketplace/model/Service.java | 9 ++++++-- .../fiware/apps/marketplace/model/Store.java | 4 ++++ .../utils/xmladapters/StoreXMLAdapter.java | 20 +++++++++++++++++ .../utils/xmladapters/UserXMLAdapter.java | 22 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapter.java create mode 100644 src/main/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapter.java diff --git a/src/main/java/org/fiware/apps/marketplace/model/Service.java b/src/main/java/org/fiware/apps/marketplace/model/Service.java index 1adc636..1a5395d 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Service.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Service.java @@ -16,8 +16,10 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.fiware.apps.marketplace.utils.xmladapters.StoreXMLAdapter; +import org.fiware.apps.marketplace.utils.xmladapters.UserXMLAdapter; import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; @Entity @@ -77,7 +79,8 @@ public void setDescription(String description) { this.description = description; } - @XmlTransient + @XmlElement + @XmlJavaTypeAdapter(StoreXMLAdapter.class) @ManyToOne(optional = false) @JoinColumn(name = "store", nullable=false) public Store getStore() { @@ -89,6 +92,7 @@ public void setStore(Store store) { } @XmlElement + @XmlJavaTypeAdapter(UserXMLAdapter.class) @ManyToOne(optional = false) @JoinColumn(name = "creator", nullable=false) public User getCreator() { @@ -100,6 +104,7 @@ public void setCreator(User creator) { } @XmlElement + @XmlJavaTypeAdapter(UserXMLAdapter.class) @ManyToOne(optional = false) @JoinColumn(name = "last_editor", nullable=false) public User getLasteditor() { diff --git a/src/main/java/org/fiware/apps/marketplace/model/Store.java b/src/main/java/org/fiware/apps/marketplace/model/Store.java index 7073c8b..5573549 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Store.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Store.java @@ -20,7 +20,9 @@ import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.fiware.apps.marketplace.utils.xmladapters.UserXMLAdapter; import org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes; @@ -83,6 +85,7 @@ public void setDescription(String description) { } @XmlElement + @XmlJavaTypeAdapter(UserXMLAdapter.class) @ManyToOne(optional = false) @JoinColumn(name = "creator", nullable=false) public User getCreator() { @@ -94,6 +97,7 @@ public void setCreator(User creator) { } @XmlElement + @XmlJavaTypeAdapter(UserXMLAdapter.class) @ManyToOne(optional = false) @JoinColumn(name = "last_editor", nullable=false) public User getLasteditor() { diff --git a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapter.java new file mode 100644 index 0000000..c63bb9c --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapter.java @@ -0,0 +1,20 @@ +package org.fiware.apps.marketplace.utils.xmladapters; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +import org.fiware.apps.marketplace.model.Store; + +public class StoreXMLAdapter extends XmlAdapter{ + + @Override + public Store unmarshal(String value) throws Exception { + // Not needed... + return null; + } + + @Override + public String marshal(Store store) throws Exception { + return store.getName(); + } + +} diff --git a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapter.java new file mode 100644 index 0000000..fe4ad1a --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapter.java @@ -0,0 +1,22 @@ +package org.fiware.apps.marketplace.utils.xmladapters; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +import org.fiware.apps.marketplace.model.User; + +public class UserXMLAdapter extends XmlAdapter{ + + @Override + public User unmarshal(String value) throws Exception { + // Not needed... + return null; + } + + @Override + public String marshal(User user) throws Exception { + return user.getUserName(); + } + + + +} From 122e9c04ce2b747cde37f9226519c2049bd0dae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 22 Dec 2014 18:02:11 +0100 Subject: [PATCH 50/69] Set fields to null to avoid returning them in the response --- .../rest/UserRegistrationService.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 5a9ba0b..3f56530 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -159,10 +159,15 @@ public Response getUser(@PathParam("username") String username) { Response response; try { - User localuser = userBo.findByName(username); - - if (userRegistrationAuth.canGet(localuser)) { - response = Response.status(Status.OK).entity(localuser).build(); + User user = userBo.findByName(username); + + if (userRegistrationAuth.canGet(user)) { + // If the value of the attribute is null, the + // attribute won't be returned in the response + // Note: We are not saving the user, otherwise the information will be lost + user.setPassword(null); + user.setEmail(null); + response = Response.status(Status.OK).entity(user).build(); } else { response = ERROR_UTILS.unauthorizedResponse("get user " + username); } @@ -189,6 +194,15 @@ public Response listUsers(@DefaultValue("0") @QueryParam("offset") int offset, try { if (userRegistrationAuth.canList()) { List users = userBo.getUsersPage(offset, max); + + // If the value of the attribute is null, the + // attribute won't be returned in the response + // Note: We are not saving the users, otherwise the information will be lost + for (User user: users) { + user.setPassword(null); + user.setEmail(null); + } + return Response.status(Status.OK).entity(new Users(users)).build(); } else { response = ERROR_UTILS.unauthorizedResponse("list users"); From 3326434b356be61d687fba7eef0033182d1bd787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 22 Dec 2014 18:05:31 +0100 Subject: [PATCH 51/69] New API to retrieve all the registered offerings (regardless of the store) --- .../fiware/apps/marketplace/bo/ServiceBo.java | 4 + .../marketplace/bo/impl/ServiceBoImpl.java | 12 ++ .../apps/marketplace/dao/ServiceDao.java | 4 + .../marketplace/dao/impl/ServiceDaoImpl.java | 13 ++ .../marketplace/rest/AllOfferingsService.java | 59 +++++++++ .../apps/marketplace/rest/ErrorUtils.java | 7 +- .../rest/OfferingRegistrationService.java | 30 +++-- .../auth/OfferingRegistrationAuth.java | 10 ++ src/main/webapp/WEB-INF/web.xml | 6 +- .../rest/AllOfferingsServiceTest.java | 122 ++++++++++++++++++ .../rest/OfferingRegistrationServiceTest.java | 14 +- .../rest/StoreRegistrationServiceTest.java | 2 +- 12 files changed, 258 insertions(+), 25 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/rest/AllOfferingsService.java create mode 100644 src/test/java/org/fiware/apps/marketplace/rest/AllOfferingsServiceTest.java diff --git a/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java b/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java index e9b759f..4e6b6ba 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java @@ -1,5 +1,7 @@ package org.fiware.apps.marketplace.bo; +import java.util.List; + import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; import org.fiware.apps.marketplace.model.Service; @@ -11,4 +13,6 @@ public interface ServiceBo { Service findByName(String name) throws ServiceNotFoundException; Service findByNameAndStore(String name, String store) throws ServiceNotFoundException, StoreNotFoundException; Service findById(Integer id) throws ServiceNotFoundException; + List getAllServices(); + List getServicesPage(int offset, int max); } diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java index 27a1dc9..a2fbf5c 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java @@ -1,5 +1,7 @@ package org.fiware.apps.marketplace.bo.impl; +import java.util.List; + import org.fiware.apps.marketplace.bo.ServiceBo; import org.fiware.apps.marketplace.dao.ServiceDao; import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; @@ -55,5 +57,15 @@ public Service findByName(String name) throws ServiceNotFoundException { public Service findByNameAndStore(String name, String store) throws ServiceNotFoundException, StoreNotFoundException { return serviceDao.findByNameAndStore(name, store); } + + @Override + public List getAllServices() { + return serviceDao.getAllServices(); + } + + @Override + public List getServicesPage(int offset, int max) { + return serviceDao.getServicesPage(offset, max); + } } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java b/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java index 8e50f18..b3525b5 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java @@ -1,5 +1,7 @@ package org.fiware.apps.marketplace.dao; +import java.util.List; + import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; import org.fiware.apps.marketplace.model.Service; @@ -10,4 +12,6 @@ public interface ServiceDao { Service findByName(String name) throws ServiceNotFoundException; Service findByNameAndStore(String name, String store) throws ServiceNotFoundException; Service findById(Integer id); + List getAllServices(); + List getServicesPage(int offset, int max); } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java index ec83ba4..7399295 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java @@ -6,6 +6,7 @@ import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.utils.MarketplaceHibernateDao; +import org.hibernate.criterion.DetachedCriteria; import org.springframework.stereotype.Repository; @Repository("serviceDao") @@ -53,5 +54,17 @@ public Service findByNameAndStore(String name, String store) throws ServiceNotFo Object[] params = {name , store}; return this.findByQuery("from Service where name = ? and store.name = ?", params); } + + @Override + public List getAllServices() { + return getHibernateTemplate().loadAll(Service.class); + } + + @SuppressWarnings("unchecked") + @Override + public List getServicesPage(int offset, int max) { + return (List) getHibernateTemplate().findByCriteria( + DetachedCriteria.forClass(Service.class), offset, max); + } } diff --git a/src/main/java/org/fiware/apps/marketplace/rest/AllOfferingsService.java b/src/main/java/org/fiware/apps/marketplace/rest/AllOfferingsService.java new file mode 100644 index 0000000..654d129 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/rest/AllOfferingsService.java @@ -0,0 +1,59 @@ +package org.fiware.apps.marketplace.rest; + +import java.util.List; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.fiware.apps.marketplace.bo.ServiceBo; +import org.fiware.apps.marketplace.model.Service; +import org.fiware.apps.marketplace.model.Services; +import org.fiware.apps.marketplace.security.auth.OfferingRegistrationAuth; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +@Path("/offerings") +public class AllOfferingsService { + + // OBJECT ATTRIBUTES // + @Autowired private ServiceBo serviceBo; + @Autowired private OfferingRegistrationAuth offeringRegistrationAuth; + + // CLASS ATTRIBUTES // + private static final ErrorUtils ERROR_UTILS = new ErrorUtils(); + + + @GET + @Produces({"application/xml", "application/json"}) + @Path("/") + public Response listServices(@DefaultValue("0") @QueryParam("offset") int offset, + @DefaultValue("100") @QueryParam("max") int max) { + Response response; + + if (offset < 0 || max <= 0) { + // Offset and Max should be checked + response = ERROR_UTILS.badRequestResponse("offset and/or max are not valid"); + } else { + if (offeringRegistrationAuth.canList()) { + try { + List servicesPage = serviceBo.getServicesPage(offset, max); + Services returnedServices = new Services(); + returnedServices.setServices(servicesPage); + response = Response.status(Status.OK).entity(returnedServices).build(); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex); + } + } else { + response = ERROR_UTILS.unauthorizedResponse("list offerings"); + } + } + + return response; + } +} diff --git a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java index a502223..0ec3dd4 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java @@ -13,13 +13,18 @@ public class ErrorUtils { private String contraintViolationMessage; + public ErrorUtils() { + this.contraintViolationMessage = null; + } + public ErrorUtils(String contraintViolationMessage) { this.contraintViolationMessage = contraintViolationMessage; } public Response badRequestResponse(DataAccessException ex) { String message; - if (ex.getRootCause() instanceof MySQLIntegrityConstraintViolationException) { + if (ex.getRootCause() instanceof MySQLIntegrityConstraintViolationException + && this.contraintViolationMessage != null) { message = this.contraintViolationMessage; } else { message = ex.getRootCause().getMessage(); diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index 9facf7e..b1691c1 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -34,7 +34,7 @@ import org.springframework.stereotype.Component; @Component -@Path("/store/{storeName}/offering") +@Path("/store/{storeName}/offering/") public class OfferingRegistrationService { // OBJECT ATTRIBUTES // @@ -46,7 +46,7 @@ public class OfferingRegistrationService { // CLASS ATTRIBUTES // private static final ErrorUtils ERROR_UTILS = new ErrorUtils( - "There is already an Offering in this Store with that name/URL"); + "There is already an Offering in this Store with that name/URL"); @POST @Consumes({"application/xml", "application/json"}) @@ -206,7 +206,7 @@ public Response getService(@PathParam("storeName") String storeName, @GET @Produces({"application/xml", "application/json"}) @Path("/") - public Response listServices(@PathParam("storeName") String storeName, + public Response listServicesInStore(@PathParam("storeName") String storeName, @DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("100") @QueryParam("max") int max) { Response response; @@ -215,10 +215,11 @@ public Response listServices(@PathParam("storeName") String storeName, // Offset and Max should be checked response = ERROR_UTILS.badRequestResponse("offset and/or max are not valid"); } else { - if (offeringRegistrationAuth.canList()) { - try { - int toIndex; - Store store = storeBo.findByName(storeName); + try { + int toIndex; + Store store = storeBo.findByName(storeName); + + if (offeringRegistrationAuth.canList(store)) { Services returnedServices = new Services(); List allServices = store.getServices(); @@ -233,17 +234,18 @@ public Response listServices(@PathParam("storeName") String storeName, } response = Response.status(Status.OK).entity(returnedServices).build(); - } catch (StoreNotFoundException ex) { - response = ERROR_UTILS.entityNotFoundResponse(ex); - } catch (Exception ex) { - response = ERROR_UTILS.internalServerError(ex); + } else { + response = ERROR_UTILS.unauthorizedResponse("list offerings"); } - } else { - response = ERROR_UTILS.unauthorizedResponse("list offerings"); + + + } catch (StoreNotFoundException ex) { + response = ERROR_UTILS.entityNotFoundResponse(ex); + } catch (Exception ex) { + response = ERROR_UTILS.internalServerError(ex); } } return response; - } } diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java index b9c5911..7fa1ee0 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java @@ -1,5 +1,6 @@ package org.fiware.apps.marketplace.security.auth; +import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Service; @@ -11,5 +12,14 @@ public class OfferingRegistrationAuth extends RegistrationAuth { protected User getEntityOwner(Service service) { return service.getCreator(); } + + /** + * Method to know if a user can list the offerings belonging to a Store + * @param store The store whose offerings will be listed + * @return By default it returns true + */ + public boolean canList(Store store) { + return true; + } } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index f119502..455b28d 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -18,10 +18,12 @@ resteasy.resources - org.fiware.apps.marketplace.rest.StoreRegistrationService, + + org.fiware.apps.marketplace.rest.AllOfferingsService, + org.fiware.apps.marketplace.rest.OfferingRegistrationService, + org.fiware.apps.marketplace.rest.StoreRegistrationService, org.fiware.apps.marketplace.rest.SearchService, org.fiware.apps.marketplace.rest.UserRegistrationService, - org.fiware.apps.marketplace.rest.OfferingRegistrationService, org.fiware.apps.marketplace.rest.RatingService, org.fiware.apps.marketplace.rest.RecommendationService, org.fiware.apps.marketplace.rest.CompareService, diff --git a/src/test/java/org/fiware/apps/marketplace/rest/AllOfferingsServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/AllOfferingsServiceTest.java new file mode 100644 index 0000000..c982f71 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/rest/AllOfferingsServiceTest.java @@ -0,0 +1,122 @@ +package org.fiware.apps.marketplace.rest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.fiware.apps.marketplace.bo.ServiceBo; +import org.fiware.apps.marketplace.model.ErrorType; +import org.fiware.apps.marketplace.model.Service; +import org.fiware.apps.marketplace.model.Services; +import org.fiware.apps.marketplace.security.auth.OfferingRegistrationAuth; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class AllOfferingsServiceTest { + + @Mock private ServiceBo serviceBoMock; + @Mock private OfferingRegistrationAuth offeringRegistrationAuthMock; + + @InjectMocks private AllOfferingsService allOfferingsService; + + private static final String OFFSET_MAX_INVALID = "offset and/or max are not valid"; + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testListAllServicesNotAllowed() { + // Mocks + when(offeringRegistrationAuthMock.canList()).thenReturn(false); + + // Call the method + Response res = allOfferingsService.listServices(0, 100); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to list offerings"); + } + + + private void testListAllServicesInvalidParams(int offset, int max) { + // Mocks + when(offeringRegistrationAuthMock.canList()).thenReturn(true); + + // Call the method + Response res = allOfferingsService.listServices(offset, max); + + // Assertions + GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, OFFSET_MAX_INVALID); + } + + @Test + public void testListAllServicesInvalidOffset() { + testListAllServicesInvalidParams(-1, 100); + } + + @Test + public void testListAllServicesInvalidMax() { + testListAllServicesInvalidParams(0, -1); + } + + @Test + public void testListAllServicesInvalidOffsetMax() { + testListAllServicesInvalidParams(-1, -1); + } + + @Test + public void testListAllServicesGetNoErrors() { + List services = new ArrayList(); + for (int i = 0; i < 3; i++) { + Service service = new Service(); + service.setId(i); + services.add(service); + } + + // Mocks + when(offeringRegistrationAuthMock.canList()).thenReturn(true); + when(serviceBoMock.getServicesPage(anyInt(), anyInt())).thenReturn(services); + + // Call the method + int offset = 0; + int max = 100; + Response res = allOfferingsService.listServices(offset, max); + + // Verify + verify(serviceBoMock).getServicesPage(offset, max); + + // Assertions + assertThat(res.getStatus()).isEqualTo(200); + assertThat(((Services) res.getEntity()).getServices()).isEqualTo(services); + } + + @Test + public void testListAllServicesException() { + // Mocks + String exceptionMsg = "exception"; + doThrow(new RuntimeException("", new Exception(exceptionMsg))).when(serviceBoMock).getServicesPage(anyInt(), anyInt()); + when(offeringRegistrationAuthMock.canList()).thenReturn(true); + + // Call the method + int offset = 0; + int max = 100; + Response res = allOfferingsService.listServices(offset, max); + + // Verify + verify(serviceBoMock).getServicesPage(offset, max); + + // Check exception + GenericRestTestUtils.checkAPIError(res, 500, ErrorType.INTERNAL_SERVER_ERROR, exceptionMsg); + } +} diff --git a/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java index 3797f13..1d150e7 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java @@ -554,10 +554,10 @@ public void testGetServiceNotKnownException() throws StoreNotFoundException, Ser @Test public void testListServicesNotAllowed() { // Mocks - when(offeringRegistrationAuthMock.canList()).thenReturn(false); + when(offeringRegistrationAuthMock.canList(store)).thenReturn(false); // Call the method - Response res = offeringRegistrationService.listServices(STORE_NAME, 0, 100); + Response res = offeringRegistrationService.listServicesInStore(STORE_NAME, 0, 100); // Assertions GenericRestTestUtils.checkAPIError(res, 401, ErrorType.UNAUTHORIZED, "You are not authorized to list offerings"); @@ -565,10 +565,10 @@ public void testListServicesNotAllowed() { private void testListServicesInvalidParams(int offset, int max) { // Mocks - when(offeringRegistrationAuthMock.canList()).thenReturn(true); + when(offeringRegistrationAuthMock.canList(store)).thenReturn(true); // Call the method - Response res = offeringRegistrationService.listServices(STORE_NAME, offset, max); + Response res = offeringRegistrationService.listServicesInStore(STORE_NAME, offset, max); // Assertions GenericRestTestUtils.checkAPIError(res, 400, ErrorType.BAD_REQUEST, OFFSET_MAX_INVALID); @@ -596,16 +596,16 @@ private void testListServicesNoError(List storeServices, List // Mocks try { when(storeBoMock.findByName(STORE_NAME)).thenReturn(store); - when(offeringRegistrationAuthMock.canList()).thenReturn(true); + when(offeringRegistrationAuthMock.canList(store)).thenReturn(true); store.setServices(storeServices); } catch(Exception ex) { fail ("Exception " + ex + " not expected"); } // Call the method - Response res = offeringRegistrationService.listServices(STORE_NAME, offset, max); + Response res = offeringRegistrationService.listServicesInStore(STORE_NAME, offset, max); - // Assertations + // Assertions assertThat(res.getStatus()).isEqualTo(200); assertThat(((Services) res.getEntity()).getServices()).isEqualTo(returnedServices); } diff --git a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java index 0d49346..8b871e2 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java @@ -563,7 +563,7 @@ public void testListStoresGetNoErrors() { // Verify verify(storeBoMock).getStoresPage(offset, max); - // Assertations + // Assertions assertThat(res.getStatus()).isEqualTo(200); assertThat(((Stores) res.getEntity()).getStores()).isEqualTo(stores); } From a918858d5318510012e5c9ab7de74b4d9a9d4ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 11:13:26 +0100 Subject: [PATCH 52/69] Add License to all the files. Some legacy code has been commented --- license.txt => LICENSE.txt | 8 ++-- .../apps/marketplace/bo/AttributeTypeBo.java | 32 +++++++++++++ .../bo/AttributeTypeStatisticsBo.java | 32 +++++++++++++ .../fiware/apps/marketplace/bo/CompareBo.java | 32 +++++++++++++ .../apps/marketplace/bo/MaintenanceBo.java | 32 +++++++++++++ .../apps/marketplace/bo/OfferingBo.java | 32 +++++++++++++ .../fiware/apps/marketplace/bo/RatingBo.java | 32 +++++++++++++ .../fiware/apps/marketplace/bo/SearchBo.java | 32 +++++++++++++ .../fiware/apps/marketplace/bo/ServiceBo.java | 33 +++++++++++++ .../bo/ServiceManifestationBo.java | 32 +++++++++++++ .../fiware/apps/marketplace/bo/StoreBo.java | 33 +++++++++++++ .../fiware/apps/marketplace/bo/UserBo.java | 33 +++++++++++++ .../apps/marketplace/bo/VocabularyBo.java | 32 +++++++++++++ .../bo/impl/AttributeTypeBoImpl.java | 32 +++++++++++++ .../impl/AttributeTypeStatisticsBoImpl.java | 32 +++++++++++++ .../marketplace/bo/impl/CompareBoImpl.java | 32 +++++++++++++ .../bo/impl/MaintenanceBoImpl.java | 32 +++++++++++++ .../marketplace/bo/impl/OfferingBoImpl.java | 31 ++++++++++++ .../marketplace/bo/impl/RatingBoImpl.java | 33 +++++++++++++ .../marketplace/bo/impl/SearchBoImpl.java | 32 +++++++++++++ .../marketplace/bo/impl/ServiceBoImpl.java | 33 +++++++++++++ .../bo/impl/ServiceManifestationBoImpl.java | 32 +++++++++++++ .../apps/marketplace/bo/impl/StoreBoImpl.java | 33 +++++++++++++ .../apps/marketplace/bo/impl/UserBoImpl.java | 33 +++++++++++++ .../marketplace/bo/impl/VocabularyBoImpl.java | 32 +++++++++++++ .../apps/marketplace/client/ClientUtil.java | 32 +++++++++++++ .../marketplace/client/MarketplaceClient.java | 48 +++++++++++++++---- .../marketplace/client/ServiceClient.java | 37 +++++++++++++- .../apps/marketplace/client/StoreClient.java | 40 ++++++++++++++-- .../apps/marketplace/client/UserClient.java | 39 +++++++++++++-- .../apps/marketplace/dao/RatingDao.java | 32 +++++++++++++ .../apps/marketplace/dao/ServiceDao.java | 33 +++++++++++++ .../fiware/apps/marketplace/dao/StoreDao.java | 33 +++++++++++++ .../fiware/apps/marketplace/dao/UserDao.java | 33 +++++++++++++ .../marketplace/dao/impl/RatingDaoImpl.java | 32 +++++++++++++ .../marketplace/dao/impl/ServiceDaoImpl.java | 33 +++++++++++++ .../marketplace/dao/impl/StoreDaoImpl.java | 33 +++++++++++++ .../marketplace/dao/impl/UserDaoImpl.java | 33 +++++++++++++ .../fiware/apps/marketplace/db/Dialect.java | 32 +++++++++++++ .../marketplace/db/HibernateDDLGenerator.java | 38 --------------- .../exceptions/ServiceNotFoundException.java | 32 +++++++++++++ .../exceptions/StoreNotFoundException.java | 32 +++++++++++++ .../exceptions/UserNotFoundException.java | 32 +++++++++++++ .../exceptions/ValidationException.java | 32 +++++++++++++ .../helpers/AttributeAssignmentResolver.java | 32 +++++++++++++ .../helpers/AttributeTypeResolver.java | 32 +++++++++++++ .../AttributeTypeStatisticsResolver.java | 32 +++++++++++++ .../helpers/AttributeUnitFactorResolver.java | 32 +++++++++++++ .../marketplace/helpers/OfferingResolver.java | 32 +++++++++++++ .../ServiceManifestationComparator.java | 32 +++++++++++++ .../helpers/ServiceManifestationResolver.java | 31 ++++++++++++ .../apps/marketplace/model/APIError.java | 31 ++++++++++++ .../marketplace/model/ComparisonResult.java | 32 +++++++++++++ .../model/ComparisonResultAttribute.java | 32 +++++++++++++ .../apps/marketplace/model/ErrorType.java | 32 +++++++++++++ .../apps/marketplace/model/Offering.java | 32 +++++++++++++ .../fiware/apps/marketplace/model/Rating.java | 32 +++++++++++++ .../marketplace/model/RatingCategory.java | 32 +++++++++++++ .../model/RatingCategoryEntry.java | 32 +++++++++++++ .../apps/marketplace/model/RatingObject.java | 32 +++++++++++++ .../model/RatingObjectCategory.java | 32 +++++++++++++ .../apps/marketplace/model/SearchResult.java | 32 +++++++++++++ .../marketplace/model/SearchResultEntry.java | 32 +++++++++++++ .../model/SearchResultEntryMatch.java | 32 +++++++++++++ .../apps/marketplace/model/Service.java | 33 +++++++++++++ .../marketplace/model/ServiceAttribute.java | 32 +++++++++++++ .../model/ServiceAttributeType.java | 32 +++++++++++++ .../model/ServiceAttributeTypeStatistics.java | 32 +++++++++++++ .../model/ServiceManifestation.java | 32 +++++++++++++ .../model/ServiceNominalAttributeType.java | 32 +++++++++++++ .../model/ServiceOrdinalAttributeType.java | 32 +++++++++++++ .../model/ServiceQualitativeAttribute.java | 32 +++++++++++++ .../model/ServiceQuantitativeAttribute.java | 32 +++++++++++++ .../model/ServiceRatioAttributeType.java | 33 +++++++++++++ .../apps/marketplace/model/Services.java | 32 +++++++++++++ .../fiware/apps/marketplace/model/Store.java | 33 +++++++++++++ .../fiware/apps/marketplace/model/Stores.java | 32 +++++++++++++ .../fiware/apps/marketplace/model/User.java | 33 +++++++++++++ .../fiware/apps/marketplace/model/Users.java | 32 +++++++++++++ .../model/validators/GenericValidator.java | 32 +++++++++++++ .../model/validators/ServiceValidator.java | 32 +++++++++++++ .../model/validators/StoreValidator.java | 32 +++++++++++++ .../model/validators/UserValidator.java | 32 +++++++++++++ .../apps/marketplace/oauth2/FIWAREApi.java | 32 +++++++++++++ .../oauth2/FIWAREAttributesDefinition.java | 32 +++++++++++++ .../apps/marketplace/oauth2/FIWAREClient.java | 32 +++++++++++++ .../marketplace/oauth2/FIWAREProfile.java | 32 +++++++++++++ .../rdf/IndexBuilderNodeExtended.java | 32 +++++++++++++ .../rdf/IndexBuilderStringExtended.java | 32 +++++++++++++ .../apps/marketplace/rdf/RdfHelper.java | 32 +++++++++++++ .../apps/marketplace/rdf/RdfIndexer.java | 32 +++++++++++++ .../marketplace/rest/AllOfferingsService.java | 32 +++++++++++++ .../apps/marketplace/rest/CompareService.java | 32 +++++++++++++ .../apps/marketplace/rest/ErrorUtils.java | 32 +++++++++++++ .../rest/OfferingRegistrationService.java | 33 +++++++++++++ .../apps/marketplace/rest/RatingService.java | 32 +++++++++++++ .../rest/RecommendationService.java | 32 +++++++++++++ .../apps/marketplace/rest/SearchService.java | 32 +++++++++++++ .../ServiceManifestationIndexerService.java | 32 +++++++++++++ .../rest/StoreRegistrationService.java | 33 +++++++++++++ .../rest/UserRegistrationService.java | 33 +++++++++++++ .../apps/marketplace/security/Assembler.java | 33 +++++++++++++ .../security/UserManagementService.java | 33 +++++++++++++ .../marketplace/security/auth/AuthUtils.java | 32 +++++++++++++ .../auth/OfferingRegistrationAuth.java | 32 +++++++++++++ .../security/auth/RegistrationAuth.java | 32 +++++++++++++ .../security/auth/StoreRegistrationAuth.java | 32 +++++++++++++ .../security/auth/UserRegistrationAuth.java | 32 +++++++++++++ .../utils/ApplicationContextProvider.java | 35 +++++++++++++- .../utils/MarketplaceHibernateDao.java | 32 +++++++++++++ .../marketplace/utils/PropertiesUtil.java | 32 +++++++++++++ .../xmladapters/HiddenFieldsXMLAdapter.java | 32 +++++++++++++ .../utils/xmladapters/StoreXMLAdapter.java | 32 +++++++++++++ .../utils/xmladapters/UserXMLAdapter.java | 32 +++++++++++++ .../validators/ServiceValidatorTest.java | 32 +++++++++++++ .../model/validators/StoreValidatorTest.java | 32 +++++++++++++ .../model/validators/UserValidatorTest.java | 32 +++++++++++++ .../rest/AllOfferingsServiceTest.java | 32 +++++++++++++ .../rest/GenericRestTestUtils.java | 32 +++++++++++++ .../rest/OfferingRegistrationServiceTest.java | 32 +++++++++++++ .../rest/StoreRegistrationServiceTest.java | 32 +++++++++++++ .../rest/UserRegistrationServiceTest.java | 32 +++++++++++++ .../auth/OfferingRegistrationAuthTest.java | 39 +++++++++++++++ .../auth/StoreRegistrationAuthTest.java | 32 +++++++++++++ .../auth/UserRegistrationAuthTest.java | 32 +++++++++++++ .../fiware/apps/marketplace/tests/App.java | 32 +++++++++++++ .../AttributeAssignmentResolverTest.java | 41 ++++++++++++++++ .../tests/AttributeTypeResolverTest.java | 35 ++++++++++++++ .../AttributeTypeStatisticsResolverTest.java | 36 ++++++++++++++ .../marketplace/tests/FillLiveInstance.java | 44 +++++++++++++++-- .../apps/marketplace/tests/OAuthtest.java | 32 +++++++++++++ .../apps/marketplace/tests/OAuthtestCall.java | 32 +++++++++++++ .../tests/OfferingResolverTest.java | 36 ++++++++++++++ .../apps/marketplace/tests/OpenJenaTest.java | 32 +++++++++++++ .../marketplace/tests/ParticipantTest.java | 40 ++++++++++++++-- .../tests/RegisterServiceTest.java | 36 +++++++++++++- .../tests/RegisterServiceTestEnhanced.java | 40 ++++++++++++++-- .../marketplace/tests/RegisterStoreTest.java | 40 ++++++++++++++-- .../ServiceManifestationComparatorTest.java | 44 +++++++++++++++++ .../ServiceManifestationResolverTest.java | 43 +++++++++++++++++ 140 files changed, 4536 insertions(+), 74 deletions(-) rename license.txt => LICENSE.txt (82%) delete mode 100644 src/main/java/org/fiware/apps/marketplace/db/HibernateDDLGenerator.java diff --git a/license.txt b/LICENSE.txt similarity index 82% rename from license.txt rename to LICENSE.txt index 4925c96..7d03051 100644 --- a/license.txt +++ b/LICENSE.txt @@ -2,7 +2,7 @@ Modified BSD License ==================== Copyright (c) 2012, SAP AG -Copyright (c) 2014, UPM +Copyright (c) 2014, CoNWeT Lab, Universidad Politécnica de Madrid All rights reserved. Redistribution and use in source and binary forms, with or without @@ -12,9 +12,9 @@ modification, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of the SAP AG nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. + * Neither the name of copyright holders nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED diff --git a/src/main/java/org/fiware/apps/marketplace/bo/AttributeTypeBo.java b/src/main/java/org/fiware/apps/marketplace/bo/AttributeTypeBo.java index c1a0961..3787f94 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/AttributeTypeBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/AttributeTypeBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.HashMap; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/AttributeTypeStatisticsBo.java b/src/main/java/org/fiware/apps/marketplace/bo/AttributeTypeStatisticsBo.java index d3d39c4..03b6d7f 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/AttributeTypeStatisticsBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/AttributeTypeStatisticsBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.HashMap; import org.fiware.apps.marketplace.model.ServiceAttributeTypeStatistics; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/CompareBo.java b/src/main/java/org/fiware/apps/marketplace/bo/CompareBo.java index f727b29..be84690 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/CompareBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/CompareBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.model.ComparisonResult; public interface CompareBo { diff --git a/src/main/java/org/fiware/apps/marketplace/bo/MaintenanceBo.java b/src/main/java/org/fiware/apps/marketplace/bo/MaintenanceBo.java index d582fd9..52876fc 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/MaintenanceBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/MaintenanceBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public interface MaintenanceBo { void initialize(); boolean isInitializationDone(); diff --git a/src/main/java/org/fiware/apps/marketplace/bo/OfferingBo.java b/src/main/java/org/fiware/apps/marketplace/bo/OfferingBo.java index fe7b689..256f4ba 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/OfferingBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/OfferingBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.model.Offering; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/RatingBo.java b/src/main/java/org/fiware/apps/marketplace/bo/RatingBo.java index 9bd62db..30b2c41 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/RatingBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/RatingBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.model.Rating; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/SearchBo.java b/src/main/java/org/fiware/apps/marketplace/bo/SearchBo.java index eaf7a7f..547fc0a 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/SearchBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/SearchBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.model.SearchResult; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java b/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java index 4e6b6ba..aeb55e1 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/ServiceBo.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/ServiceManifestationBo.java b/src/main/java/org/fiware/apps/marketplace/bo/ServiceManifestationBo.java index 332d73f..9335771 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/ServiceManifestationBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/ServiceManifestationBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.model.ServiceManifestation; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java b/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java index 8200fc8..eb40df3 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/StoreBo.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java index e689ce6..2ad18e6 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/UserBo.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/VocabularyBo.java b/src/main/java/org/fiware/apps/marketplace/bo/VocabularyBo.java index b7da00d..40f2154 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/VocabularyBo.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/VocabularyBo.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; public interface VocabularyBo { diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/AttributeTypeBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/AttributeTypeBoImpl.java index ba15eef..e28d426 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/AttributeTypeBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/AttributeTypeBoImpl.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/AttributeTypeStatisticsBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/AttributeTypeStatisticsBoImpl.java index 135d970..4dc069b 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/AttributeTypeStatisticsBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/AttributeTypeStatisticsBoImpl.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.HashMap; import org.fiware.apps.marketplace.bo.AttributeTypeStatisticsBo; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/CompareBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/CompareBoImpl.java index 2477f37..9fe82d9 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/CompareBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/CompareBoImpl.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java index 383a3c2..5dd4e1b 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/MaintenanceBoImpl.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.HashMap; import org.fiware.apps.marketplace.bo.AttributeTypeBo; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/OfferingBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/OfferingBoImpl.java index 20fd2d5..75f00bb 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/OfferingBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/OfferingBoImpl.java @@ -1,5 +1,36 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/RatingBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/RatingBoImpl.java index 7d15094..1b85b11 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/RatingBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/RatingBoImpl.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.bo.RatingBo; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/SearchBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/SearchBoImpl.java index 1ef1aed..46863d8 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/SearchBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/SearchBoImpl.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.IOException; import java.util.Iterator; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java index a2fbf5c..447784c 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceBoImpl.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.bo.ServiceBo; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceManifestationBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceManifestationBoImpl.java index d551524..a379718 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceManifestationBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/ServiceManifestationBoImpl.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java index 212275d..2c3e152 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/StoreBoImpl.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.bo.StoreBo; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java index 3290693..1d7c9b7 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/UserBoImpl.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.bo.UserBo; diff --git a/src/main/java/org/fiware/apps/marketplace/bo/impl/VocabularyBoImpl.java b/src/main/java/org/fiware/apps/marketplace/bo/impl/VocabularyBoImpl.java index c0e8b50..7078fb4 100644 --- a/src/main/java/org/fiware/apps/marketplace/bo/impl/VocabularyBoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/bo/impl/VocabularyBoImpl.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.bo.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/client/ClientUtil.java b/src/main/java/org/fiware/apps/marketplace/client/ClientUtil.java index 6a8b23c..d5a3adb 100644 --- a/src/main/java/org/fiware/apps/marketplace/client/ClientUtil.java +++ b/src/main/java/org/fiware/apps/marketplace/client/ClientUtil.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.client; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.jboss.resteasy.client.ClientRequest; import org.jboss.resteasy.client.ClientResponse; diff --git a/src/main/java/org/fiware/apps/marketplace/client/MarketplaceClient.java b/src/main/java/org/fiware/apps/marketplace/client/MarketplaceClient.java index 7c145f2..076844f 100644 --- a/src/main/java/org/fiware/apps/marketplace/client/MarketplaceClient.java +++ b/src/main/java/org/fiware/apps/marketplace/client/MarketplaceClient.java @@ -1,16 +1,48 @@ package org.fiware.apps.marketplace.client; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.net.URI; import java.net.URISyntaxException; -import org.apache.commons.httpclient.Credentials; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.Credentials; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.HttpClient; import org.jboss.resteasy.client.ClientExecutor; import org.jboss.resteasy.client.ClientRequest; import org.jboss.resteasy.client.ClientRequestFactory; -import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor; public abstract class MarketplaceClient { @@ -25,7 +57,7 @@ public MarketplaceClient(String endpoint, String user, String pwd) { this.pwd = pwd; } - protected ClientRequest createRequest(String uriString){ + /*protected ClientRequest createRequest(String uriString){ URI uri=null; try { uri = new URI(uriString); @@ -44,8 +76,8 @@ protected ClientRequest createRequest(String uriString){ ClientRequest request = fac.createRequest(uriString); return request; - - } + + }*/ } diff --git a/src/main/java/org/fiware/apps/marketplace/client/ServiceClient.java b/src/main/java/org/fiware/apps/marketplace/client/ServiceClient.java index db119c6..1e4a8db 100644 --- a/src/main/java/org/fiware/apps/marketplace/client/ServiceClient.java +++ b/src/main/java/org/fiware/apps/marketplace/client/ServiceClient.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.client; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; @@ -27,7 +60,7 @@ public ServiceClient(String endpoint, String user, String pwd) { - public boolean save(String storeName, Service service){ + /*public boolean save(String storeName, Service service){ ClientRequest request = createRequest(endpoint+REGISTRATION_SERVICE_SAVE+"/"+storeName+"/offering"); JAXBContext ctx; try { @@ -136,7 +169,7 @@ public Service find(String storeName, String serviceName){ } return r; - } + }*/ diff --git a/src/main/java/org/fiware/apps/marketplace/client/StoreClient.java b/src/main/java/org/fiware/apps/marketplace/client/StoreClient.java index 9db731f..a15e78b 100644 --- a/src/main/java/org/fiware/apps/marketplace/client/StoreClient.java +++ b/src/main/java/org/fiware/apps/marketplace/client/StoreClient.java @@ -1,4 +1,38 @@ -package org.fiware.apps.marketplace.client; +package org.fiware.apps.marketplace.client; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.BufferedReader; import java.io.ByteArrayInputStream; @@ -26,7 +60,7 @@ public StoreClient(String endpoint, String user, String pwd) { private static String REGISTRATION_STORE_FIND = "/registration/store"; - public boolean save(Store store){ + /*public boolean save(Store store){ ClientRequest request = createRequest(endpoint+REGISTRATION_STORE_SAVE); @@ -138,5 +172,5 @@ public Store find(String name){ } return r; - } + }*/ } diff --git a/src/main/java/org/fiware/apps/marketplace/client/UserClient.java b/src/main/java/org/fiware/apps/marketplace/client/UserClient.java index ca7ef33..0270d6b 100644 --- a/src/main/java/org/fiware/apps/marketplace/client/UserClient.java +++ b/src/main/java/org/fiware/apps/marketplace/client/UserClient.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.client; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; @@ -9,7 +42,7 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.jboss.resteasy.client.ClientRequest; import org.jboss.resteasy.client.ClientResponse; @@ -26,7 +59,7 @@ public UserClient(String endpoint, String user, String pwd) { private static String USER_SERVICE_FIND= "/registration/userManagement/user"; - public boolean save(Localuser user){ + /*public boolean save(Localuser user){ ClientRequest request = createRequest(endpoint+USER_SERVICE_SAVE); @@ -138,5 +171,5 @@ public Localuser find(String name){ } return r; - } + }*/ } diff --git a/src/main/java/org/fiware/apps/marketplace/dao/RatingDao.java b/src/main/java/org/fiware/apps/marketplace/dao/RatingDao.java index d7f6e29..9113003 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/RatingDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/RatingDao.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.dao; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.model.Rating; diff --git a/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java b/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java index b3525b5..c48ee4c 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/ServiceDao.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.dao; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.exceptions.ServiceNotFoundException; diff --git a/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java b/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java index 58ef4f7..267239e 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/StoreDao.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.dao; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.exceptions.StoreNotFoundException; diff --git a/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java b/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java index 333de97..498b590 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/UserDao.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.dao; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/RatingDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/RatingDaoImpl.java index c638aa1..9c19e44 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/RatingDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/RatingDaoImpl.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.dao.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.dao.RatingDao; diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java index 7399295..28aef6e 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/ServiceDaoImpl.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.dao.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.dao.ServiceDao; diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java index 975e11e..7845f70 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/StoreDaoImpl.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.dao.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.dao.StoreDao; diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java index 884fba5..a8b0488 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.dao.impl; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import org.fiware.apps.marketplace.dao.UserDao; diff --git a/src/main/java/org/fiware/apps/marketplace/db/Dialect.java b/src/main/java/org/fiware/apps/marketplace/db/Dialect.java index 902fa4b..854e31d 100644 --- a/src/main/java/org/fiware/apps/marketplace/db/Dialect.java +++ b/src/main/java/org/fiware/apps/marketplace/db/Dialect.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.db; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + enum Dialect { MYSQL("org.hibernate.dialect.MySQLInnoDBDialect"), MYSQL5("org.hibernate.dialect.MySQL5InnoDBDialect"), diff --git a/src/main/java/org/fiware/apps/marketplace/db/HibernateDDLGenerator.java b/src/main/java/org/fiware/apps/marketplace/db/HibernateDDLGenerator.java deleted file mode 100644 index 1ecadf9..0000000 --- a/src/main/java/org/fiware/apps/marketplace/db/HibernateDDLGenerator.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.fiware.apps.marketplace.db; - - -import org.fiware.apps.marketplace.model.User; -import org.fiware.apps.marketplace.model.Rating; -import org.fiware.apps.marketplace.model.RatingCategory; -import org.fiware.apps.marketplace.model.RatingCategoryEntry; -import org.fiware.apps.marketplace.model.RatingObject; -import org.fiware.apps.marketplace.model.RatingObjectCategory; -import org.fiware.apps.marketplace.model.Service; -import org.fiware.apps.marketplace.model.Store; -import org.hibernate.cfg.AnnotationConfiguration; -import org.hibernate.cfg.Environment; -import org.hibernate.tool.hbm2ddl.SchemaExport; - -public class HibernateDDLGenerator { - /** - * @param args - */ - public static void main(String[] args) { - new HibernateDDLGenerator().execute(Dialect.MYSQL5, Store.class, Service.class, User.class, Rating.class, RatingCategory.class, RatingCategoryEntry.class, RatingObject.class, RatingObjectCategory.class); - } - private void execute(Dialect dialect, Class... classes) { - AnnotationConfiguration configuration = new AnnotationConfiguration(); - configuration.setProperty(Environment.DIALECT, dialect.getClassName()); - for (Class entityClass : classes) { - configuration.addAnnotatedClass(entityClass); - } - - SchemaExport schemaExport = new SchemaExport(configuration); - schemaExport.setDelimiter(";"); - schemaExport.setOutputFile(String.format("database/%s_%s.%s ", new Object[] {"ddl", dialect.name().toLowerCase(), "sql" })); - schemaExport.create(true, false); - - - - } -} diff --git a/src/main/java/org/fiware/apps/marketplace/exceptions/ServiceNotFoundException.java b/src/main/java/org/fiware/apps/marketplace/exceptions/ServiceNotFoundException.java index 267c4db..8db0142 100644 --- a/src/main/java/org/fiware/apps/marketplace/exceptions/ServiceNotFoundException.java +++ b/src/main/java/org/fiware/apps/marketplace/exceptions/ServiceNotFoundException.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.exceptions; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class ServiceNotFoundException extends Exception { private static final long serialVersionUID = 1L; diff --git a/src/main/java/org/fiware/apps/marketplace/exceptions/StoreNotFoundException.java b/src/main/java/org/fiware/apps/marketplace/exceptions/StoreNotFoundException.java index d9aa445..582c6d9 100644 --- a/src/main/java/org/fiware/apps/marketplace/exceptions/StoreNotFoundException.java +++ b/src/main/java/org/fiware/apps/marketplace/exceptions/StoreNotFoundException.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.exceptions; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class StoreNotFoundException extends Exception { private static final long serialVersionUID = 1L; diff --git a/src/main/java/org/fiware/apps/marketplace/exceptions/UserNotFoundException.java b/src/main/java/org/fiware/apps/marketplace/exceptions/UserNotFoundException.java index 7483b17..90bb3c2 100644 --- a/src/main/java/org/fiware/apps/marketplace/exceptions/UserNotFoundException.java +++ b/src/main/java/org/fiware/apps/marketplace/exceptions/UserNotFoundException.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.exceptions; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class UserNotFoundException extends Exception { private static final long serialVersionUID = 1L; diff --git a/src/main/java/org/fiware/apps/marketplace/exceptions/ValidationException.java b/src/main/java/org/fiware/apps/marketplace/exceptions/ValidationException.java index 0b59f93..ca2d1c4 100644 --- a/src/main/java/org/fiware/apps/marketplace/exceptions/ValidationException.java +++ b/src/main/java/org/fiware/apps/marketplace/exceptions/ValidationException.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.exceptions; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class ValidationException extends Exception { private static final long serialVersionUID = 1L; diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeAssignmentResolver.java b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeAssignmentResolver.java index f630290..cd1ad37 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeAssignmentResolver.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeAssignmentResolver.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.helpers; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeTypeResolver.java b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeTypeResolver.java index ecfba31..ca91d2f 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeTypeResolver.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeTypeResolver.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.helpers; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeTypeStatisticsResolver.java b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeTypeStatisticsResolver.java index 955139e..5d6ef1e 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeTypeStatisticsResolver.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeTypeStatisticsResolver.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.helpers; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.HashMap; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeUnitFactorResolver.java b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeUnitFactorResolver.java index 602284b..7bf131a 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/AttributeUnitFactorResolver.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/AttributeUnitFactorResolver.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.helpers; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/OfferingResolver.java b/src/main/java/org/fiware/apps/marketplace/helpers/OfferingResolver.java index cb8a1f0..79cc522 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/OfferingResolver.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/OfferingResolver.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.helpers; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/ServiceManifestationComparator.java b/src/main/java/org/fiware/apps/marketplace/helpers/ServiceManifestationComparator.java index 5620f9e..96b33bd 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/ServiceManifestationComparator.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/ServiceManifestationComparator.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.helpers; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/ServiceManifestationResolver.java b/src/main/java/org/fiware/apps/marketplace/helpers/ServiceManifestationResolver.java index 728e5b6..ea6c1e3 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/ServiceManifestationResolver.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/ServiceManifestationResolver.java @@ -1,5 +1,36 @@ package org.fiware.apps.marketplace.helpers; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/org/fiware/apps/marketplace/model/APIError.java b/src/main/java/org/fiware/apps/marketplace/model/APIError.java index 2fb3715..4409bd6 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/APIError.java +++ b/src/main/java/org/fiware/apps/marketplace/model/APIError.java @@ -1,5 +1,36 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ComparisonResult.java b/src/main/java/org/fiware/apps/marketplace/model/ComparisonResult.java index ec0cb40..112f5e9 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ComparisonResult.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ComparisonResult.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ComparisonResultAttribute.java b/src/main/java/org/fiware/apps/marketplace/model/ComparisonResultAttribute.java index e4bd44a..b436830 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ComparisonResultAttribute.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ComparisonResultAttribute.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java b/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java index 1ffae6e..a9f75ba 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ErrorType.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public enum ErrorType { BAD_REQUEST, diff --git a/src/main/java/org/fiware/apps/marketplace/model/Offering.java b/src/main/java/org/fiware/apps/marketplace/model/Offering.java index 768251d..8d0d47d 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Offering.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Offering.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Rating.java b/src/main/java/org/fiware/apps/marketplace/model/Rating.java index f52e57a..77cf14c 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Rating.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Rating.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static javax.persistence.GenerationType.IDENTITY; import java.util.Date; diff --git a/src/main/java/org/fiware/apps/marketplace/model/RatingCategory.java b/src/main/java/org/fiware/apps/marketplace/model/RatingCategory.java index cc61a88..ef41e92 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/RatingCategory.java +++ b/src/main/java/org/fiware/apps/marketplace/model/RatingCategory.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static javax.persistence.GenerationType.IDENTITY; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/RatingCategoryEntry.java b/src/main/java/org/fiware/apps/marketplace/model/RatingCategoryEntry.java index 01e58c4..6a5189b 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/RatingCategoryEntry.java +++ b/src/main/java/org/fiware/apps/marketplace/model/RatingCategoryEntry.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static javax.persistence.GenerationType.IDENTITY; import javax.persistence.Column; diff --git a/src/main/java/org/fiware/apps/marketplace/model/RatingObject.java b/src/main/java/org/fiware/apps/marketplace/model/RatingObject.java index b1d3cbd..85c3a7b 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/RatingObject.java +++ b/src/main/java/org/fiware/apps/marketplace/model/RatingObject.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static javax.persistence.GenerationType.IDENTITY; import java.util.Set; diff --git a/src/main/java/org/fiware/apps/marketplace/model/RatingObjectCategory.java b/src/main/java/org/fiware/apps/marketplace/model/RatingObjectCategory.java index 229b424..62280af 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/RatingObjectCategory.java +++ b/src/main/java/org/fiware/apps/marketplace/model/RatingObjectCategory.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static javax.persistence.GenerationType.IDENTITY; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/SearchResult.java b/src/main/java/org/fiware/apps/marketplace/model/SearchResult.java index 566f9aa..a50d9d1 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/SearchResult.java +++ b/src/main/java/org/fiware/apps/marketplace/model/SearchResult.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntry.java b/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntry.java index 4493814..6b4a41c 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntry.java +++ b/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntry.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntryMatch.java b/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntryMatch.java index 250c60d..6aeb627 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntryMatch.java +++ b/src/main/java/org/fiware/apps/marketplace/model/SearchResultEntryMatch.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Service.java b/src/main/java/org/fiware/apps/marketplace/model/Service.java index 1a5395d..f17e150 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Service.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Service.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static javax.persistence.GenerationType.IDENTITY; import java.util.Date; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceAttribute.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceAttribute.java index 96902c9..4388732 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceAttribute.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceAttribute.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceAttributeType.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceAttributeType.java index 535fe79..8f05005 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceAttributeType.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceAttributeType.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceAttributeTypeStatistics.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceAttributeTypeStatistics.java index 00d3066..f11fbc3 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceAttributeTypeStatistics.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceAttributeTypeStatistics.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.HashMap; public class ServiceAttributeTypeStatistics { diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceManifestation.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceManifestation.java index 2c16034..0e93309 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceManifestation.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceManifestation.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceNominalAttributeType.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceNominalAttributeType.java index 0c6f3a0..d5222ce 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceNominalAttributeType.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceNominalAttributeType.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class ServiceNominalAttributeType extends ServiceAttributeType { public static final String baseTypeUri = "http://purl.org/goodrelations/v1#QualitativeValue"; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceOrdinalAttributeType.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceOrdinalAttributeType.java index 3a0dc4d..f8b9e5b 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceOrdinalAttributeType.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceOrdinalAttributeType.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class ServiceOrdinalAttributeType extends ServiceAttributeType { public static final String baseTypeUri = "http://purl.org/goodrelations/v1#QualitativeValue"; diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceQualitativeAttribute.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceQualitativeAttribute.java index 691f4bc..738cb4f 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceQualitativeAttribute.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceQualitativeAttribute.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class ServiceQualitativeAttribute extends ServiceAttribute { } diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceQuantitativeAttribute.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceQuantitativeAttribute.java index fedfe41..9ab6183 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceQuantitativeAttribute.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceQuantitativeAttribute.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class ServiceQuantitativeAttribute extends ServiceAttribute { // TODO suitable unit implementation diff --git a/src/main/java/org/fiware/apps/marketplace/model/ServiceRatioAttributeType.java b/src/main/java/org/fiware/apps/marketplace/model/ServiceRatioAttributeType.java index 43f15b5..6583c37 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/ServiceRatioAttributeType.java +++ b/src/main/java/org/fiware/apps/marketplace/model/ServiceRatioAttributeType.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + public class ServiceRatioAttributeType extends ServiceAttributeType { public static final String baseTypeUri = "http://purl.org/goodrelations/v1#QuantitativeValue"; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Services.java b/src/main/java/org/fiware/apps/marketplace/model/Services.java index 0c87e65..1948300 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Services.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Services.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Store.java b/src/main/java/org/fiware/apps/marketplace/model/Store.java index 5573549..10d1b16 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Store.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Store.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static javax.persistence.GenerationType.IDENTITY; import java.util.Date; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Stores.java b/src/main/java/org/fiware/apps/marketplace/model/Stores.java index cbaa5a3..b865119 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Stores.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Stores.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/User.java b/src/main/java/org/fiware/apps/marketplace/model/User.java index 5a39416..b81ca97 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/User.java +++ b/src/main/java/org/fiware/apps/marketplace/model/User.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static javax.persistence.GenerationType.IDENTITY; import java.util.Date; diff --git a/src/main/java/org/fiware/apps/marketplace/model/Users.java b/src/main/java/org/fiware/apps/marketplace/model/Users.java index 332ef5b..f203eb8 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/Users.java +++ b/src/main/java/org/fiware/apps/marketplace/model/Users.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/GenericValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/GenericValidator.java index 1059930..57562b6 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/GenericValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/GenericValidator.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model.validators; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.regex.Pattern; import org.apache.commons.validator.routines.UrlValidator; diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java index ea281db..e533026 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/ServiceValidator.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model.validators; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.exceptions.ValidationException; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java index ee7d6b4..a5ffdd4 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/StoreValidator.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model.validators; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.exceptions.ValidationException; import org.fiware.apps.marketplace.model.Store; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java index 70d3352..297a8c7 100644 --- a/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java +++ b/src/main/java/org/fiware/apps/marketplace/model/validators/UserValidator.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model.validators; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.exceptions.ValidationException; import org.fiware.apps.marketplace.model.User; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREApi.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREApi.java index 198e24e..f88425e 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREApi.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREApi.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.oauth2; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.scribe.builder.api.DefaultApi20; import org.scribe.extractors.AccessTokenExtractor; import org.scribe.extractors.JsonTokenExtractor; diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java index ae6f273..87c5d85 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREAttributesDefinition.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.oauth2; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.pac4j.core.profile.converter.Converters; import org.pac4j.oauth.profile.OAuthAttributesDefinition; diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java index ff11cac..9e78e22 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.oauth2; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.Date; import org.fiware.apps.marketplace.bo.UserBo; diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java index c29324b..c6d9f78 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.oauth2; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.pac4j.oauth.profile.OAuth20Profile; public class FIWAREProfile extends OAuth20Profile{ diff --git a/src/main/java/org/fiware/apps/marketplace/rdf/IndexBuilderNodeExtended.java b/src/main/java/org/fiware/apps/marketplace/rdf/IndexBuilderNodeExtended.java index 939398a..4495b1c 100644 --- a/src/main/java/org/fiware/apps/marketplace/rdf/IndexBuilderNodeExtended.java +++ b/src/main/java/org/fiware/apps/marketplace/rdf/IndexBuilderNodeExtended.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rdf; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.IOException; import org.apache.lucene.document.Document; diff --git a/src/main/java/org/fiware/apps/marketplace/rdf/IndexBuilderStringExtended.java b/src/main/java/org/fiware/apps/marketplace/rdf/IndexBuilderStringExtended.java index 6a16907..bb81c69 100644 --- a/src/main/java/org/fiware/apps/marketplace/rdf/IndexBuilderStringExtended.java +++ b/src/main/java/org/fiware/apps/marketplace/rdf/IndexBuilderStringExtended.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rdf; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/org/fiware/apps/marketplace/rdf/RdfHelper.java b/src/main/java/org/fiware/apps/marketplace/rdf/RdfHelper.java index 44b82b0..dafc3dd 100644 --- a/src/main/java/org/fiware/apps/marketplace/rdf/RdfHelper.java +++ b/src/main/java/org/fiware/apps/marketplace/rdf/RdfHelper.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rdf; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; diff --git a/src/main/java/org/fiware/apps/marketplace/rdf/RdfIndexer.java b/src/main/java/org/fiware/apps/marketplace/rdf/RdfIndexer.java index 3c836cd..9005bf0 100644 --- a/src/main/java/org/fiware/apps/marketplace/rdf/RdfIndexer.java +++ b/src/main/java/org/fiware/apps/marketplace/rdf/RdfIndexer.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rdf; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.IOException; import org.apache.lucene.analysis.Analyzer; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/AllOfferingsService.java b/src/main/java/org/fiware/apps/marketplace/rest/AllOfferingsService.java index 654d129..66f1404 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/AllOfferingsService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/AllOfferingsService.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import javax.ws.rs.DefaultValue; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/CompareService.java b/src/main/java/org/fiware/apps/marketplace/rest/CompareService.java index f264dc9..d452215 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/CompareService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/CompareService.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java index 0ec3dd4..b002818 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/ErrorUtils.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java index b1691c1..57041ec 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/OfferingRegistrationService.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.Date; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/RatingService.java b/src/main/java/org/fiware/apps/marketplace/rest/RatingService.java index a48fb83..66b2fe8 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/RatingService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/RatingService.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.Date; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/RecommendationService.java b/src/main/java/org/fiware/apps/marketplace/rest/RecommendationService.java index 4d1ec15..ab64985 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/RecommendationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/RecommendationService.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.Collections; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/SearchService.java b/src/main/java/org/fiware/apps/marketplace/rest/SearchService.java index a458c79..2d4d71e 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/SearchService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/SearchService.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/ServiceManifestationIndexerService.java b/src/main/java/org/fiware/apps/marketplace/rest/ServiceManifestationIndexerService.java index e60654d..f0ae050 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/ServiceManifestationIndexerService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/ServiceManifestationIndexerService.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.List; import javax.ws.rs.GET; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java index 83359c1..b441023 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/StoreRegistrationService.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.Date; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java index 3f56530..d8334cd 100644 --- a/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java +++ b/src/main/java/org/fiware/apps/marketplace/rest/UserRegistrationService.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.Date; import java.util.List; diff --git a/src/main/java/org/fiware/apps/marketplace/security/Assembler.java b/src/main/java/org/fiware/apps/marketplace/security/Assembler.java index dab9b18..76a8ff5 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/Assembler.java +++ b/src/main/java/org/fiware/apps/marketplace/security/Assembler.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.security; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java b/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java index 3631da4..213a474 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java +++ b/src/main/java/org/fiware/apps/marketplace/security/UserManagementService.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.security; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java index 7e32345..d2adc7b 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java index 7fa1ee0..9426668 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuth.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Service; diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java index e132f42..615ad22 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/RegistrationAuth.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java index eff6a17..756c625 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuth.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Store; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java index a192ff4..2e61787 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuth.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.model.User; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/fiware/apps/marketplace/utils/ApplicationContextProvider.java b/src/main/java/org/fiware/apps/marketplace/utils/ApplicationContextProvider.java index e678d7e..e9bc8fb 100644 --- a/src/main/java/org/fiware/apps/marketplace/utils/ApplicationContextProvider.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/ApplicationContextProvider.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.utils; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -14,6 +47,6 @@ public static ApplicationContext getApplicationContext() { } public void setApplicationContext(ApplicationContext ctx) throws BeansException { - this.ctx = ctx; + ApplicationContextProvider.ctx = ctx; } } diff --git a/src/main/java/org/fiware/apps/marketplace/utils/MarketplaceHibernateDao.java b/src/main/java/org/fiware/apps/marketplace/utils/MarketplaceHibernateDao.java index bc32c4e..ecbfaf1 100644 --- a/src/main/java/org/fiware/apps/marketplace/utils/MarketplaceHibernateDao.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/MarketplaceHibernateDao.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.utils; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate4.support.HibernateDaoSupport; diff --git a/src/main/java/org/fiware/apps/marketplace/utils/PropertiesUtil.java b/src/main/java/org/fiware/apps/marketplace/utils/PropertiesUtil.java index 3868ff6..129a60d 100644 --- a/src/main/java/org/fiware/apps/marketplace/utils/PropertiesUtil.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/PropertiesUtil.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.utils; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.util.HashMap; import java.util.HashSet; import java.util.Map; diff --git a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapter.java index 2094aff..6d850b4 100644 --- a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapter.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapter.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.utils.xmladapters; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import javax.xml.bind.annotation.adapters.XmlAdapter; public class HiddenFieldsXMLAdapter extends XmlAdapter{ diff --git a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapter.java index c63bb9c..0c7f1ae 100644 --- a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapter.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapter.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.utils.xmladapters; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import javax.xml.bind.annotation.adapters.XmlAdapter; import org.fiware.apps.marketplace.model.Store; diff --git a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapter.java b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapter.java index fe4ad1a..000d647 100644 --- a/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapter.java +++ b/src/main/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapter.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.utils.xmladapters; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import javax.xml.bind.annotation.adapters.XmlAdapter; import org.fiware.apps.marketplace.model.User; diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java index df34dbf..09c2dc3 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/ServiceValidatorTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model.validators; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java index a117516..89bab83 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/StoreValidatorTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model.validators; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; diff --git a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java index b539dde..f7bc6f0 100644 --- a/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/model/validators/UserValidatorTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.model.validators; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.*; import org.fiware.apps.marketplace.exceptions.ValidationException; diff --git a/src/test/java/org/fiware/apps/marketplace/rest/AllOfferingsServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/AllOfferingsServiceTest.java index c982f71..c014613 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/AllOfferingsServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/AllOfferingsServiceTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.doThrow; diff --git a/src/test/java/org/fiware/apps/marketplace/rest/GenericRestTestUtils.java b/src/test/java/org/fiware/apps/marketplace/rest/GenericRestTestUtils.java index d3f9414..16ee222 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/GenericRestTestUtils.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/GenericRestTestUtils.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.assertThat; import javax.ws.rs.core.Response; diff --git a/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java index 1d150e7..38476ff 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/OfferingRegistrationServiceTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.doThrow; diff --git a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java index 8b871e2..70d87c8 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/StoreRegistrationServiceTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.*; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.*; diff --git a/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java b/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java index 3c1b034..1197b32 100644 --- a/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/rest/UserRegistrationServiceTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.rest; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java index 2622a24..98a3b21 100644 --- a/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/OfferingRegistrationAuthTest.java @@ -1,10 +1,43 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.Service; +import org.fiware.apps.marketplace.model.Store; import org.fiware.apps.marketplace.model.User; import org.junit.Before; import org.junit.Test; @@ -155,9 +188,15 @@ public void canNotDeleteOfferingNotLoggedIn() { /////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////// TEST LIST ////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// + @Test public void canList() { assertThat(authHelper.canList()).isTrue(); } + + @Test + public void canListStore() { + assertThat(authHelper.canList(new Store())).isTrue(); + } } diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java index dffed85..13ddde1 100644 --- a/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/StoreRegistrationAuthTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java index a384f8d..4b15c57 100644 --- a/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/UserRegistrationAuthTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; diff --git a/src/test/java/org/fiware/apps/marketplace/tests/App.java b/src/test/java/org/fiware/apps/marketplace/tests/App.java index 64afffa..3c5b013 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/App.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/App.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import org.fiware.apps.marketplace.bo.ServiceBo; import org.fiware.apps.marketplace.model.Service; import org.springframework.context.ApplicationContext; diff --git a/src/test/java/org/fiware/apps/marketplace/tests/AttributeAssignmentResolverTest.java b/src/test/java/org/fiware/apps/marketplace/tests/AttributeAssignmentResolverTest.java index 72bd2c6..c83a012 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/AttributeAssignmentResolverTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/AttributeAssignmentResolverTest.java @@ -1,13 +1,47 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.junit.Assert.*; import org.fiware.apps.marketplace.helpers.AttributeAssignmentResolver; +import org.junit.Ignore; import org.junit.Test; public class AttributeAssignmentResolverTest { @Test + @Ignore public void getMaximalAttributeAssignmentsTest_1() { double[][] values = new double[][] { { 1.0, 0.0, 0.0, }, { 0.0, 1.0, 0.0, }, { 0.0, 0.0, 1.0, } }; @@ -20,6 +54,7 @@ public void getMaximalAttributeAssignmentsTest_1() { } @Test + @Ignore public void getMaximalAttributeAssignmentsTest_2() { double[][] values = new double[][] { { 1.0, 0.0, 0.0, }, { 0.0, 0.0, 1.0, }, { 0.0, 1.0, 0.0, } }; @@ -32,6 +67,7 @@ public void getMaximalAttributeAssignmentsTest_2() { } @Test + @Ignore public void getMaximalAttributeAssignmentsTest_3() { double[][] values = new double[][] { { 1.0, 0.0, 0.0, }, { 0.0, 1.0, 1.0, }, { 0.0, 0.0, 1.0, } }; @@ -44,6 +80,7 @@ public void getMaximalAttributeAssignmentsTest_3() { } @Test + @Ignore public void getMaximalAttributeAssignmentsTest_4() { double[][] values = new double[][] { { 0.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 3.0, 3.0 }, { 0.0, 5.0, 5.0, 9.0 }, { 0.0, 1.0, 3.0, 7.0 }, }; @@ -58,6 +95,7 @@ public void getMaximalAttributeAssignmentsTest_4() { } @Test + @Ignore public void getMaximalAttributeAssignmentsTest_5() { double[][] values = new double[][] { { 1.0, 2.0, 3.0, 4.0, 5.0 }, { 6.0, 7.0, 8.0, 7.0, 2.0 }, { 1.0, 3.0, 4.0, 4.0, 5.0 }, { 3.0, 6.0, 2.0, 8.0, 7.0 }, { 4.0, 1.0, 3.0, 5.0, 4.0 } }; @@ -70,6 +108,7 @@ public void getMaximalAttributeAssignmentsTest_5() { } @Test + @Ignore public void getMaximalAttributeAssignmentsTest_6() { double[][] values = new double[][] { { 10.0, 19.0, 08.0, 15.0, 19.0 }, { 10.0, 18.0, 07.0, 17.0, 19.0 }, { 13.0, 16.0, 09.0, 14.0, 19.0 }, { 12.0, 19.0, 08.0, 18.0, 19.0 }, { 14.0, 17.0, 10.0, 19.0, 19.0 } }; @@ -82,6 +121,7 @@ public void getMaximalAttributeAssignmentsTest_6() { } @Test + @Ignore public void getMaximalAttributeAssignmentsTest_7() { double[][] values = new double[][] { { 10.0, 19.0, 08.0, 15.0 }, { 10.0, 18.0, 07.0, 17.0 }, { 13.0, 16.0, 09.0, 14.0 }, { 12.0, 19.0, 08.0, 18.0 }, { 14.0, 17.0, 10.0, 19.0 } }; @@ -103,6 +143,7 @@ public void getMaximalAttributeAssignmentsTest_7() { } @Test + @Ignore public void getMaximalAttributeAssignmentsTest_8() { double[][] values = new double[][] { { 1, 1, 1 }, { 0, 1, 1 }, { 1, 1, 0 } }; int[] assignments = AttributeAssignmentResolver.getMaximalAttributeAssignments(values); diff --git a/src/test/java/org/fiware/apps/marketplace/tests/AttributeTypeResolverTest.java b/src/test/java/org/fiware/apps/marketplace/tests/AttributeTypeResolverTest.java index 1d29b8d..d57a703 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/AttributeTypeResolverTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/AttributeTypeResolverTest.java @@ -1,5 +1,36 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -12,6 +43,7 @@ import org.fiware.apps.marketplace.model.ServiceNominalAttributeType; import org.fiware.apps.marketplace.model.ServiceOrdinalAttributeType; import org.fiware.apps.marketplace.model.ServiceRatioAttributeType; +import org.junit.Ignore; import org.junit.Test; public class AttributeTypeResolverTest { @@ -21,6 +53,7 @@ public class AttributeTypeResolverTest { private static final String generalVocUri = "http://appsnserv.testbed.fi-ware.eu/cloudservices/rdf/vocabulary/Vocabulary_General_001"; @Test + @Ignore public void testResolveAttributeTypesFromUri_GeneralVoc() { List generalVocTypes = AttributeTypeResolver.resolveAttributeTypesFromUri(generalVocUri); assertEquals(7, generalVocTypes.size()); @@ -105,6 +138,7 @@ public void testResolveAttributeTypesFromUri_GeneralVoc() { } @Test + @Ignore public void testResolveAttributeTypesFromUri_CloudVoc() { List generalVocTypes = AttributeTypeResolver.resolveAttributeTypesFromUri(cloudVocUri); assertEquals(36, generalVocTypes.size()); @@ -164,6 +198,7 @@ public void testResolveAttributeTypesFromUri_CloudVoc() { } @Test + @Ignore public void testResolveOrdinalValue() { List types = AttributeTypeResolver.resolveAttributeTypesFromUri(amazonUri); assertEquals(20, types.size()); diff --git a/src/test/java/org/fiware/apps/marketplace/tests/AttributeTypeStatisticsResolverTest.java b/src/test/java/org/fiware/apps/marketplace/tests/AttributeTypeStatisticsResolverTest.java index 74ec94f..eafe0e0 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/AttributeTypeStatisticsResolverTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/AttributeTypeStatisticsResolverTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -16,6 +48,7 @@ import org.fiware.apps.marketplace.model.ServiceAttributeTypeStatistics; import org.fiware.apps.marketplace.model.ServiceManifestation; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; public class AttributeTypeStatisticsResolverTest { @@ -62,6 +95,7 @@ public static void setUpBeforeClass() { } @Test + @Ignore public void testResolveStatistics_Keys() { HashMap statisticsMap = AttributeTypeStatisticsResolver.resolveStatistics(types, serviceManifestationList); @@ -83,6 +117,7 @@ public void testResolveStatistics_Keys() { } @Test + @Ignore public void testResolveStatistics_BranchSum() { HashMap statisticsMap = AttributeTypeStatisticsResolver.resolveStatistics(types, serviceManifestationList); @@ -109,6 +144,7 @@ public void testResolveStatistics_BranchSum() { } @Test + @Ignore public void testResolveStatistics_SumIsOne() { assertTrue(getSumOfProbabilities(AttributeTypeStatisticsResolver.resolveStatistics(types, serviceManifestationList)) - 1.0 < epsilon); } diff --git a/src/test/java/org/fiware/apps/marketplace/tests/FillLiveInstance.java b/src/test/java/org/fiware/apps/marketplace/tests/FillLiveInstance.java index d8d9299..9835eed 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/FillLiveInstance.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/FillLiveInstance.java @@ -1,29 +1,63 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.fiware.apps.marketplace.client.ServiceClient; import org.fiware.apps.marketplace.client.StoreClient; import org.fiware.apps.marketplace.client.UserClient; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; +import org.junit.Ignore; import org.junit.Test; public class FillLiveInstance { private static final String BASE_URL = "http://130.206.81.36:8080/FiwareMarketplace/v1"; UserClient userClient = new UserClient(BASE_URL, "demo1234", "demo1234"); - @Test + @Test + @Ignore public void testRegistration() { - Localuser user = new Localuser(); + User user = new User(); user.setCompany("IntegrationCompany"); user.setEmail("integration123@integrationcompany.com"); user.setPassword("integrationUser123"); - user.setUsername("integrationUser123"); + user.setUserName("integrationUser123"); //assertTrue(userClient.save(user)); @@ -45,7 +79,7 @@ public void testRegistration() { service.setUrl("http://130.206.81.36:8080/FiwareRepository/v1/integrationCollection/IntegrationService.usdl"); //assertTrue(serviceClient.update("integrationStore", "integrationOffering", service)); - assertTrue(serviceClient.save("integrationStore", service)); + //assertTrue(serviceClient.save("integrationStore", service)); /* Service service = serviceClient.find("integrationStore", "integrationOffering"); diff --git a/src/test/java/org/fiware/apps/marketplace/tests/OAuthtest.java b/src/test/java/org/fiware/apps/marketplace/tests/OAuthtest.java index 093c46f..a6a9e0e 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/OAuthtest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/OAuthtest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; diff --git a/src/test/java/org/fiware/apps/marketplace/tests/OAuthtestCall.java b/src/test/java/org/fiware/apps/marketplace/tests/OAuthtestCall.java index e0e30a9..27fadcf 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/OAuthtestCall.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/OAuthtestCall.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.File; import java.util.Properties; diff --git a/src/test/java/org/fiware/apps/marketplace/tests/OfferingResolverTest.java b/src/test/java/org/fiware/apps/marketplace/tests/OfferingResolverTest.java index 3e18db9..83c7687 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/OfferingResolverTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/OfferingResolverTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; @@ -9,6 +41,7 @@ import org.fiware.apps.marketplace.helpers.OfferingResolver; import org.fiware.apps.marketplace.model.Offering; +import org.junit.Ignore; import org.junit.Test; public class OfferingResolverTest { @@ -16,6 +49,7 @@ public class OfferingResolverTest { private static final String uri = "http://appsnserv.testbed.fi-ware.eu/cloudservices/rdf/cloudServices/Amazon_EC2_001"; @Test + @Ignore public void testResolveOfferingsFromServiceDescription_Basic() { List offerings = OfferingResolver.resolveOfferingsFromServiceDescription(uri, ""); assertNotNull(offerings); @@ -23,6 +57,7 @@ public void testResolveOfferingsFromServiceDescription_Basic() { } @Test + @Ignore public void testResolveOfferingsFromServiceDescription_ExpectedOfferings() { List offerings = OfferingResolver.resolveOfferingsFromServiceDescription(uri, ""); @@ -46,6 +81,7 @@ public void testResolveOfferingsFromServiceDescription_ExpectedOfferings() { } @Test + @Ignore public void testResolveOfferingsFromServiceDescription_OfferingContent() { List offerings = OfferingResolver.resolveOfferingsFromServiceDescription(uri, ""); for (Offering offering : offerings) { diff --git a/src/test/java/org/fiware/apps/marketplace/tests/OpenJenaTest.java b/src/test/java/org/fiware/apps/marketplace/tests/OpenJenaTest.java index 46b2c61..6305457 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/OpenJenaTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/OpenJenaTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; diff --git a/src/test/java/org/fiware/apps/marketplace/tests/ParticipantTest.java b/src/test/java/org/fiware/apps/marketplace/tests/ParticipantTest.java index a903c84..c337c8c 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/ParticipantTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/ParticipantTest.java @@ -1,11 +1,44 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.fiware.apps.marketplace.client.UserClient; -import org.fiware.apps.marketplace.model.Localuser; +import org.fiware.apps.marketplace.model.User; +import org.junit.Ignore; import org.junit.Test; public class ParticipantTest { @@ -14,9 +47,10 @@ public class ParticipantTest { private static final String BASE_URL = "http://localhost:8080/FiwareMarketplace/v1"; private static UserClient userClient = new UserClient(BASE_URL, "demo1234", "demo1234"); - @Test + @Test + @Ignore public void testRegistration() { - + /* Localuser user = new Localuser(); user.setCompany("SAP"); user.setEmail("demo123@sap.com"); diff --git a/src/test/java/org/fiware/apps/marketplace/tests/RegisterServiceTest.java b/src/test/java/org/fiware/apps/marketplace/tests/RegisterServiceTest.java index e183b96..eb20624 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/RegisterServiceTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/RegisterServiceTest.java @@ -1,11 +1,44 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import junit.framework.TestCase; import org.fiware.apps.marketplace.client.ServiceClient; import org.fiware.apps.marketplace.client.StoreClient; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; +import org.junit.Ignore; import org.junit.Test; public class RegisterServiceTest extends TestCase { @@ -16,8 +49,9 @@ public class RegisterServiceTest extends TestCase { private static ServiceClient serviceClient = new ServiceClient(BASE_URL,"demo", "demo"); @Test + @Ignore public void testRegistration() { - + /* Store store = new Store(); store.setName("testStore"); diff --git a/src/test/java/org/fiware/apps/marketplace/tests/RegisterServiceTestEnhanced.java b/src/test/java/org/fiware/apps/marketplace/tests/RegisterServiceTestEnhanced.java index 7879c15..516020a 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/RegisterServiceTestEnhanced.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/RegisterServiceTestEnhanced.java @@ -1,11 +1,44 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.junit.Assert.*; import org.fiware.apps.marketplace.client.ServiceClient; import org.fiware.apps.marketplace.client.StoreClient; import org.fiware.apps.marketplace.model.Service; import org.fiware.apps.marketplace.model.Store; +import org.junit.Ignore; import org.junit.Test; public class RegisterServiceTestEnhanced { @@ -15,11 +48,12 @@ public class RegisterServiceTestEnhanced { private static ServiceClient serviceClient = new ServiceClient(BASE_URL,"demo", "demo"); @Test + @Ignore /** * Test for registration of authentic cloud services */ public void testRegistrationEnhanced() { - String storeName = "AuthenticCloudServicesStore"; + /*String storeName = "AuthenticCloudServicesStore"; String amazonEC2Name = "Amazon_EC2"; String ElasticHostsCloudHostingName = "ElasticHosts_CloudHosting"; String RackspaceCloudServersName = "Rackspace_CloudServers"; @@ -54,7 +88,7 @@ public void testRegistrationEnhanced() { */ } - private Store createStoreTest(String storeName, String storeURL, String storeDesc){ + /*private Store createStoreTest(String storeName, String storeURL, String storeDesc){ Store store = new Store(); store.setName(storeName); store.setUrl(storeURL); @@ -65,7 +99,7 @@ private Store createStoreTest(String storeName, String storeURL, String storeDes assertNotNull(storeClient.find(storeName)); return store; - } + }*/ private Service createServiceTest(String serviceName, String serviceURL, String storeName){ Service service = new Service(); diff --git a/src/test/java/org/fiware/apps/marketplace/tests/RegisterStoreTest.java b/src/test/java/org/fiware/apps/marketplace/tests/RegisterStoreTest.java index f3c84d0..d959982 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/RegisterStoreTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/RegisterStoreTest.java @@ -1,9 +1,42 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import junit.framework.TestCase; import org.fiware.apps.marketplace.client.StoreClient; import org.fiware.apps.marketplace.model.Store; +import org.junit.Ignore; import org.junit.Test; public class RegisterStoreTest extends TestCase { @@ -12,9 +45,10 @@ public class RegisterStoreTest extends TestCase { private static final String BASE_URL = "http://localhost:8080/FiwareMarketplace/v1"; private static StoreClient storeClient = new StoreClient(BASE_URL, "demo", "demo"); - @Test + @Test + @Ignore public void testRegistration() { - Store store = new Store(); + /*Store store = new Store(); store.setName("testName1235"); store.setUrl("http://www.test1235.de"); @@ -31,7 +65,7 @@ public void testRegistration() { assertEquals(store.getUrl(), "http://www.xxx.de"); assertTrue(storeClient.delete("testName1235")); - assertNull(storeClient.find("testName1235")); + assertNull(storeClient.find("testName1235"));*/ } diff --git a/src/test/java/org/fiware/apps/marketplace/tests/ServiceManifestationComparatorTest.java b/src/test/java/org/fiware/apps/marketplace/tests/ServiceManifestationComparatorTest.java index e40703f..ec8b4ee 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/ServiceManifestationComparatorTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/ServiceManifestationComparatorTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -24,6 +56,7 @@ import org.fiware.apps.marketplace.model.ServiceQualitativeAttribute; import org.fiware.apps.marketplace.model.ServiceQuantitativeAttribute; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; public class ServiceManifestationComparatorTest { @@ -100,6 +133,7 @@ public static void setUpBeforeClass() { } @Test + @Ignore public void testCompare_IdenticalManifestations() { ComparisonResult result = ServiceManifestationComparator.compare(serviceManifestationList.get(0), serviceManifestationList.get(0), typeMap, statisticsMap); @@ -108,6 +142,7 @@ public void testCompare_IdenticalManifestations() { } @Test + @Ignore public void testCompare_UnidenticalManifestations() { ComparisonResult result = ServiceManifestationComparator.compare(serviceManifestationList.get(0), serviceManifestationList.get(1), typeMap, statisticsMap); @@ -116,6 +151,7 @@ public void testCompare_UnidenticalManifestations() { } @Test + @Ignore public void testGetNearestCommonAncestor() { ServiceAttributeType ancestor1 = ServiceManifestationComparatorAccessor.testGetNearestCommonAncestorType( typeMap.get(osVocUri + "#WindowsServer2008R2Standard"), typeMap.get(osVocUri + "#WindowsServer2008R2Enterprise"), typeMap); @@ -134,6 +170,7 @@ public void testGetNearestCommonAncestor() { } @Test + @Ignore public void testGetAffectedSiblings() { ServiceOrdinalAttributeType s1 = (ServiceOrdinalAttributeType) typeMap.get(amazonUri + "#Amazon_Support_ArchitectureSupport_BuildingBlocks"); @@ -190,6 +227,7 @@ public void testGetAffectedSiblings() { } @Test + @Ignore public void testOrdinalSimilarity() { ServiceQualitativeAttribute s1 = new ServiceQualitativeAttribute(); s1.setTypeUri(amazonUri + "#Amazon_Support_ArchitectureSupport_BuildingBlocks"); @@ -202,6 +240,7 @@ public void testOrdinalSimilarity() { } @Test + @Ignore public void testCalculateValueReferencesScore() { ServiceAttribute sourceAttribute = null; for (ServiceManifestation serviceManifestation : serviceManifestationList) { @@ -241,6 +280,7 @@ public void testCalculateValueReferencesScore() { } @Test + @Ignore public void testRatio() { ServiceAttribute ec2Memory = null; ServiceAttribute rackspaceMemory1 = null; @@ -281,6 +321,7 @@ public void testRatio() { } @Test + @Ignore public void testNaNError_1() { ServiceAttribute sourceAttribute = null; @@ -314,6 +355,7 @@ public void testNaNError_1() { } @Test + @Ignore public void testNaNError_2() { // Ratio value comparison of the following attribute returned NaN // http://appsnserv.testbed.fi-ware.eu/cloudservices/rdf/cloudServices/Visi_ReliaCloud_001#resource_CloudServer_CPU_1 @@ -346,6 +388,7 @@ public void testNaNError_2() { } @Test + @Ignore public void testCalculateNumericValuesScore() { ServiceQuantitativeAttribute disk1 = null; ServiceQuantitativeAttribute disk2 = null; @@ -370,6 +413,7 @@ public void testCalculateNumericValuesScore() { } @Test + @Ignore public void testAttributeComparisonOfIPs() { ServiceAttribute ip = null; ServiceAttribute optionalIP = null; diff --git a/src/test/java/org/fiware/apps/marketplace/tests/ServiceManifestationResolverTest.java b/src/test/java/org/fiware/apps/marketplace/tests/ServiceManifestationResolverTest.java index ea97eac..98989d3 100644 --- a/src/test/java/org/fiware/apps/marketplace/tests/ServiceManifestationResolverTest.java +++ b/src/test/java/org/fiware/apps/marketplace/tests/ServiceManifestationResolverTest.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.tests; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2012 SAP + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -17,6 +49,7 @@ import org.fiware.apps.marketplace.model.ServiceQuantitativeAttribute; import org.fiware.apps.marketplace.rdf.RdfHelper; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import com.hp.hpl.jena.rdf.model.Model; @@ -41,6 +74,7 @@ public static void setUpBeforeClass() { } @Test + @Ignore public void testResolveServiceManifestations() { Offering offering = new Offering(); offering.setOfferingUri(baseUri + "#offering_Support_Premium"); @@ -59,6 +93,7 @@ public void testResolveServiceManifestations() { } @Test + @Ignore public void testCreateServiceAttribute_Basic1() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_EC2_Small_Storage", model); @@ -75,6 +110,7 @@ public void testCreateServiceAttribute_Basic1() { } @Test + @Ignore public void testCreateServiceAttribute_Basic2() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_EC2_Small_ComputeUnit", model); @@ -92,6 +128,7 @@ public void testCreateServiceAttribute_Basic2() { } @Test + @Ignore public void testCreateServiceAttribute_Basic3() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_EC2_Small_IO", model); @@ -102,6 +139,7 @@ public void testCreateServiceAttribute_Basic3() { } @Test + @Ignore public void testCreateServiceAttribute_Basic4() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_EC2_DataCentre_EU", model); @@ -114,6 +152,7 @@ public void testCreateServiceAttribute_Basic4() { } @Test + @Ignore public void testCreateServiceAttribute_Basic5() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_Support_Gold_TechSupport", model); @@ -125,6 +164,7 @@ public void testCreateServiceAttribute_Basic5() { } @Test + @Ignore public void testCreateServiceAttribute_MaxDouble() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_Support_Premium_NamedContacts", model); @@ -142,6 +182,7 @@ public void testCreateServiceAttribute_MaxDouble() { } @Test + @Ignore public void testCreateServiceAttribute_ReferencedAttributes1() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_EC2_Small_ComputeUnit", model); @@ -158,6 +199,7 @@ public void testCreateServiceAttribute_ReferencedAttributes1() { } @Test + @Ignore public void testCreateServiceAttribute_ReferencedAttributes2() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_Support_Gold_TechSupport", model); @@ -188,6 +230,7 @@ public void testCreateServiceAttribute_ReferencedAttributes2() { } @Test + @Ignore public void testCreateServiceAttribute_NestedReferencedAttributes1() { ServiceAttribute attr = ServiceManifestationResolverAccessor.testCreateServiceAttribute(baseUri + "#resource_Support_Gold_TechSupport", model); From e64b9025442ab9a738c5c5cb8c9f48cc238fc568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 11:14:49 +0100 Subject: [PATCH 53/69] Modify License.txt --- LICENSE.txt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 7d03051..28d72bf 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -16,13 +16,14 @@ modification, are permitted provided that the following conditions are met: may be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL SAP AG BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file From 7f449a7b0f92c69f0087fb54e028ba8704501d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 12:35:29 +0100 Subject: [PATCH 54/69] Fix problem with visualization --- .../apps/marketplace/oauth2/FIWAREClient.java | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java index 9e78e22..545fc4b 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java @@ -54,7 +54,7 @@ public class FIWAREClient extends BaseOAuth20Client{ - + // To store users information private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); private UserBo userBo = (UserBo) context.getBean("userBo"); @@ -83,43 +83,43 @@ protected boolean requiresStateParameter() { @Override protected FIWAREProfile extractUserProfile(String body) { FIWAREProfile profile = new FIWAREProfile(); - + final JsonNode json = JsonHelper.getFirstNode(body); - if (json != null) { - profile.setId(JsonHelper.get(json, "nickName")); - for (final String attribute : new FIWAREAttributesDefinition().getPrincipalAttributes()) { - profile.addAttribute(attribute, JsonHelper.get(json, attribute)); - } - } - - // FIXME: By default, we are adding the default Role... - profile.addRole("ROLE_USER"); - - // User information should be stored in the local users table // - User user; - String username = (String) profile.getUsername(); - String email = (String) profile.getEmail(); - String displayName = (String) profile.getDisplayName(); - - try { - // Modify the existing user + if (json != null) { + profile.setId(JsonHelper.get(json, "nickName")); + for (final String attribute : new FIWAREAttributesDefinition().getPrincipalAttributes()) { + profile.addAttribute(attribute, JsonHelper.get(json, attribute)); + } + } + + // FIXME: By default, we are adding the default Role... + profile.addRole("ROLE_USER"); + + // User information should be stored in the local users table // + User user; + String username = (String) profile.getUsername(); + String email = (String) profile.getEmail(); + String displayName = (String) profile.getDisplayName(); + + try { + // Modify the existing user user = userBo.findByName(username); } catch (UserNotFoundException e) { // Create a new user user = new User(); user.setRegistrationDate(new Date()); } - - // Set field values - user.setUserName(username); - user.setEmail(email); - user.setPassword(""); // Password cannot be NULL - user.setDisplayName(displayName); - - // Save the new user - userBo.save(user); - - return profile; + + // Set field values + user.setUserName(username); + user.setEmail(email); + user.setPassword(""); // Password cannot be NULL + user.setDisplayName(displayName); + + // Save the new user + userBo.save(user); + + return profile; } @Override @@ -129,14 +129,14 @@ protected String getProfileUrl(Token arg0) { @Override protected boolean hasBeenCancelled(WebContext context) { - final String error = context.getRequestParameter(OAuthCredentialsException.ERROR); - - // user has denied permissions - if ("access_denied".equals(error)) { - return true; - } else { - return false; - } + final String error = context.getRequestParameter(OAuthCredentialsException.ERROR); + + // user has denied permissions + if ("access_denied".equals(error)) { + return true; + } else { + return false; + } } @Override From 162a8ccf6fb36ff4ff3e4f2cdc92bef875662ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 12:36:01 +0100 Subject: [PATCH 55/69] Add coverage plugin --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 7b5f4ae..0730829 100644 --- a/pom.xml +++ b/pom.xml @@ -280,6 +280,11 @@ maven-dependency-plugin 2.9 + + org.codehaus.mojo + cobertura-maven-plugin + 2.6 + From 26b1f2bc5dbc75f222fee05faa38639909238ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 12:48:05 +0100 Subject: [PATCH 56/69] Add tests for XML Adapters --- .../HiddenFieldsXMLAdapterTest.java | 53 ++++++++++++++++ .../xmladapters/StoreXMLAdapterTest.java | 63 +++++++++++++++++++ .../utils/xmladapters/UserXMLAdapterTest.java | 63 +++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 src/test/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapterTest.java create mode 100644 src/test/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapterTest.java create mode 100644 src/test/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapterTest.java diff --git a/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapterTest.java b/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapterTest.java new file mode 100644 index 0000000..571524a --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/HiddenFieldsXMLAdapterTest.java @@ -0,0 +1,53 @@ +package org.fiware.apps.marketplace.utils.xmladapters; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import static org.assertj.core.api.Assertions.*; +import org.junit.Test; + +public class HiddenFieldsXMLAdapterTest { + + private HiddenFieldsXMLAdapter adapter = new HiddenFieldsXMLAdapter(); + + @Test + public void testUnmarshall() throws Exception { + String content = "content"; + assertThat(adapter.unmarshal(content)).isEqualTo(content); + } + + @Test + public void testMarshall() throws Exception { + String content = "content"; + assertThat(adapter.marshal(content)).isEqualTo(null); + } +} diff --git a/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapterTest.java b/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapterTest.java new file mode 100644 index 0000000..d274387 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/StoreXMLAdapterTest.java @@ -0,0 +1,63 @@ +package org.fiware.apps.marketplace.utils.xmladapters; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import static org.assertj.core.api.Assertions.*; + +import org.fiware.apps.marketplace.model.Store; +import org.junit.Test; + +public class StoreXMLAdapterTest { + + private StoreXMLAdapter adapter = new StoreXMLAdapter(); + + @Test + public void testUnmarshall() throws Exception { + // Store information is not unmarshalled. When a service is + // created, the store is deduced based on the URL + assertThat(adapter.unmarshal("content")).isEqualTo(null); + } + + @Test + public void testMarshallValidValue() throws Exception { + Store store = new Store(); + store.setName("fiware"); + assertThat(adapter.marshal(store)).isEqualTo(store.getName()); + } + + @Test + public void testMarshallNull() throws Exception { + Store store = new Store(); + assertThat(adapter.marshal(store)).isEqualTo(null); + } +} diff --git a/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapterTest.java b/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapterTest.java new file mode 100644 index 0000000..ca3003f --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/utils/xmladapters/UserXMLAdapterTest.java @@ -0,0 +1,63 @@ +package org.fiware.apps.marketplace.utils.xmladapters; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import static org.assertj.core.api.Assertions.*; + +import org.fiware.apps.marketplace.model.User; +import org.junit.Test; + +public class UserXMLAdapterTest { + + private UserXMLAdapter adapter = new UserXMLAdapter(); + + @Test + public void testUnmarshall() throws Exception { + // User information is not unmarshalled since the + // session information is used + assertThat(adapter.unmarshal("content")).isEqualTo(null); + } + + @Test + public void testMarshallValidValue() throws Exception { + User user = new User(); + user.setUserName("fiware"); + assertThat(adapter.marshal(user)).isEqualTo(user.getUserName()); + } + + @Test + public void testMarshallNull() throws Exception { + User user = new User(); + assertThat(adapter.marshal(user)).isEqualTo(null); + } +} From 2b4005f808e8ad125d833979f30a76fcc541a114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 15:17:34 +0100 Subject: [PATCH 57/69] Tests for AuthUtils --- .../marketplace/security/auth/AuthUtils.java | 6 +- .../security/auth/AuthUtilsTest.java | 153 ++++++++++++++++++ 2 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/security/auth/AuthUtilsTest.java diff --git a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java index d2adc7b..fc2e19f 100644 --- a/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java +++ b/src/main/java/org/fiware/apps/marketplace/security/auth/AuthUtils.java @@ -35,8 +35,8 @@ import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; -import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.pac4j.springframework.security.authentication.ClientAuthenticationToken; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; @@ -45,7 +45,7 @@ public class AuthUtils { //Instance attributes - private UserBo localuserBo = (UserBo) ApplicationContextProvider.getApplicationContext().getBean("userBo"); + @Autowired private UserBo localuserBo; public User getLoggedUser() throws UserNotFoundException { String userName; @@ -55,7 +55,7 @@ public User getLoggedUser() throws UserNotFoundException { if (authentication instanceof ClientAuthenticationToken) { userName = ((ClientAuthenticationToken) authentication).getUserProfile().getId(); } else { - userName = SecurityContextHolder.getContext().getAuthentication().getName(); + userName = authentication.getName(); } return localuserBo.findByName(userName); diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/AuthUtilsTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/AuthUtilsTest.java new file mode 100644 index 0000000..e13a4d6 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/AuthUtilsTest.java @@ -0,0 +1,153 @@ +package org.fiware.apps.marketplace.security.auth; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; + +import java.util.Collection; + +import org.fiware.apps.marketplace.bo.UserBo; +import org.fiware.apps.marketplace.model.User; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.pac4j.core.profile.UserProfile; +import org.pac4j.springframework.security.authentication.ClientAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; + +public class AuthUtilsTest { + + @Mock private UserBo userBoMock; + @InjectMocks private AuthUtils authUtils; + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } + + private void testGeneric(User user, SecurityContext context) { + try { + String userName = user.getUserName(); + + // Configure the mocks + when(userBoMock.findByName(userName)).thenReturn(user); + + // Configure the context returned by the SecurityContextHolder + SecurityContextHolder.setContext(context); + + // Call the function + User returnedUser = authUtils.getLoggedUser(); + + verify(userBoMock).findByName(userName); + assertThat(returnedUser).isEqualTo(user); + } catch (Exception ex) { + fail("Exception " + ex + " not expected"); + } + } + + @Test + public void testOAuth2() { + // User + final String userName = "oauth2username"; + User user = new User(); + user.setUserName(userName); + + // The context + SecurityContext context = new SecurityContext() { + + private static final long serialVersionUID = 1L; + + @Override + public void setAuthentication(Authentication auth) { + } + + @Override + public Authentication getAuthentication() { + UserProfile userProfile = new UserProfile(); + userProfile.setId(userName); + ClientAuthenticationToken auth = new ClientAuthenticationToken(null, "FIWARE", userProfile, null); + return auth; + } + }; + + testGeneric(user, context); + } + + @Test + public void testLocalLogin() { + // The user + final String userName = "oauth2username"; + User user = new User(); + user.setUserName(userName); + + // The context + SecurityContext context = new SecurityContext() { + + private static final long serialVersionUID = 1L; + + @Override + public void setAuthentication(Authentication arg0) { + + } + + @Override + public Authentication getAuthentication() { + UserProfile userProfile = new UserProfile(); + userProfile.setId(userName); + Authentication auth = new Authentication() { + + private static final long serialVersionUID = 1L; + + @Override + public String getName() { + return userName; + } + + @Override + public void setAuthenticated(boolean arg0) throws IllegalArgumentException { + } + + @Override + public boolean isAuthenticated() { + return true; + } + + @Override + public Object getPrincipal() { + return null; + } + + @Override + public Object getDetails() { + return null; + } + + @Override + public Object getCredentials() { + return null; + } + + @Override + public Collection getAuthorities() { + return null; + } + }; + + return auth; + } + }; + + testGeneric(user, context); + } + + + + + +} From dd3685c8b5bcb5e599a8fb68d1f44748cdc9fcd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 15:22:21 +0100 Subject: [PATCH 58/69] Add license to AuthUtilsTest --- .../security/auth/AuthUtilsTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/test/java/org/fiware/apps/marketplace/security/auth/AuthUtilsTest.java b/src/test/java/org/fiware/apps/marketplace/security/auth/AuthUtilsTest.java index e13a4d6..be802cb 100644 --- a/src/test/java/org/fiware/apps/marketplace/security/auth/AuthUtilsTest.java +++ b/src/test/java/org/fiware/apps/marketplace/security/auth/AuthUtilsTest.java @@ -1,5 +1,38 @@ package org.fiware.apps.marketplace.security.auth; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.when; From b1127433f9f6ef954c83d1cdfe91d04f79574c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 17:17:17 +0100 Subject: [PATCH 59/69] Remove unneeded dependencies and tests --- pom.xml | 18 +- .../apps/marketplace/tests/OAuthtest.java | 202 ------------------ .../apps/marketplace/tests/OAuthtestCall.java | 61 ------ 3 files changed, 6 insertions(+), 275 deletions(-) delete mode 100644 src/test/java/org/fiware/apps/marketplace/tests/OAuthtest.java delete mode 100644 src/test/java/org/fiware/apps/marketplace/tests/OAuthtestCall.java diff --git a/pom.xml b/pom.xml index 0730829..4ac5169 100644 --- a/pom.xml +++ b/pom.xml @@ -45,18 +45,6 @@ - - - net.oauth.core - oauth - 20090825 - - - - net.oauth.core - oauth-httpclient4 - 20090617 - @@ -284,6 +272,12 @@ org.codehaus.mojo cobertura-maven-plugin 2.6 + + + html + xml + + diff --git a/src/test/java/org/fiware/apps/marketplace/tests/OAuthtest.java b/src/test/java/org/fiware/apps/marketplace/tests/OAuthtest.java deleted file mode 100644 index a6a9e0e..0000000 --- a/src/test/java/org/fiware/apps/marketplace/tests/OAuthtest.java +++ /dev/null @@ -1,202 +0,0 @@ -package org.fiware.apps.marketplace.tests; - -/* - * #%L - * FiwareMarketplace - * %% - * Copyright (C) 2012 SAP - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of copyright holders nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import net.oauth.OAuth; -import net.oauth.OAuthAccessor; -import net.oauth.OAuthConsumer; -import net.oauth.OAuthException; -import net.oauth.OAuthMessage; -import net.oauth.OAuthServiceProvider; -import net.oauth.client.OAuthClient; -import net.oauth.client.httpclient4.HttpClient4; -import net.oauth.client.httpclient4.HttpClientPool; - -import org.apache.http.conn.ClientConnectionManager; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; -import org.apache.http.params.HttpParams; - - - -public class OAuthtest { - - private Properties props; - private File propFile; - - public OAuthtest(Properties props, File propFile) { - super(); - this.props = props; - this.propFile = propFile; - } - - private void updateProperties(String msg) throws IOException { - props.store(new FileOutputStream(propFile), msg); - } - - private OAuthAccessor createOAuthAccessor() { - String consumerKey = props.getProperty("consumerKey"); - String callbackUrl = null; - String consumerSecret = props.getProperty("consumerSecret"); - String reqUrl = props.getProperty("requestUrl"); - String authzUrl = props.getProperty("authorizationUrl"); - String accessUrl = props.getProperty("accessUrl"); - OAuthServiceProvider provider = new OAuthServiceProvider(reqUrl, - authzUrl, accessUrl); - OAuthConsumer consumer = new OAuthConsumer(callbackUrl, consumerKey, - consumerSecret, provider); - return new OAuthAccessor(consumer); - } - - private OAuthMessage sendRequest(Map map, String url) throws IOException, - URISyntaxException, OAuthException { - List params = new ArrayList(); - Iterator it = map.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry p = (Map.Entry) it.next(); - params.add(new OAuth.Parameter((String) p.getKey(), (String) p - .getValue())); - } - OAuthAccessor accessor = createOAuthAccessor(); - accessor.tokenSecret = props.getProperty("tokenSecret"); - OAuthClient client = new OAuthClient( - new HttpClient4(new SingleClient())); - return client.invoke(accessor, "GET", url, params); - } - - public String prepareOAuthHeaderForAccesingResources(Properties props, - String method, String resource, String updateStatus) - throws Exception { - OAuthMessage message = new OAuthMessage(method, resource, null, null); - message.addParameter(OAuth.OAUTH_NONCE, System.nanoTime() + ""); - message.addParameter(OAuth.OAUTH_VERSION, OAuth.VERSION_1_0); - message.addParameter(OAuth.OAUTH_TIMESTAMP, - (System.currentTimeMillis() / 1000) + ""); - message.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1); - message.addParameter(OAuth.OAUTH_TOKEN, props - .getProperty("accessToken")); - message.addParameter(OAuth.OAUTH_CONSUMER_KEY, props - .getProperty("consumerKey")); - - if (updateStatus != null) { - // the parameter used by twitter on - message.addParameter("status", updateStatus); - } - - OAuthServiceProvider provider = new OAuthServiceProvider(props - .getProperty("requestUrl"), props - .getProperty("authorizationUrl"), props - .getProperty("accessUrl")); - OAuthConsumer consumer = new OAuthConsumer("", props - .getProperty("consumerKey"), props - .getProperty("consumerSecret"), provider); - OAuthAccessor accessor = new OAuthAccessor(consumer); - accessor.tokenSecret = props.getProperty("tokenSecret"); - message.sign(accessor); - - return message.getAuthorizationHeader(resource); - } - - public void request() throws Exception { - OAuthAccessor accessor = createOAuthAccessor(); - HttpClient4 httpClient = new HttpClient4(new SingleClient()); - OAuthClient client = new OAuthClient(httpClient); - client.getRequestToken(accessor); - props.setProperty("requestToken", accessor.requestToken); - props.setProperty("tokenSecret", accessor.tokenSecret); - updateProperties("Last action: added requestToken"); - } - - public String authorize() throws Exception { - // just print the redirect - Properties paramProps = new Properties(); - paramProps - .setProperty("application_name", props.getProperty("appName")); - paramProps - .setProperty("oauth_token", props.getProperty("requestToken")); - OAuthAccessor accessor = createOAuthAccessor(); - OAuthMessage response = sendRequest(paramProps, - accessor.consumer.serviceProvider.userAuthorizationURL); - return response.URL; - } - - public void access() throws Exception { - Properties paramProps = new Properties(); - paramProps - .setProperty("oauth_token", props.getProperty("requestToken")); - OAuthMessage response = sendRequest(paramProps, props - .getProperty("accessUrl")); - - props.setProperty("accessToken", response.getParameter("oauth_token")); - props.setProperty("tokenSecret", response - .getParameter("oauth_token_secret")); - props.setProperty("userId", response.getParameter("user_id")); - updateProperties("Last action: added accessToken"); - } - - public class SingleClient implements HttpClientPool { - SingleClient() { - org.apache.http.client.HttpClient client = new DefaultHttpClient(); - ClientConnectionManager mgr = client.getConnectionManager(); - if (!(mgr instanceof ThreadSafeClientConnManager)) { - HttpParams params = client.getParams(); - client = new DefaultHttpClient(new ThreadSafeClientConnManager( - params, mgr.getSchemeRegistry()), params); - } - - // Use Proxy to access if you are in one of the countries that cannot connects to twitter directly. - // HttpHost proxy = new HttpHost("your_proxy_url", your_proxy_port); - // client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, - // proxy); - - this.client = client; - } - - private final org.apache.http.client.HttpClient client; - - public org.apache.http.client.HttpClient getHttpClient(URL server) { - return client; - } - } -} diff --git a/src/test/java/org/fiware/apps/marketplace/tests/OAuthtestCall.java b/src/test/java/org/fiware/apps/marketplace/tests/OAuthtestCall.java deleted file mode 100644 index 27fadcf..0000000 --- a/src/test/java/org/fiware/apps/marketplace/tests/OAuthtestCall.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.fiware.apps.marketplace.tests; - -/* - * #%L - * FiwareMarketplace - * %% - * Copyright (C) 2012 SAP - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of copyright holders nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -import java.io.File; -import java.util.Properties; - -public class OAuthtestCall { - - - public static void main(String[] args) throws Exception { - - Properties props = new Properties(); - File propFile = null; - - props.setProperty("consumerKey", "fwa"); - props.setProperty("consumerSecret", ""); - props.setProperty("requestUrl", "http://localhost:8080/FiwareMarketplace/v1/registration/stores/"); - props.setProperty("authorizationUrl", "http://localhost:8080/FiwareMarketplace/v1/registration/stores/"); - props.setProperty("accessUrl", "http://localhost:8080/FiwareMarketplace/v1/registration/stores/"); - props.setProperty("tokenSecret", ""); - - OAuthtest oauthHelper; - oauthHelper = new OAuthtest(props, propFile); - - oauthHelper.request(); - - } - - -} \ No newline at end of file From 9c53fc0f12b3d5c5478fd38bd3d7bea44ccf9db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 17:17:53 +0100 Subject: [PATCH 60/69] Tests for FIWARE OAuth2 --- .../marketplace/dao/impl/UserDaoImpl.java | 3 +- .../apps/marketplace/oauth2/FIWAREClient.java | 7 +- .../marketplace/oauth2/FIWAREProfile.java | 5 - .../marketplace/oauth2/FIWAREApiTest.java | 75 +++++++++ .../marketplace/oauth2/FIWAREClientTest.java | 144 ++++++++++++++++++ .../marketplace/oauth2/FIWAREProfileTest.java | 64 ++++++++ 6 files changed, 286 insertions(+), 12 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREApiTest.java create mode 100644 src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREClientTest.java create mode 100644 src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREProfileTest.java diff --git a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java index a8b0488..25edece 100644 --- a/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java +++ b/src/main/java/org/fiware/apps/marketplace/dao/impl/UserDaoImpl.java @@ -52,8 +52,7 @@ public void save(User user) { @Override public void update(User user) { - getHibernateTemplate().update(user); - + getHibernateTemplate().update(user); } @Override diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java index 545fc4b..4e1540e 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java @@ -37,7 +37,6 @@ import org.fiware.apps.marketplace.bo.UserBo; import org.fiware.apps.marketplace.exceptions.UserNotFoundException; import org.fiware.apps.marketplace.model.User; -import org.fiware.apps.marketplace.utils.ApplicationContextProvider; import org.pac4j.core.client.BaseClient; import org.pac4j.core.context.WebContext; import org.pac4j.oauth.client.BaseOAuth20Client; @@ -48,16 +47,14 @@ import org.scribe.model.Token; import org.scribe.model.SignatureType; import org.scribe.oauth.ProxyOAuth20ServiceImpl; -import org.springframework.context.ApplicationContext; +import org.springframework.beans.factory.annotation.Autowired; import com.fasterxml.jackson.databind.JsonNode; - public class FIWAREClient extends BaseOAuth20Client{ // To store users information - private ApplicationContext context = ApplicationContextProvider.getApplicationContext(); - private UserBo userBo = (UserBo) context.getBean("userBo"); + @Autowired private UserBo userBo; private String scopeValue = ""; diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java index c6d9f78..23a2795 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREProfile.java @@ -47,10 +47,5 @@ public String getDisplayName() { public String getUsername() { return (String) this.getAttribute("nickName"); } - - @Override - public String getTypedId() { - return super.getTypedId(); - } } diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREApiTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREApiTest.java new file mode 100644 index 0000000..8acc24a --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREApiTest.java @@ -0,0 +1,75 @@ +package org.fiware.apps.marketplace.oauth2; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.scribe.extractors.JsonTokenExtractor; +import org.scribe.model.OAuthConfig; +import org.scribe.model.Verb; +import org.scribe.utils.OAuthEncoder; + +public class FIWAREApiTest { + + private FIWAREApi api = new FIWAREApi(); + + @Test + public void testGetAuthorizationUrl() { + String clientId = "1"; + String redirectURI = "http://fi-ware.org"; + String scope = "profile,store"; + OAuthConfig config = new OAuthConfig(clientId, null, redirectURI, null, scope, null); + String expectedURL = "https://account.lab.fi-ware.org/authorize?client_id=" + clientId + + "&redirect_uri=" + OAuthEncoder.encode(redirectURI) + "&scope=" + + OAuthEncoder.encode(scope) + "&response_type=code"; + + assertThat(api.getAuthorizationUrl(config)).isEqualTo(expectedURL); + } + + @Test + public void testGetAccessTokenEndpoint() { + assertThat(api.getAccessTokenEndpoint()).isEqualTo("https://account.lab.fi-ware.org/token"); + } + + @Test + public void testGetAccessTokenVerb() { + assertThat(api.getAccessTokenVerb()).isEqualTo(Verb.POST); + } + + @Test + public void testGetAccessTokenExtractor() { + assertThat(api.getAccessTokenExtractor()).isInstanceOf(JsonTokenExtractor.class); + } + +} diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREClientTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREClientTest.java new file mode 100644 index 0000000..dbe8ee3 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREClientTest.java @@ -0,0 +1,144 @@ +package org.fiware.apps.marketplace.oauth2; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import org.fiware.apps.marketplace.bo.UserBo; +import org.fiware.apps.marketplace.exceptions.UserNotFoundException; +import org.fiware.apps.marketplace.model.User; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.pac4j.core.context.WebContext; + +public class FIWAREClientTest { + + @Mock private UserBo userBoMock; + @InjectMocks private FIWAREClient client = new FIWAREClient(); + + + @Before + public void initMocks() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testRequiresStateParameter() { + assertThat(client.requiresStateParameter()).isFalse(); + } + + private void testExtractUserProfile(boolean userExist) { + try { + // This JSON simulates a response from the IdM + String userName = "user"; + String displayName = "User Name"; + String email = "user@fiware.org"; + String json = "{\"id\":1,\"actorId\":2487,\"nickName\":\"" + userName + "\"," + + "\"displayName\":\"" + displayName + "\",\"email\":\"" + email + "\"}"; + + // Mock + if (userExist) { + User user = new User(); + user.setId(1); + user.setUserName(userName + "_old"); + user.setDisplayName(displayName + "_old"); + user.setEmail(email + "_old"); + when(userBoMock.findByName(userName)).thenReturn(user); + } else { + doThrow(new UserNotFoundException("user not found")).when(userBoMock).findByName(userName); + } + + // Call the function + FIWAREProfile profile = client.extractUserProfile(json); + + // Check the profile + assertThat(profile.getId()).isEqualTo(userName); + assertThat(profile.getDisplayName()).isEqualTo(displayName); + assertThat(profile.getEmail()).isEqualTo(email); + + // Capture the user saved in the database + ArgumentCaptor captor = ArgumentCaptor.forClass(User.class); + verify(userBoMock).save(captor.capture()); + + User storedUser = captor.getValue(); + assertThat(storedUser.getUserName()).isEqualTo(userName); + assertThat(storedUser.getEmail()).isEqualTo(email); + assertThat(storedUser.getPassword()).isEqualTo(""); + assertThat(storedUser.getEmail()).isEqualTo(email); + } catch (Exception ex) { + fail("Exception " + ex + " not expected"); + } + } + + @Test + public void testExtractUserProfileUserExists() { + testExtractUserProfile(true); + } + + @Test + public void testExtractUserProfileUserDoesNotExist() { + testExtractUserProfile(false); + } + + @Test + public void testGetProfileUrl() { + assertThat(client.getProfileUrl(null)).isEqualTo("https://account.lab.fi-ware.org/user"); + } + + private void testHasBeenCancelled(String error, boolean cancelled) { + WebContext context = mock(WebContext.class); + when(context.getRequestParameter(anyString())).thenReturn(error); + assertThat(client.hasBeenCancelled(context)).isEqualTo(cancelled); + } + + @Test + public void testCancelled() { + testHasBeenCancelled("access_denied", true); + } + + @Test + public void testNotCancelled() { + testHasBeenCancelled("internal_error", false); + } + + @Test + public void testNewClient() { + assertThat(client.newClient()).isInstanceOf(FIWAREClient.class); + } + +} diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREProfileTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREProfileTest.java new file mode 100644 index 0000000..88a79de --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREProfileTest.java @@ -0,0 +1,64 @@ +package org.fiware.apps.marketplace.oauth2; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +import org.junit.Test; + + +public class FIWAREProfileTest { + + private FIWAREProfile profile = spy(new FIWAREProfile()); + + @Test + public void testGetDisplayName() { + String displayName = "Display Name"; + when(profile.getAttribute(anyString())).thenReturn(displayName); + assertThat(profile.getDisplayName()).isEqualTo(displayName); + verify(profile).getAttribute("displayName"); + } + + @Test + public void testUserName() { + String userName = "userName"; + when(profile.getAttribute(anyString())).thenReturn(userName); + assertThat(profile.getUsername()).isEqualTo(userName); + verify(profile).getAttribute("nickName"); + } + + + +} From 00ad957732ea8c372790f495a5a5695bd78cbf40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 17:30:19 +0100 Subject: [PATCH 61/69] Return null if body is null --- .../apps/marketplace/oauth2/FIWAREClient.java | 61 ++++++++++--------- .../marketplace/oauth2/FIWAREClientTest.java | 10 +++ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java index 4e1540e..1942986 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREClient.java @@ -80,43 +80,46 @@ protected boolean requiresStateParameter() { @Override protected FIWAREProfile extractUserProfile(String body) { FIWAREProfile profile = new FIWAREProfile(); - - final JsonNode json = JsonHelper.getFirstNode(body); - if (json != null) { + + if (body != null) { + final JsonNode json = JsonHelper.getFirstNode(body); profile.setId(JsonHelper.get(json, "nickName")); for (final String attribute : new FIWAREAttributesDefinition().getPrincipalAttributes()) { profile.addAttribute(attribute, JsonHelper.get(json, attribute)); } - } - // FIXME: By default, we are adding the default Role... - profile.addRole("ROLE_USER"); - - // User information should be stored in the local users table // - User user; - String username = (String) profile.getUsername(); - String email = (String) profile.getEmail(); - String displayName = (String) profile.getDisplayName(); - - try { - // Modify the existing user - user = userBo.findByName(username); - } catch (UserNotFoundException e) { - // Create a new user - user = new User(); - user.setRegistrationDate(new Date()); - } - // Set field values - user.setUserName(username); - user.setEmail(email); - user.setPassword(""); // Password cannot be NULL - user.setDisplayName(displayName); + // FIXME: By default, we are adding the default Role... + profile.addRole("ROLE_USER"); - // Save the new user - userBo.save(user); + // User information should be stored in the local users table // + User user; + String username = (String) profile.getUsername(); + String email = (String) profile.getEmail(); + String displayName = (String) profile.getDisplayName(); + + try { + // Modify the existing user + user = userBo.findByName(username); + } catch (UserNotFoundException e) { + // Create a new user + user = new User(); + user.setRegistrationDate(new Date()); + } - return profile; + // Set field values + user.setUserName(username); + user.setEmail(email); + user.setPassword(""); // Password cannot be NULL + user.setDisplayName(displayName); + + // Save the new user + userBo.save(user); + + return profile; + } else { + return null; + } } @Override diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREClientTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREClientTest.java index dbe8ee3..f51a33b 100644 --- a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREClientTest.java +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREClientTest.java @@ -114,6 +114,16 @@ public void testExtractUserProfileUserExists() { public void testExtractUserProfileUserDoesNotExist() { testExtractUserProfile(false); } + + @Test + public void testExtractUserProfileNull() { + // Call the function + FIWAREProfile profile = client.extractUserProfile(null); + + // Assertions + assertThat(profile).isNull(); + verify(userBoMock, never()).save(isA(User.class)); + } @Test public void testGetProfileUrl() { From ea375dba0c71021d0ec1592d70b8b0b15b6415d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Tue, 23 Dec 2014 17:59:28 +0100 Subject: [PATCH 62/69] Use JaCoCo for cobertura reporting --- pom.xml | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 4ac5169..c6742e0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.fiware.apps.marketplace FiwareMarketplace war - 4.1.1-SNAPSHOT + 4.1.3-SNAPSHOT FiwareMarketplace Webapp http://maven.apache.org @@ -65,6 +65,7 @@ org.mockito mockito-core 1.10.8 + test @@ -256,29 +257,41 @@ FiwareMarketplace + maven-compiler-plugin - 1.6 - 1.6 + 1.7 + 1.7 3.2 + maven-dependency-plugin 2.9 + - org.codehaus.mojo - cobertura-maven-plugin - 2.6 - - - html - xml - - + org.jacoco + jacoco-maven-plugin + 0.7.2.201409121644 + + + + prepare-agent + + + + report + prepare-package + + report + + + + From 0c899d6f842e8376f64a2a5395cabcbe1b9c3849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 29 Dec 2014 18:57:25 +0100 Subject: [PATCH 63/69] Enable authorization using the X-Auth-Token header --- .../FIWAREHeaderAuthenticationFilter.java | 193 ++++++++++++++++++ .../spring/config/securityOAuth2.xml | 15 +- 2 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java new file mode 100644 index 0000000..6c03f42 --- /dev/null +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java @@ -0,0 +1,193 @@ +package org.fiware.apps.marketplace.oauth2; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.pac4j.core.profile.UserProfile; +import org.pac4j.oauth.credentials.OAuthCredentials; +import org.pac4j.springframework.security.authentication.ClientAuthenticationToken; +import org.pac4j.springframework.security.authentication.CopyRolesUserDetailsService; +import org.springframework.security.authentication.AccountStatusUserDetailsChecker; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.AuthenticationUserDetailsService; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsChecker; +import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; +import org.springframework.security.web.authentication.session.SessionAuthenticationException; +import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; +import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.util.StringUtils; + +/** + * Filter that will identify a user when the X-Auth-Header is specified in a request to the API + * @author aitor + * + */ +public class FIWAREHeaderAuthenticationFilter extends AbstractAuthenticationProcessingFilter{ + + private String headerName; + private UserDetailsChecker userDetailsChecker = new AccountStatusUserDetailsChecker(); + private AuthenticationUserDetailsService userDetailsService = + new CopyRolesUserDetailsService(); + + private FIWAREClient client; + + protected FIWAREHeaderAuthenticationFilter() { + this("/api/", "X-Auth-Token"); + } + + protected FIWAREHeaderAuthenticationFilter(String baseUrl, String headerName) { + // Super class constructor must be called. + super(new FIWAREHeaderAuthenticationRequestMatcher(baseUrl, headerName)); + + // Store header name + this.headerName = headerName; + + // Needed to continue with the process of the request + setContinueChainBeforeSuccessfulAuthentication(true); + + // Set the authentication in the context + setSessionAuthenticationStrategy(new FIWAREHeaderAuthenticationAuthenticationStrategy()); + + // This handler doesn't do anything but it's required to replace the default one + setAuthenticationSuccessHandler(new FIWAREHeaderAuthenticationSuccessHandler()); + } + + @Override + public Authentication attemptAuthentication(HttpServletRequest request, + HttpServletResponse response) throws AuthenticationException, + IOException, ServletException { + + Authentication auth = null; + String authToken = request.getHeader(headerName); + + try { + // This method can return an exception when the Token is invalid + // In this case, the exception is caught and the correct exceptions is thrown... + UserProfile profile = client.getUserProfile(authToken); + + // by default, no authorities + Collection authorities = new ArrayList(); + + // get user details and check them + if (this.userDetailsService != null) { + final ClientAuthenticationToken tmpToken = new ClientAuthenticationToken(null, + client.getName(), profile, null); + final UserDetails userDetails = this.userDetailsService.loadUserDetails(tmpToken); + + if (userDetails != null) { + this.userDetailsChecker.check(userDetails); + authorities = userDetails.getAuthorities(); + } + } + + // new token with credentials (like previously) and user profile and authorities + OAuthCredentials credentials = new OAuthCredentials(null, authToken, "", client.getName()); + auth = new ClientAuthenticationToken(credentials, client.getName(), profile, authorities); + + } catch (Exception ex) { + throw new BadCredentialsException("The provided token is invalid or the system was not able to check it"); + // Nothing to do... + } + + + return auth; + } + + public FIWAREClient getClient() { + return this.client; + } + + public void setClient(FIWAREClient client) { + this.client = client; + } + + // AUXILIAR CLASSES // + + /** + * Request Matcher that specifies when the filter should be executed. In this case we + * want the filter to be executed when the following two conditions are true: + * 1) The request is to the API (/api/...) + * 2) The X-Auth-Token header is present (X-Auth-Token: ...) + * @author aitor + * + */ + private static class FIWAREHeaderAuthenticationRequestMatcher implements RequestMatcher { + + private String baseUrl; + private String headerName; + + public FIWAREHeaderAuthenticationRequestMatcher(String baseUrl, String headerName) { + this.baseUrl = baseUrl; + this.headerName = headerName; + } + + @Override + public boolean matches(HttpServletRequest request) { + + String authToken = request.getHeader(headerName); + + // Get path + String url = request.getServletPath(); + String pathInfo = request.getPathInfo(); + String query = request.getQueryString(); + + if (pathInfo != null || query != null) { + StringBuilder sb = new StringBuilder(url); + + if (pathInfo != null) { + sb.append(pathInfo); + } + + if (query != null) { + sb.append('?').append(query); + } + url = sb.toString(); + } + + return url.startsWith(baseUrl) && authToken != null && StringUtils.hasText(authToken);} + + } + + /** + * Actions to be carried out when the authentication is successful. In this case + * no actions are required. + * @author aitor + */ + private static class FIWAREHeaderAuthenticationSuccessHandler implements AuthenticationSuccessHandler { + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, + HttpServletResponse response, Authentication authentication) + throws IOException, ServletException { + // Nothing to do... The chain will continue + } + } + + /** + * Set the session in the context when the Authorization token is valid + * @author aitor + * + */ + private static class FIWAREHeaderAuthenticationAuthenticationStrategy implements SessionAuthenticationStrategy { + + @Override + public void onAuthentication(Authentication authentication, + HttpServletRequest request, HttpServletResponse response) + throws SessionAuthenticationException { + // Set the authentication in the current context + SecurityContextHolder.getContext().setAuthentication(authentication); + } + + } +} diff --git a/src/main/resources/spring/config/securityOAuth2.xml b/src/main/resources/spring/config/securityOAuth2.xml index 6a355b1..582ba5c 100644 --- a/src/main/resources/spring/config/securityOAuth2.xml +++ b/src/main/resources/spring/config/securityOAuth2.xml @@ -12,9 +12,10 @@ - - - + + + + @@ -58,6 +59,14 @@ + + + + + + + From 1d43eb2720d84a05dd6aaa545927c676cc9f62d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 31 Dec 2014 16:22:16 +0100 Subject: [PATCH 64/69] Fix compilation error --- pom.xml | 13 ++++++++++--- .../oauth2/FIWAREHeaderAuthenticationFilter.java | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index c6742e0..b5984d0 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,13 @@ 3.0.10.Final + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + @@ -257,7 +264,7 @@ FiwareMarketplace - + maven-compiler-plugin @@ -266,12 +273,12 @@ 3.2 - + maven-dependency-plugin 2.9 - + org.jacoco jacoco-maven-plugin diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java index 6c03f42..532e394 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java @@ -96,11 +96,10 @@ public Authentication attemptAuthentication(HttpServletRequest request, auth = new ClientAuthenticationToken(credentials, client.getName(), profile, authorities); } catch (Exception ex) { + // This exception should be risen in order to return a 401 throw new BadCredentialsException("The provided token is invalid or the system was not able to check it"); - // Nothing to do... } - return auth; } @@ -163,6 +162,7 @@ public boolean matches(HttpServletRequest request) { * Actions to be carried out when the authentication is successful. In this case * no actions are required. * @author aitor + * */ private static class FIWAREHeaderAuthenticationSuccessHandler implements AuthenticationSuccessHandler { @@ -175,7 +175,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, } /** - * Set the session in the context when the Authorization token is valid + * Set the Session in the Security Context when the Authorization token is valid * @author aitor * */ From 7b7d015033700aa14e45059c2680fa1c8aa29490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 31 Dec 2014 16:29:59 +0100 Subject: [PATCH 65/69] Fix indentation --- .../FIWAREHeaderAuthenticationFilter.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java index 532e394..fb13516 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java @@ -34,7 +34,7 @@ * */ public class FIWAREHeaderAuthenticationFilter extends AbstractAuthenticationProcessingFilter{ - + private String headerName; private UserDetailsChecker userDetailsChecker = new AccountStatusUserDetailsChecker(); private AuthenticationUserDetailsService userDetailsService = @@ -49,16 +49,16 @@ protected FIWAREHeaderAuthenticationFilter() { protected FIWAREHeaderAuthenticationFilter(String baseUrl, String headerName) { // Super class constructor must be called. super(new FIWAREHeaderAuthenticationRequestMatcher(baseUrl, headerName)); - + // Store header name this.headerName = headerName; - + // Needed to continue with the process of the request setContinueChainBeforeSuccessfulAuthentication(true); - + // Set the authentication in the context setSessionAuthenticationStrategy(new FIWAREHeaderAuthenticationAuthenticationStrategy()); - + // This handler doesn't do anything but it's required to replace the default one setAuthenticationSuccessHandler(new FIWAREHeaderAuthenticationSuccessHandler()); } @@ -112,7 +112,7 @@ public void setClient(FIWAREClient client) { } // AUXILIAR CLASSES // - + /** * Request Matcher that specifies when the filter should be executed. In this case we * want the filter to be executed when the following two conditions are true: @@ -122,10 +122,10 @@ public void setClient(FIWAREClient client) { * */ private static class FIWAREHeaderAuthenticationRequestMatcher implements RequestMatcher { - + private String baseUrl; private String headerName; - + public FIWAREHeaderAuthenticationRequestMatcher(String baseUrl, String headerName) { this.baseUrl = baseUrl; this.headerName = headerName; @@ -133,31 +133,31 @@ public FIWAREHeaderAuthenticationRequestMatcher(String baseUrl, String headerNam @Override public boolean matches(HttpServletRequest request) { - + String authToken = request.getHeader(headerName); - + // Get path String url = request.getServletPath(); - String pathInfo = request.getPathInfo(); - String query = request.getQueryString(); + String pathInfo = request.getPathInfo(); + String query = request.getQueryString(); - if (pathInfo != null || query != null) { - StringBuilder sb = new StringBuilder(url); + if (pathInfo != null || query != null) { + StringBuilder sb = new StringBuilder(url); - if (pathInfo != null) { - sb.append(pathInfo); - } + if (pathInfo != null) { + sb.append(pathInfo); + } - if (query != null) { - sb.append('?').append(query); - } - url = sb.toString(); - } + if (query != null) { + sb.append('?').append(query); + } + url = sb.toString(); + } return url.startsWith(baseUrl) && authToken != null && StringUtils.hasText(authToken);} } - + /** * Actions to be carried out when the authentication is successful. In this case * no actions are required. @@ -169,25 +169,25 @@ private static class FIWAREHeaderAuthenticationSuccessHandler implements Authent @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) - throws IOException, ServletException { + throws IOException, ServletException { // Nothing to do... The chain will continue } } - + /** * Set the Session in the Security Context when the Authorization token is valid * @author aitor * */ private static class FIWAREHeaderAuthenticationAuthenticationStrategy implements SessionAuthenticationStrategy { - + @Override public void onAuthentication(Authentication authentication, HttpServletRequest request, HttpServletResponse response) - throws SessionAuthenticationException { + throws SessionAuthenticationException { // Set the authentication in the current context SecurityContextHolder.getContext().setAuthentication(authentication); } - + } } From 581e48cf02f7fce24e49e3ab81be3e5a8bdc4381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 7 Jan 2015 10:38:14 +0100 Subject: [PATCH 66/69] Add test for Request Matcher. Add copyright headers whhere missing --- .../FIWAREHeaderAuthenticationFilter.java | 42 +++++- ...eaderAuthenticationRequestMatcherTest.java | 122 ++++++++++++++++++ .../marketplace/oauth2/FIWAREProfileTest.java | 3 - 3 files changed, 159 insertions(+), 8 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationRequestMatcherTest.java diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java index fb13516..4ff2e4b 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java @@ -1,5 +1,37 @@ package org.fiware.apps.marketplace.oauth2; +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -121,7 +153,7 @@ public void setClient(FIWAREClient client) { * @author aitor * */ - private static class FIWAREHeaderAuthenticationRequestMatcher implements RequestMatcher { + static class FIWAREHeaderAuthenticationRequestMatcher implements RequestMatcher { private String baseUrl; private String headerName; @@ -154,8 +186,8 @@ public boolean matches(HttpServletRequest request) { url = sb.toString(); } - return url.startsWith(baseUrl) && authToken != null && StringUtils.hasText(authToken);} - + return url.startsWith(baseUrl) && authToken != null && StringUtils.hasText(authToken); + } } /** @@ -164,7 +196,7 @@ public boolean matches(HttpServletRequest request) { * @author aitor * */ - private static class FIWAREHeaderAuthenticationSuccessHandler implements AuthenticationSuccessHandler { + static class FIWAREHeaderAuthenticationSuccessHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, @@ -179,7 +211,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, * @author aitor * */ - private static class FIWAREHeaderAuthenticationAuthenticationStrategy implements SessionAuthenticationStrategy { + static class FIWAREHeaderAuthenticationAuthenticationStrategy implements SessionAuthenticationStrategy { @Override public void onAuthentication(Authentication authentication, diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationRequestMatcherTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationRequestMatcherTest.java new file mode 100644 index 0000000..9ccce10 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationRequestMatcherTest.java @@ -0,0 +1,122 @@ +package org.fiware.apps.marketplace.oauth2; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +import javax.servlet.http.HttpServletRequest; +import org.fiware.apps.marketplace.oauth2.FIWAREHeaderAuthenticationFilter.FIWAREHeaderAuthenticationRequestMatcher; +import org.junit.Test; + +public class FIWAREHeaderAuthenticationRequestMatcherTest { + + private static final String BASE_URL = "/system/"; + private static final String HEADER_NAME = "Auth-Tkt"; + + private FIWAREHeaderAuthenticationRequestMatcher matcher = + new FIWAREHeaderAuthenticationRequestMatcher(BASE_URL, HEADER_NAME); + + public void testMatcher(String servletPath, String pathInfo, String queryString, + String headerValue, boolean matches) { + + // Setup the servlet + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getServletPath()).thenReturn(servletPath); + when(request.getPathInfo()).thenReturn(pathInfo); + when(request.getQueryString()).thenReturn(queryString); + when(request.getHeader(HEADER_NAME)).thenReturn(headerValue); + + assertThat(matcher.matches(request)).isEqualTo(matches); + } + + @Test + public void testMatchesNoQueryNoPath() { + testMatcher(BASE_URL, null, null, "Header Val", true); + } + + @Test + public void testMatchesNoQuery() { + testMatcher(BASE_URL, "/store", null, "Header Val", true); + } + + @Test + public void testMatches() { + testMatcher(BASE_URL, "/store", "foo=boo", "Header Val", true); + } + + @Test + public void testNoMatchesNoQueryNoPathInvalidPath() { + testMatcher("/api/", null, null, "Header Val", false); + } + + @Test + public void testNoMatchesNoQueryInvalidPath() { + testMatcher("/api/", "/store", null, "Header Val", false); + } + + @Test + public void testNoMatchesInvalidPath() { + testMatcher("/api/", "/store", "foo=boo", "Header Val", false); + } + + @Test + public void testNoMatchesNoQueryNoPathInvalidPathNoHeader() { + testMatcher("/api/", null, null, null, false); + } + + @Test + public void testNoMatchesNoQueryInvalidPathNoHeader() { + testMatcher("/api/", "/store", null, null, false); + } + + @Test + public void testNoMatchesInvalidPathNoHeader() { + testMatcher("/api/", "/store", "foo=boo", null, false); + } + + @Test + public void testNoMatchesNoQueryNoPathNoHeader() { + testMatcher(BASE_URL, null, null, null, false); + } + + @Test + public void testNoMatchesNoQueryNoHeader() { + testMatcher(BASE_URL, "/store", null, null, false); + } + + @Test + public void testNoMatchesNoHeader() { + testMatcher(BASE_URL, "/store", "foo=boo", null, false); + } +} diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREProfileTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREProfileTest.java index 88a79de..88ab018 100644 --- a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREProfileTest.java +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREProfileTest.java @@ -58,7 +58,4 @@ public void testUserName() { assertThat(profile.getUsername()).isEqualTo(userName); verify(profile).getAttribute("nickName"); } - - - } From 5340c41c821a44f529d1d9051af12db12da1f1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 7 Jan 2015 15:04:19 +0100 Subject: [PATCH 67/69] Add tests for FIWAREHeaderAuthenticationStrategy --- .../FIWAREHeaderAuthenticationFilter.java | 4 +- ...eaderAuthenticationRequestMatcherTest.java | 2 +- ...IWAREHeaderAuthenticationStrategyTest.java | 60 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationStrategyTest.java diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java index 4ff2e4b..02d5f13 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java @@ -89,7 +89,7 @@ protected FIWAREHeaderAuthenticationFilter(String baseUrl, String headerName) { setContinueChainBeforeSuccessfulAuthentication(true); // Set the authentication in the context - setSessionAuthenticationStrategy(new FIWAREHeaderAuthenticationAuthenticationStrategy()); + setSessionAuthenticationStrategy(new FIWAREHeaderAuthenticationStrategy()); // This handler doesn't do anything but it's required to replace the default one setAuthenticationSuccessHandler(new FIWAREHeaderAuthenticationSuccessHandler()); @@ -211,7 +211,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, * @author aitor * */ - static class FIWAREHeaderAuthenticationAuthenticationStrategy implements SessionAuthenticationStrategy { + static class FIWAREHeaderAuthenticationStrategy implements SessionAuthenticationStrategy { @Override public void onAuthentication(Authentication authentication, diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationRequestMatcherTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationRequestMatcherTest.java index 9ccce10..15ee758 100644 --- a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationRequestMatcherTest.java +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationRequestMatcherTest.java @@ -4,7 +4,7 @@ * #%L * FiwareMarketplace * %% - * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * Copyright (C) 2015 CoNWeT Lab, Universidad Politécnica de Madrid * %% * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationStrategyTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationStrategyTest.java new file mode 100644 index 0000000..ad06005 --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationStrategyTest.java @@ -0,0 +1,60 @@ +package org.fiware.apps.marketplace.oauth2; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2015 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import static org.mockito.Mockito.*; + +import org.fiware.apps.marketplace.oauth2.FIWAREHeaderAuthenticationFilter.FIWAREHeaderAuthenticationStrategy; +import org.junit.Test; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; + +public class FIWAREHeaderAuthenticationStrategyTest { + + private FIWAREHeaderAuthenticationStrategy strategy = + new FIWAREHeaderAuthenticationStrategy(); + + @Test + public void testAuthenticationIsSet() { + SecurityContext context = mock(SecurityContext.class); + SecurityContextHolder.setContext(context); + Authentication auth = mock(Authentication.class); + + strategy.onAuthentication(auth, null, null); + + // Verify that the authentication has been set + verify(context).setAuthentication(auth); + } + +} From 8abc84ad386fbe19a124abf2bdce29973747476b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 7 Jan 2015 15:41:34 +0100 Subject: [PATCH 68/69] Ease the way the authorities are set --- .../FIWAREHeaderAuthenticationFilter.java | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java index 02d5f13..049b78e 100644 --- a/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java +++ b/src/main/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilter.java @@ -4,7 +4,7 @@ * #%L * FiwareMarketplace * %% - * Copyright (C) 2014 CoNWeT Lab, Universidad Politécnica de Madrid + * Copyright (C) 2014-2015 CoNWeT Lab, Universidad Politécnica de Madrid * %% * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -43,16 +43,12 @@ import org.pac4j.core.profile.UserProfile; import org.pac4j.oauth.credentials.OAuthCredentials; import org.pac4j.springframework.security.authentication.ClientAuthenticationToken; -import org.pac4j.springframework.security.authentication.CopyRolesUserDetailsService; -import org.springframework.security.authentication.AccountStatusUserDetailsChecker; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.AuthenticationUserDetailsService; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsChecker; import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.session.SessionAuthenticationException; @@ -68,10 +64,6 @@ public class FIWAREHeaderAuthenticationFilter extends AbstractAuthenticationProcessingFilter{ private String headerName; - private UserDetailsChecker userDetailsChecker = new AccountStatusUserDetailsChecker(); - private AuthenticationUserDetailsService userDetailsService = - new CopyRolesUserDetailsService(); - private FIWAREClient client; protected FIWAREHeaderAuthenticationFilter() { @@ -108,20 +100,11 @@ public Authentication attemptAuthentication(HttpServletRequest request, // In this case, the exception is caught and the correct exceptions is thrown... UserProfile profile = client.getUserProfile(authToken); - // by default, no authorities - Collection authorities = new ArrayList(); - - // get user details and check them - if (this.userDetailsService != null) { - final ClientAuthenticationToken tmpToken = new ClientAuthenticationToken(null, - client.getName(), profile, null); - final UserDetails userDetails = this.userDetailsService.loadUserDetails(tmpToken); - - if (userDetails != null) { - this.userDetailsChecker.check(userDetails); - authorities = userDetails.getAuthorities(); - } - } + // Define authorities + Collection authorities = new ArrayList(); + for (String role: profile.getRoles()) { + authorities.add(new SimpleGrantedAuthority(role)); + } // new token with credentials (like previously) and user profile and authorities OAuthCredentials credentials = new OAuthCredentials(null, authToken, "", client.getName()); From 5ba98e89ed95f7d5be1dfd566f91ff473c09464e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Wed, 7 Jan 2015 17:13:47 +0100 Subject: [PATCH 69/69] Add tests for FIWAREHeaderAuthenticationFilter --- .../FIWAREHeaderAuthenticationFilterTest.java | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilterTest.java diff --git a/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilterTest.java b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilterTest.java new file mode 100644 index 0000000..d75b9bb --- /dev/null +++ b/src/test/java/org/fiware/apps/marketplace/oauth2/FIWAREHeaderAuthenticationFilterTest.java @@ -0,0 +1,145 @@ +package org.fiware.apps.marketplace.oauth2; + +/* + * #%L + * FiwareMarketplace + * %% + * Copyright (C) 2015 CoNWeT Lab, Universidad Politécnica de Madrid + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; + +import org.junit.Test; +import org.pac4j.springframework.security.authentication.ClientAuthenticationToken; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; + + +public class FIWAREHeaderAuthenticationFilterTest { + + private static final String BASE_URL = "/system/"; + private static final String HEADER_NAME = "Auth-Tkt"; + private FIWAREHeaderAuthenticationFilter filter = + new FIWAREHeaderAuthenticationFilter(BASE_URL, HEADER_NAME); + + public void testAttemptAuthentication(List roles) { + String authToken = "authTokenSimulation"; + + // Profile + FIWAREProfile profile = new FIWAREProfile(); + profile.addAttribute("nickName", "exampleNickName"); + profile.addAttribute("displayName", "EXAMPLE DISPLAY NAME"); + profile.addAttribute("email", "example@example.com"); + + for (GrantedAuthority authority: roles) { + profile.addRole(authority.getAuthority()); + } + + // Set the client + FIWAREClient client = mock(FIWAREClient.class); + when(client.getUserProfile(authToken)).thenReturn(profile); + filter.setClient(client); + + // Set the HTTPRequest + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getHeader(HEADER_NAME)).thenReturn(authToken); + + // Call the method + try { + Authentication auth = filter.attemptAuthentication(request, null); + assertThat(auth).isInstanceOf(ClientAuthenticationToken.class); + assertThat(auth.getAuthorities()).isEqualTo(roles); + + ClientAuthenticationToken castedAuth = (ClientAuthenticationToken) auth; + assertThat(castedAuth.getUserProfile()).isEqualTo(profile); + } catch (Exception ex) { + fail("Exception " + ex + " not expected"); + } + } + + @Test + public void testAttemptAuthenticationNoRoles() throws AuthenticationException, IOException, ServletException { + testAttemptAuthentication(new ArrayList()); + } + + @Test + public void testAttemptAuthenticationOneRol() throws AuthenticationException, IOException, ServletException { + List authorities = new ArrayList(); + authorities.add(new SimpleGrantedAuthority("ROLE_USER")); + + testAttemptAuthentication(authorities); + } + + @Test + public void testAttemptAuthenticationSomeRoles() throws AuthenticationException, IOException, ServletException { + List authorities = new ArrayList(); + authorities.add(new SimpleGrantedAuthority("ROLE_USER")); + authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN")); + authorities.add(new SimpleGrantedAuthority("ROLE_MANAGER")); + + testAttemptAuthentication(authorities); + } + + @Test + public void testExceptionRisenOnAuthError() { + String authToken = "authTokenSimulation"; + + // FIWARE Client + FIWAREClient client = mock(FIWAREClient.class); + doThrow(new RuntimeException("Exception Message")).when(client).getUserProfile(authToken); + + // Set the HTTPRequest + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getHeader(HEADER_NAME)).thenReturn(authToken); + + // Call the method + try { + filter.attemptAuthentication(request, null); + failBecauseExceptionWasNotThrown(BadCredentialsException.class); + } catch (BadCredentialsException ex) { + // Nothing to do... This is what it was expected + } catch (Exception ex) { + fail("Exception " + ex + " not expected"); + } + + + + } + +}