Commit 99c60199 authored by Mahdi Sellami's avatar Mahdi Sellami
Browse files

initial commit uhh-db

parent 1140175b
Pipeline #13187 failed with stages
in 1 minute and 9 seconds
# ideadbservice
# uhhdbservice
How to start the ideadbservice application
How to start the uhhdbservice application
---
1. Run `mvn clean install` to build your application
2. Set MySql database URL in `config.yml`
3. Migrate database data with `java -jar target/ideadb-1.0-SNAPSHOT.jar db migrate config.yml`
4. Start application with `java -jar target/ideadb-1.0-SNAPSHOT.jar server config.yml`
3. Migrate database data with `java -jar target/uhhdb-1.0-SNAPSHOT.jar db migrate config.yml`
4. Start application with `java -jar target/uhhdb-1.0-SNAPSHOT.jar server config.yml`
5. To check that your application is running enter url `http://localhost:9004`
6. To see the API documentation (Swagger) enter url `http://localhost:9004/swagger`
......
......@@ -18,7 +18,7 @@ database:
# the password
password: root
# the JDBC URL; the database is called tmms
url: jdbc:mysql://localhost:3306/wrapper
url: jdbc:mysql://localhost:3306/uhhdb
swagger:
resourcePackage: org.tmms.ideadb
\ No newline at end of file
resourcePackage: org.tmms.uhhdb
\ No newline at end of file
......@@ -7,18 +7,18 @@
<maven>3.0.0</maven>
</prerequisites>
<groupId>org.tmms.ideadb</groupId>
<artifactId>ideadb</artifactId>
<groupId>org.tmms.uhhdb</groupId>
<artifactId>uhhdb</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ideadbservice</name>
<name>uhhdbservice</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>1.3.0</dropwizard.version>
<mainClass>org.tmms.ideadb.IdeadbserviceApplication</mainClass>
<mainClass>org.tmms.uhhdb.UhhdbserviceApplication</mainClass>
</properties>
<dependencyManagement>
......
/**
* This (dummy) class is used to serve a fixed list of keywords.
*
* @see SuggestionResource
*/
package org.tmms.ideadb.api;
import java.util.ArrayList;
import java.util.List;
public class KeyWords {
/**
* The list of keywords.
*/
private List<String> keywords;
/**
* A no-argument constructor.
*/
public KeyWords() {
}
/**
* Constructor.
*
* @param keywords
* list of keywords.
*/
public KeyWords(List<String> keywords) {
this.keywords = keywords;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((keywords == null) ? 0 : keywords.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
KeyWords other = (KeyWords) obj;
if (keywords == null) {
if (other.keywords != null)
return false;
} else if (!keywords.equals(other.keywords))
return false;
return true;
}
public List<String> getKeywords() {
return keywords;
}
public void setKeywords(List<String> keywords) {
this.keywords = keywords;
}
public void addKeyword(String keyword) {
if (keywords != null)
keywords = new ArrayList<String>();
keywords.add(keyword);
}
}
/**
* This (dummy) class is used to serve a fixed list of sub-categories.
*
* @see SuggestionResource
*/
package org.tmms.ideadb.api;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class SubCategories {
/**
* The list of sub-categories.
*/
private List<String> subCategories;
/**
* A no-argument constructor.
*/
public SubCategories() {
}
/**
* Constructor.
*
* @param subCategories
* list of sub-categories
*/
public SubCategories(List<String> subCategories) {
this.subCategories = subCategories;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((subCategories == null) ? 0 : subCategories.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SubCategories other = (SubCategories) obj;
if (subCategories == null) {
if (other.subCategories != null)
return false;
} else if (!subCategories.equals(other.subCategories))
return false;
return true;
}
@JsonProperty
public List<String> getSubCategories() {
return subCategories;
}
public void setSubCategories(List<String> categories) {
this.subCategories = categories;
}
public void addsubCategory(String subCategory) {
if (subCategories == null)
subCategories = new ArrayList<String>();
subCategories.add(subCategory);
}
}
/**
* This Entity class represents a single Sub-Category. It stores the internal ID,
* the name and the category of a Sub-Category.
*
* @author Mahdi Sellami
*/
package org.tmms.ideadb.api;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import io.swagger.annotations.ApiModel;
@ApiModel(description = "Subcategory Model")
@Entity
@Table(name = "sub_categories")
@NamedQueries({ @NamedQuery(name = "org.tmms.ideadb.api.Subcategory.findAll", query = "select s from Subcategory s"),
@NamedQuery(name = "org.tmms.ideadb.api.Subcategory.findByName", query = "select s from Subcategory s "
+ "where s.name like :name ") })
public class Subcategory {
/**
* Entity's unique identifier.
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "SUB_CAT_ID", unique = true, nullable = false)
private long subCatId;
/**
* The name of the sub-category.
*/
@Column(name = "NAME", unique = true, nullable = false)
private String name;
/**
* The category to which the su-category belongs.
*/
@OneToOne
@JoinColumn(name = "CATEGORY_ID")
private Category category;
/**
* The Keywords belonging to the sub-category
*/
@ManyToMany(cascade = { CascadeType.ALL })
@JoinTable(
name = "sub_category_keyword",
joinColumns = { @JoinColumn(name = "sub_cat_id") },
inverseJoinColumns = { @JoinColumn(name = "keyword_id") }
)
Set<KeyWord> keyWords = new HashSet<>();
/**
* A no-argument constructor.
*/
public Subcategory() {
}
/**
* A constructor to create a sub-category. Id is not passed, because it's
* auto-generated by RDBMS.
*
* @param name
* the name of the subcategory
*/
public Subcategory(String name) {
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((category == null) ? 0 : category.hashCode());
result = prime * result + ((keyWords == null) ? 0 : keyWords.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + (int) (subCatId ^ (subCatId >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Subcategory other = (Subcategory) obj;
if (category == null) {
if (other.category != null)
return false;
} else if (!category.equals(other.category))
return false;
if (keyWords == null) {
if (other.keyWords != null)
return false;
} else if (!keyWords.equals(other.keyWords))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (subCatId != other.subCatId)
return false;
return true;
}
public long getSubCatId() {
return subCatId;
}
public void setSubCatId(long subCatId) {
this.subCatId = subCatId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public Set<KeyWord> getKeyWords() {
return keyWords;
}
public void setKeyWords(Set<KeyWord> keyWords) {
this.keyWords = keyWords;
}
}
/**
* This (dummy) class is used to serve tag matches of an idea.
*
* @See IdeaResource
*/
package org.tmms.ideadb.api;
import java.util.List;
public class TagMatch {
/**
* The Tag found in the idea
*/
private String tag;
/**
* The matching words in the idea corresponding to the tag
*/
private List<String> match;
/**
* A no-argument constructor.
*/
public TagMatch(){
}
/**
* Constructor.
*
* @param tag
* the tag found in the idea
* @param match
* the matching words in the idea corresponding to the tag
*/
public TagMatch(String tag, List<String> match){
this.tag = tag;
this.match = match;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((match == null) ? 0 : match.hashCode());
result = prime * result + ((tag == null) ? 0 : tag.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TagMatch other = (TagMatch) obj;
if (match == null) {
if (other.match != null)
return false;
} else if (!match.equals(other.match))
return false;
if (tag == null) {
if (other.tag != null)
return false;
} else if (!tag.equals(other.tag))
return false;
return true;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public List<String> getMatch() {
return match;
}
public void setMatch(List<String> match) {
this.match = match;
}
}
/**
* This class is a Data access object for data Persistence using Hibernate. It's
* used to persist the Category entity.
*
* @see Category
*
* @author Mahdi Sellami
*/
package org.tmms.ideadb.db;
import java.util.List;
import org.hibernate.SessionFactory;
import org.tmms.ideadb.api.Category;
import io.dropwizard.hibernate.AbstractDAO;
public class CategoryDAO extends AbstractDAO<Category> {
/**
* Constructor.
*
* @param sessionFactory
* Hibernate session factory.
*/
public CategoryDAO(SessionFactory sessionFactory) {
super(sessionFactory);
}
/**
* This method returns all Categories stored in the database.
*
* @return list of all Categories stored in the database
*/
@SuppressWarnings("unchecked")
public List<Category> findAll() {
return list(namedQuery("org.tmms.ideadb.api.Category.findAll"));
}
/**
* This method looks for a Category by its id.
*
* @param id
* the id of the desired Category.
* @return the Category with the given id
*/
public Category findById(long id) {
return get(id);
}
}
/**
* This class is a Data access object for data Persistence using Hibernate. It's
* used to persist the Subcategory entity.
*
* @see Subcategory
*
* @author Mahdi Sellami
*/
package org.tmms.ideadb.db;
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.tmms.ideadb.api.Subcategory;
import io.dropwizard.hibernate.AbstractDAO;
public class SubcategoryDAO extends AbstractDAO<Subcategory> {
/**
* Constructor.
*
* @param sessionFactory
* Hibernate session factory.
*/
public SubcategoryDAO(SessionFactory sessionFactory) {
super(sessionFactory);
}
/**
* This method returns all the sub-categories stored in the database.
*
* @return list of all the sub-categories stored in the database
*/
@SuppressWarnings("unchecked")
public List<Subcategory> findAll() {
return list(namedQuery("org.tmms.ideadb.api.Subcategory.findAll"));
}
/**
* This method looks for a sub-category by its id.
*
* @param id
* the id of the desired sub-category.
* @return the sub-category with the given id
*/
public Subcategory findById(long id) {
return get(id);
}
/**
* This method looks for a sub-category by its name.
*
* @param name
* the name of the desired sub-category.
* @return the sub-category with the given id
*/
@SuppressWarnings("unchecked")
public List<Subcategory> findByName(String name) {
return list(namedQuery("org.tmms.ideadb.api.Subcategory.findByName").setParameter("name", name));
}
/**
* This method looks for a the sub-categories by the name of their category.
*
* @param cat
* the name of a category, to which the desired sub-categories belong to.
* @return list of all sub-categories belonging to the category with the given name
*/
@SuppressWarnings({ "unchecked", "deprecation" })
public List<Subcategory> findByCategoryName(String cat) {
return currentSession().createCriteria(Subcategory.class).createAlias("category", "c")
.add(Restrictions.eq("c.name", cat)).list();
}
/**
* This method looks for a the sub-categories by the ID of their category.
*
* @param id
* the ID of a category, to which the desired sub-categories belong to.
* @return list of all sub-categories belonging to the category with the given ID
*/
@SuppressWarnings({ "unchecked", "deprecation" })
public List<Subcategory> findByCategoryId(long id) {
return currentSession().createCriteria(Subcategory.class).createAlias("category", "c")
.add(Restrictions.eq("c.catId", id)).list();
}
}