Permalink
Browse files

Merge pull request #32 from ITUBIDB/development

Development
  • Loading branch information...
dgkncelik committed May 29, 2018
2 parents 57f93ce + eef6691 commit 57b071521ab0e67f3d9957a43fe945219d41cbd5
Showing with 1,295 additions and 52 deletions.
  1. +5 −0 pom.xml
  2. +7 −2 src/main/java/edu/itu/cavabunga/advice/ExceptionHandlerAdvice.java
  3. +3 −3 src/main/java/edu/itu/cavabunga/business/CalendarManagerServiceImpl.java
  4. +130 −0 src/main/java/edu/itu/cavabunga/controller/SeederController.java
  5. +76 −3 src/main/java/edu/itu/cavabunga/core/entity/Component.java
  6. +8 −1 src/main/java/edu/itu/cavabunga/core/entity/Parameter.java
  7. +11 −7 src/main/java/edu/itu/cavabunga/core/entity/Participant.java
  8. +145 −2 src/main/java/edu/itu/cavabunga/core/entity/Property.java
  9. +21 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Alarm.java
  10. +25 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Calendar.java
  11. +17 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Daylight.java
  12. +37 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Event.java
  13. +22 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Freebusy.java
  14. +30 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Journal.java
  15. +16 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Standard.java
  16. +21 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Timezone.java
  17. +39 −2 src/main/java/edu/itu/cavabunga/core/entity/component/Todo.java
  18. +9 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Altrep.java
  19. +6 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Cn.java
  20. +13 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Cutype.java
  21. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/DelegatedFrom.java
  22. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/DelegatedTo.java
  23. +9 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Dir.java
  24. +15 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Encoding.java
  25. +11 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Fbtype.java
  26. +9 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Fmttype.java
  27. +11 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Language.java
  28. +9 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Member.java
  29. +39 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Partstat.java
  30. +11 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Range.java
  31. +9 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Related.java
  32. +11 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Reltype.java
  33. +12 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Role.java
  34. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Rsvp.java
  35. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/SentBy.java
  36. +18 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Tzid.java
  37. +21 −0 src/main/java/edu/itu/cavabunga/core/entity/parameter/Value.java
  38. +19 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Acknowledged.java
  39. +14 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Action.java
  40. +12 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Attach.java
  41. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Attendee.java
  42. +15 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Calscale.java
  43. +8 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Catagories.java
  44. +14 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Class.java
  45. +7 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Comment.java
  46. +9 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Completed.java
  47. +8 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Contact.java
  48. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Country.java
  49. +7 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Created.java
  50. +12 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Description.java
  51. +11 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Dtend.java
  52. +7 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Dtstamp.java
  53. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Dtstart.java
  54. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Due.java
  55. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Duration.java
  56. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Exdate.java
  57. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Freebusy.java
  58. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Geo.java
  59. +6 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Lastmod.java
  60. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Location.java
  61. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Method.java
  62. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Organizer.java
  63. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Percent.java
  64. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Priority.java
  65. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Prodid.java
  66. +29 −0 src/main/java/edu/itu/cavabunga/core/entity/property/PropertyValueType.java
  67. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Rdate.java
  68. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Recurid.java
  69. +2 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Related.java
  70. +6 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Repeat.java
  71. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Resources.java
  72. +6 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Rrule.java
  73. +6 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Seq.java
  74. +18 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Status.java
  75. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Summary.java
  76. +11 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Transp.java
  77. +10 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Trigger.java
  78. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Tzid.java
  79. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Tzname.java
  80. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Tzoffsetfrom.java
  81. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Tzoffsetto.java
  82. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Tzurl.java
  83. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Uid.java
  84. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Url.java
  85. +11 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Version.java
  86. +1 −1 src/main/java/edu/itu/cavabunga/core/service/IcalService.java
  87. +7 −7 src/main/java/edu/itu/cavabunga/core/service/IcalServiceImpl.java
  88. +3 −1 src/main/java/edu/itu/cavabunga/core/service/ParticipantServiceImpl.java
  89. +0 −4 src/main/java/edu/itu/cavabunga/exception/Conflict.java
  90. +0 −3 src/main/java/edu/itu/cavabunga/exception/NotFound.java
  91. +10 −0 src/main/java/edu/itu/cavabunga/exception/Validation.java
View
@@ -78,6 +78,11 @@
<version>2.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
</dependencies>
<build>
@@ -20,6 +20,7 @@
@ExceptionHandler(NotFound.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ErrorResponse handleNotFound(NotFound e){
System.out.printf(e.getMessage());
return new ErrorResponse(1,e.getMessage(), null);
}
@@ -32,6 +33,7 @@ public ErrorResponse handleNotFound(NotFound e){
@ExceptionHandler(Conflict.class)
@ResponseStatus(HttpStatus.CONFLICT)
public ErrorResponse handleConflict(Conflict e){
System.out.printf(e.getMessage());
return new ErrorResponse(1,e.getMessage(),null);
}
@@ -44,6 +46,7 @@ public ErrorResponse handleConflict(Conflict e){
@ExceptionHandler(IllegalStateException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse handleIllegalState(IllegalStateException e){
System.out.printf(e.getMessage());
return new ErrorResponse(1,e.getMessage(),null);
}
@@ -56,6 +59,7 @@ public ErrorResponse handleIllegalState(IllegalStateException e){
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse handleIllegalArgument(IllegalArgumentException e){
System.out.printf(e.getMessage());
return new ErrorResponse(1,e.getMessage(),null);
}
@@ -65,11 +69,12 @@ public ErrorResponse handleIllegalArgument(IllegalArgumentException e){
* @param e caught exception
* @return ErrorResponse with exception message with related HTTP status
*/
@ExceptionHandler(Exception.class)
/* @ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ErrorResponse handleException(Exception e){
System.out.printf(e.getMessage());
return new ErrorResponse(1,e.getMessage(), null);
}
}*/
}
@@ -110,7 +110,7 @@ public void addComponent(Component component, String owner, Long parentComponent
Assert.state(
component.getId() == null,
"New component cannot have id field, please use update methods"
"44New component cannot have id field, please use update methods"
);
if(!participantService.getParticipantByUserName(owner).isPresent()) {
@@ -192,7 +192,7 @@ public void addProperty(Property property, Long parentComponentId){
Assert.notNull(parentComponentId, "ParentComponentId must not be null!");
Assert.state(
property.getId() == null,
"New Property cannot have id field, please use update methods"
"55New Property cannot have id field, please use update methods"
);
if(!icalService.getComponentById(parentComponentId).isPresent()) {
@@ -269,7 +269,7 @@ public void addParameter(Parameter parameter, Long parentPropertyId){
Assert.notNull(parentPropertyId, "ParentPropertyId must not be null!");
Assert.state(
parameter.getId() == null,
"New parameter cannot have id field, please use update methods"
"77New parameter cannot have id field, please use update methods"
);
if(!icalService.getPropertyById(parentPropertyId).isPresent()) {
@@ -0,0 +1,130 @@
package edu.itu.cavabunga.controller;
import edu.itu.cavabunga.business.CalendarManagerService;
import edu.itu.cavabunga.core.entity.Component;
import edu.itu.cavabunga.core.entity.Parameter;
import edu.itu.cavabunga.core.entity.Participant;
import edu.itu.cavabunga.core.entity.Property;
import edu.itu.cavabunga.core.entity.component.ComponentType;
import edu.itu.cavabunga.core.entity.parameter.ParameterType;
import edu.itu.cavabunga.core.entity.participant.ParticipantType;
import edu.itu.cavabunga.core.entity.property.PropertyType;
import edu.itu.cavabunga.core.entity.property.PropertyValueType;
import edu.itu.cavabunga.core.service.IcalService;
import edu.itu.cavabunga.core.service.ParticipantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.awt.geom.AreaOp;
@RestController
@RequestMapping(path="/seeddb")
public class SeederController {
@Autowired
private CalendarManagerService calendarManagerService;
@Autowired
private ParticipantService participantService;
@Autowired
private IcalService icalService;
@GetMapping
@Transactional
public String seedDataBase(){
participantService.saveParticipant(participantService.createParticipant("testuser", ParticipantType.User));
participantService.saveParticipant(participantService.createParticipant("testgroup", ParticipantType.Group));
Component calendar = icalService.createComponent(ComponentType.Calendar);
Property prodid = icalService.createProperty(PropertyType.Prodid);
prodid.setValue("-//Test Inc//Cavabunga Calendar//");
Property version = icalService.createProperty(PropertyType.Version);
version.setValue("2.0");
Property calscale = icalService.createProperty(PropertyType.Calscale);
calscale.setValue("GREGORIAN");
Property method = icalService.createProperty(PropertyType.Method);
method.setValue("PUBLISH");
calendar.addProperty(prodid);
calendar.addProperty(version);
calendar.addProperty(calscale);
calendar.addProperty(method);
calendar.setOwner(calendarManagerService.getParticipantByUserName("testuser"));
Component timezone = icalService.createComponent(ComponentType.Timezone);
Property tzid = icalService.createProperty(PropertyType.Tzid);
tzid.setValue("Europe/Istanbul");
timezone.addProperty(tzid);
Component standard = icalService.createComponent(ComponentType.Standard);
Property tzoffsetfrom = icalService.createProperty(PropertyType.Tzoffsetfrom);
tzoffsetfrom.setValue("+0300");
Property tzoffsetto = icalService.createProperty(PropertyType.Tzoffsetto);
tzoffsetto.setValue("+0300");
Property tzname = icalService.createProperty(PropertyType.Tzname);
tzname.setValue("+03");
standard.addProperty(tzoffsetfrom);
standard.addProperty(tzoffsetto);
standard.addProperty(tzname);
timezone.addComponent(standard);
calendar.addComponent(timezone);
Component event = icalService.createComponent(ComponentType.Event);
Property dtstart = icalService.createProperty(PropertyType.Dtstart);
dtstart.setValue("20160423T170000Z");
Property dtend = icalService.createProperty(PropertyType.Dtend);
dtend.setValue("20160423T180000Z");
Property dtstamp = icalService.createProperty(PropertyType.Dtstamp);
dtstamp.setValue("20180520T181535Z");
Property organizer = icalService.createProperty(PropertyType.Organizer);
organizer.setValue("mailto:unknownorganizer@calendar.cavabunga.com");
Parameter cn = icalService.createParameter(ParameterType.Cn);
cn.setValue("unknownorganizer@calendar.google.com");
organizer.addParameter(cn);
Property uid = icalService.createProperty(PropertyType.Uid);
uid.setValue("7kukuqrfedlm2f9t0vr42q2qc8cm9l3o7vn9g00q3j3s5mhdo2ovuahsd9hf54qk3j60");
Property attendee = icalService.createProperty(PropertyType.Attendee);
attendee.setValue("mailto:dgkncelik@gmail.com");
Parameter cutype = icalService.createParameter(ParameterType.Cutype);
cutype.setValue("INDIVIDUAL");
Parameter role = icalService.createParameter(ParameterType.Role);
role.setValue("REQ-PARTICIPANT");
Parameter partstat = icalService.createParameter(ParameterType.Partstat);
partstat.setValue("ACCEPTED");
attendee.addParameter(cutype);
attendee.addParameter(role);
attendee.addParameter(partstat);
Property classs = icalService.createProperty(PropertyType.Class);
classs.setValue("PRIVATE");
Property created = icalService.createProperty(PropertyType.Created);
created.setValue("20160111T065955Z");
Property description = icalService.createProperty(PropertyType.Description);
description.setValue("---description_here---");
Property lastmod = icalService.createProperty(PropertyType.Lastmod);
lastmod.setValue("20160112T053844Z");
Property seq = icalService.createProperty(PropertyType.Seq);
seq.setValue("0");
event.addProperty(dtstart);
event.addProperty(dtend);
event.addProperty(dtstamp);
event.addProperty(organizer);
event.addProperty(uid);
event.addProperty(attendee);
event.addProperty(classs);
event.addProperty(created);
event.addProperty(description);
event.addProperty(lastmod);
event.addProperty(seq);
calendar.addComponent(event);
icalService.saveComponent(calendar);
return "ok";
}
}
@@ -2,7 +2,10 @@
import com.fasterxml.jackson.annotation.*;
import edu.itu.cavabunga.core.entity.component.*;
import edu.itu.cavabunga.core.entity.property.PropertyType;
import edu.itu.cavabunga.exception.Validation;
import lombok.Data;
import org.apache.commons.lang.Validate;
import org.hibernate.annotations.DiscriminatorOptions;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@@ -15,7 +18,6 @@
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@EntityListeners(AuditingEntityListener.class)
@DiscriminatorOptions(force=true)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
@@ -69,7 +71,78 @@ public void addProperty(Property property){
properties.add(property);
}
public boolean validate(){
return true;
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());
}
}
}
}
@@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import edu.itu.cavabunga.core.entity.parameter.*;
import edu.itu.cavabunga.exception.Validation;
import lombok.Data;
import org.hibernate.annotations.DiscriminatorOptions;
@@ -48,8 +49,14 @@
private String value;
@ManyToOne(cascade = CascadeType.ALL)
@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");
}
}
}
@@ -1,9 +1,7 @@
package edu.itu.cavabunga.core.entity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.*;
import edu.itu.cavabunga.core.entity.participant.Group;
import edu.itu.cavabunga.core.entity.participant.User;
import lombok.Data;
@@ -21,7 +19,7 @@
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@EntityListeners(AuditingEntityListener.class)
@DiscriminatorOptions(force=true)
@JsonIgnoreProperties(ignoreUnknown = 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"),
@@ -40,11 +38,17 @@
@CreatedDate
private Date creationDate;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "owner")
@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.

0 comments on commit 57b0715

Please sign in to comment.