Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving core objects from cavabunga-core to cavabunga-lib.
Unnecessary class clean-up Code analysis checked, corrections made.
- Loading branch information
Showing
108 changed files
with
3,060 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>edu.itu</groupId> | ||
<artifactId>cavabunga-lib</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>cavabunga-lib</name> | ||
<description>Cavabunga calendaring application core object library</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.8.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-rest</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>0.7.9</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.tngtech.java/junit-dataprovider --> | ||
<dependency> | ||
<groupId>com.tngtech.junit.dataprovider</groupId> | ||
<artifactId>junit4-dataprovider</artifactId> | ||
<version>2.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.16.20</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.7</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<!-- JaCoCo configuration --> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>report</id> | ||
<phase>test</phase> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
146 changes: 146 additions & 0 deletions
146
src/main/java/edu/itu/cavabunga/lib/entity/Component.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package edu.itu.cavabunga.lib.entity; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import edu.itu.cavabunga.lib.entity.component.*; | ||
import edu.itu.cavabunga.lib.entity.property.PropertyType; | ||
import edu.itu.cavabunga.lib.exception.Validation; | ||
import lombok.Data; | ||
import org.hibernate.annotations.DiscriminatorOptions; | ||
import org.springframework.data.annotation.CreatedDate; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) | ||
@DiscriminatorOptions(force=true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = Alarm.class, name = "Alarm"), | ||
@JsonSubTypes.Type(value = Calendar.class, name = "Calendar"), | ||
@JsonSubTypes.Type(value = Daylight.class, name = "Daylight"), | ||
@JsonSubTypes.Type(value = Event.class, name = "Event"), | ||
@JsonSubTypes.Type(value = Freebusy.class, name = "Freebusy"), | ||
@JsonSubTypes.Type(value = Journal.class, name = "Journal"), | ||
@JsonSubTypes.Type(value = Standard.class, name = "Standard"), | ||
@JsonSubTypes.Type(value = Timezone.class, name = "Timezone"), | ||
@JsonSubTypes.Type(value = Todo.class, name = "Todo") | ||
}) | ||
|
||
@Data | ||
public abstract class Component { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
@ManyToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name="owner_uuid") | ||
@JsonBackReference(value = "participantAndComponent") | ||
private Participant owner; | ||
|
||
@ManyToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name="parent_id") | ||
@JsonBackReference | ||
private Component parent; | ||
|
||
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL) | ||
@JsonManagedReference | ||
private List<Component> components = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "component", cascade = CascadeType.ALL) | ||
@JsonManagedReference | ||
private List<Property> properties = new ArrayList<>(); | ||
|
||
@CreatedDate | ||
private Date creationDate; | ||
|
||
public void addComponent(Component component){ | ||
component.setParent(this); | ||
component.setOwner(this.owner); | ||
components.add(component); | ||
} | ||
|
||
public void addProperty(Property property){ | ||
property.setComponent(this); | ||
properties.add(property); | ||
} | ||
|
||
public void validate(){ | ||
if(!components.isEmpty()){ | ||
for (Component c : components){ | ||
try { | ||
c.validate(); | ||
}catch (Exception e){ | ||
throw new Validation(this.getClass().getName() + " component's sub component validation failed: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
if(!properties.isEmpty()){ | ||
for(Property p : properties){ | ||
try { | ||
p.validate(); | ||
}catch (Exception e){ | ||
throw new Validation(this.getClass().getName() + " component property validateion failed " + e.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void validateOptionalOneProperties(List<PropertyType> propertyTypeList){ | ||
Integer propertyCount = 0; | ||
for(PropertyType pt : propertyTypeList){ | ||
for(Property p : properties){ | ||
if(p.getClass().getName().equals(pt.create().getClass().getName())){ | ||
propertyCount++; | ||
} | ||
|
||
if(propertyCount >= 2){ | ||
throw new Validation("Component validation failed in optional-one properties check: " + p.getClass().getName()); | ||
} | ||
} | ||
propertyCount = 0; | ||
} | ||
} | ||
|
||
public void validateOptionalManyProperties(){ | ||
// | ||
} | ||
|
||
public void validateRequiredOneProperties(List<PropertyType> propertyTypeList){ | ||
Integer propertyCount = 0; | ||
for(PropertyType pt : propertyTypeList){ | ||
for(Property p : properties){ | ||
if(p.getClass().getName().equals(pt.create().getClass().getName())){ | ||
propertyCount++; | ||
} | ||
} | ||
|
||
if(propertyCount != 1){ | ||
throw new Validation("Component validation failed in required-one properties check. Count " + propertyCount + ": " + pt.create().getClass().getName()); | ||
} | ||
|
||
propertyCount = 0; | ||
} | ||
} | ||
|
||
public void validateReqiredManyProperties(List<PropertyType> propertyTypeList){ | ||
Integer propertyCount = 0; | ||
for(PropertyType pt : propertyTypeList){ | ||
for(Property p : properties){ | ||
if(p.getClass().getName().equals(pt.create().getClass().getName())){ | ||
propertyCount++; | ||
} | ||
} | ||
|
||
if(propertyCount == 0){ | ||
throw new Validation("Component validation failed in required-many properties check: " + pt.create().getClass().getName()); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package edu.itu.cavabunga.lib.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonBackReference; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import edu.itu.cavabunga.lib.entity.parameter.*; | ||
import edu.itu.cavabunga.lib.exception.Validation; | ||
import lombok.Data; | ||
import org.hibernate.annotations.DiscriminatorOptions; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) | ||
@DiscriminatorOptions(force=true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = Altrep.class, name = "Altrep"), | ||
@JsonSubTypes.Type(value = Cn.class, name = "Cn"), | ||
@JsonSubTypes.Type(value = Cutype.class, name = "Cutype"), | ||
@JsonSubTypes.Type(value = DelegatedFrom.class, name = "DelegatedFrom"), | ||
@JsonSubTypes.Type(value = DelegatedTo.class, name = "DelegatedTo"), | ||
@JsonSubTypes.Type(value = Dir.class, name = "Dir"), | ||
@JsonSubTypes.Type(value = Encoding.class, name = "Encoding"), | ||
@JsonSubTypes.Type(value = Fbtype.class, name = "Fbtype"), | ||
@JsonSubTypes.Type(value = Fmttype.class, name = "Fmttype"), | ||
@JsonSubTypes.Type(value = Language.class, name = "Language"), | ||
@JsonSubTypes.Type(value = Member.class, name = "Member"), | ||
@JsonSubTypes.Type(value = Partstat.class, name = "Partstat"), | ||
@JsonSubTypes.Type(value = Range.class, name = "Range"), | ||
@JsonSubTypes.Type(value = Related.class, name = "Related"), | ||
@JsonSubTypes.Type(value = Reltype.class, name = "Reltype"), | ||
@JsonSubTypes.Type(value = Role.class, name = "Role"), | ||
@JsonSubTypes.Type(value = Rsvp.class, name = "Rsvp"), | ||
@JsonSubTypes.Type(value = SentBy.class, name = "SentBy"), | ||
@JsonSubTypes.Type(value = Tzid.class, name = "Tzid"), | ||
@JsonSubTypes.Type(value = Value.class, name = "Value") | ||
}) | ||
@Data | ||
public abstract class Parameter { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
private String name; | ||
|
||
private String value; | ||
|
||
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
@JoinColumn(name = "property_id") | ||
@JsonBackReference | ||
private Property property; | ||
|
||
public void validate(){ | ||
if((this.value == null) || (this.value.trim().isEmpty())){ | ||
throw new Validation(this.getClass().getName() + " parameter cannot be empty"); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/edu/itu/cavabunga/lib/entity/Participant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
package edu.itu.cavabunga.lib.entity; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import edu.itu.cavabunga.lib.entity.participant.Group; | ||
import edu.itu.cavabunga.lib.entity.participant.Resource; | ||
import edu.itu.cavabunga.lib.entity.participant.User; | ||
import lombok.Data; | ||
import org.hibernate.annotations.DiscriminatorOptions; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) | ||
@EntityListeners(AuditingEntityListener.class) | ||
@DiscriminatorOptions(force=true) | ||
@JsonIgnoreProperties(ignoreUnknown = true, value= {"components"}) //TODO: participants with no component will give error while building JSON | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = User.class, name = "User"), | ||
@JsonSubTypes.Type(value = Group.class, name = "Group"), | ||
@JsonSubTypes.Type(value = Resource.class, name = "Resource"), | ||
}) | ||
@Data | ||
public abstract class Participant { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
@Column(name = "user_name") | ||
private String userName; | ||
|
||
@Column(name = "creation_date") | ||
@CreatedDate | ||
private Date creationDate; | ||
|
||
|
||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "owner") | ||
@JsonManagedReference(value = "participantAndComponent") | ||
@JsonIgnore | ||
private List<Component> components = new ArrayList<>(); | ||
|
||
public Participant(){ | ||
|
||
} | ||
|
||
public void validate(){ | ||
|
||
} | ||
} |
Oops, something went wrong.