Skip to content

Commit

Permalink
some refactoring to retreivable resources
Browse files Browse the repository at this point in the history
  • Loading branch information
manos committed Jun 21, 2017
1 parent 395e21d commit 1a198ba
Show file tree
Hide file tree
Showing 46 changed files with 400 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface IBaseContext<O extends UserModel, M extends IMembership, MR ext

String getName();

String getDescription();
String getDetail();

String getAvatarUrl();

Expand All @@ -54,7 +54,7 @@ public interface IBaseContext<O extends UserModel, M extends IMembership, MR ext

void setTitle(String title);

void setDescription(String description);
void setDetail(String detail);

void setAvatarUrl(String avatarUrl);

Expand Down
1 change: 1 addition & 0 deletions restdude-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
</plugin-->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@MetaValue(value = "1", targetEntity = Space.class),
@MetaValue(value = "2", targetEntity = SpaceApp.class),
@MetaValue(value = "3", targetEntity = BaseCase.class),
@MetaValue(value = "4", targetEntity = AbstractCaseComment.class),
@MetaValue(value = "4", targetEntity = BaseCaseComment.class),
@MetaValue(value = "5", targetEntity = Membership.class),
@MetaValue(value = "6", targetEntity = MembershipRequest.class)
}
Expand Down
8 changes: 6 additions & 2 deletions restdude-boot/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ spring:
# type: com.zaxxer.hikari.HikariDataSource
jpa:
generate-ddl: true
database-platform: ${buildfilters.hibernate.dialect}
properties:
javax.persistence.validation.mode: none
hibernate.temp.use_jdbc_metadata_defaults: false
# open-in-view: false
# show-sql: true
# database: H2
Expand Down Expand Up @@ -73,8 +75,10 @@ logging:
org.springframework.security: WARN
springfox.documentation.schema.property.CachingModelPropertiesProvider: ERROR
com.restdude:
init: debug
mdd.service.AbstractPersistableModelServiceImpl: debug
init: WARN
mdd.service.AbstractPersistableModelServiceImpl: WARN
mdd.repository: WARN
domain.error: WARN

# test: debug
# mdd: WARN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
*/
package com.restdude.domain.cases.listener;

import java.util.Objects;
import java.util.Set;

import com.restdude.domain.cases.model.BaseCase;
import com.restdude.domain.cases.model.AbstractCaseComment;
import com.restdude.domain.cases.model.BaseCaseComment;
import com.restdude.domain.cases.model.ActivityLog;
import com.restdude.domain.cases.model.BaseContext;
import com.restdude.domain.cases.model.Membership;
import com.restdude.domain.cases.model.Space;
import com.restdude.domain.cases.model.SpaceCasesApp;
import com.restdude.domain.cases.model.dto.BaseContextInfo;
import com.restdude.domain.cases.model.dto.CaseCommenttInfo;
import com.restdude.domain.cases.model.dto.CaseInfo;
Expand Down Expand Up @@ -161,7 +161,7 @@ public void onCaseCreated(EntityCreatedEvent<BaseCase> event) {

BaseCase model = event.getModel();
User user = model.getCreatedBy();
BaseContext context = model.getApplication();
BaseContext context = (BaseContext) model.getParent();
Enum predicate = CasesActivity.CREATED;
MessageResource objectMessageResource = CaseInfo.from(model);

Expand All @@ -178,7 +178,7 @@ public void onCaseUpdated(EntityUpdatedEvent<BaseCase> event) {

BaseCase model = event.getModel();
User user = model.getCreatedBy();
BaseContext context = model.getApplication();
SpaceCasesApp context = (SpaceCasesApp) model.getParent();
Enum predicate = CasesActivity.UPDATED;
MessageResource objectMessageResource = CaseInfo.from(model);

Expand All @@ -187,14 +187,16 @@ public void onCaseUpdated(EntityUpdatedEvent<BaseCase> event) {
}

@EventListener
public <C extends AbstractCaseComment> void onCaseCommentCreated(EntityCreatedEvent<C> event) {
public void onCaseCommentCreated(EntityCreatedEvent<BaseCaseComment> event) {

AbstractCaseComment model = event.getModel();
BaseCaseComment model = event.getModel();
BaseContext context = (BaseContext) model.getParent().getParent();
User user = model.getCreatedBy();
BaseContext context = model.getSubject().getApplication();
Enum predicate = CasesActivity.COMMENTED;
MessageResource objectMessageResource = CaseCommenttInfo.from(model);

createLog(model, user, context, predicate, objectMessageResource);

}

protected void createLog(AbstractPersistableModel model, User user, BaseContext context, Enum predicate, MessageResource objectMessageResource) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.restdude.domain.CommentableModel;
import com.restdude.domain.cases.ICaseModel;
import com.restdude.domain.cases.model.dto.BaseContextInfo;
import com.restdude.domain.cases.model.dto.CaseStatustInfo;
import com.restdude.domain.users.model.User;
import com.restdude.mdd.annotation.model.ModelResource;
import com.restdude.mdd.model.AbstractPersistableNamedModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
Expand All @@ -38,39 +35,23 @@
import org.apache.commons.lang3.builder.ToStringBuilder;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.UUID;

import java.util.UUID;

@Slf4j
@Entity
@Table(name = "case_base")
@Inheritance(strategy = InheritanceType.JOINED)
@ModelResource(pathFragment = BaseCase.API_PATH_FRAGMENT,
apiDescription = "Cases management")
@ApiModel(description = BaseCase.API_MODEL_DESCRIPTION)
public class BaseCase<C extends BaseCase<C, CC>, CC extends AbstractCaseComment>
extends AbstractPersistableNamedModel
implements ICaseModel<SpaceCasesApp, CC> {
public class BaseCase<C extends BaseCase<C, CC>, CC extends BaseCaseComment<C, CC>>
extends RetreivableResource<SpaceCasesApp, BaseCase>
/*implements ICaseModel<SpaceCasesApp, CC>*/ {

public static final String API_PATH_FRAGMENT = "cases";
public static final String API_MODEL_DESCRIPTION = "A model representing a case, such as an issue, ticket, note etc.";


@NotNull
@ApiModelProperty(value = "Short descriptive title")
@Column(name = "title", nullable = true, updatable = true, length = CommentableModel.MAX_TITLE_LENGTH)
@Getter
@Setter
private String title;

@ApiModelProperty(value = "Main content", notes = "Max byte length: " + CommentableModel.MAX_DETAIL_LENGTH)
@Column(name = "detail", nullable = true, updatable = true, length = CommentableModel.MAX_DETAIL_LENGTH)
@Getter
@Setter
private String detail;

@Column(name = "entry_index")
@Getter
@Setter
Expand All @@ -81,25 +62,12 @@ public class BaseCase<C extends BaseCase<C, CC>, CC extends AbstractCaseComment
@JoinColumn(referencedColumnName = "id", nullable = false, updatable = false)
private CaseStatus status;

@ApiModelProperty(value = "The application this case belongs to")
@ManyToOne(optional = false)
@JoinColumn(name = "application", nullable=false)
private SpaceCasesApp application;

@JsonIgnore
@OneToMany(mappedBy="subject", fetch= FetchType.LAZY)
@Getter @Setter
private List<CC> comments;

@ApiModelProperty(value = "Assigned to", readOnly = true, hidden = true)
@ManyToOne(fetch = FetchType.EAGER )
@JoinColumn(name = "assigned_to", referencedColumnName = "id", updatable = false)
@Getter @Setter
private User assignee;




@JsonIgnore
public CaseStatus getStatus() {
return status;
Expand All @@ -114,36 +82,15 @@ public void setStatus(CaseStatus status) {
this.status = status;
}


@JsonGetter("application")
public BaseContextInfo getApplicationDTO() {
return BaseContextInfo.from(this.application);
}

@JsonIgnore
@Override
public SpaceCasesApp getApplication() {
return application;
}

@Override
public void setApplication(SpaceCasesApp application) {
this.application = application;
}




public BaseCase() {
super();
}

public BaseCase(String title) {
this.title = title;
}

public BaseCase(String title, String detail) {
this.title = title;
this.detail = detail;
super();
this.setTitle(title);
this.setDetail(detail);
}

@Override
Expand All @@ -160,22 +107,14 @@ public String toString() {
@Override
public void preSave() {

log.debug("preSave, before: {}", this);
super.preSave();
if (this.getCreatedBy() != null && this.getId() == null) {
this.setCreatedBy(null);
}
if (StringUtils.isNotEmpty(this.getTitle()) && this.getTitle().length() > MAX_TITLE_LENGTH) {
this.setTitle(StringUtils.abbreviate(this.getTitle(), MAX_TITLE_LENGTH));
}
if (StringUtils.isNotEmpty(this.getDetail()) && this.getDetail().length() > CommentableModel.MAX_DETAIL_LENGTH) {
this.setDetail(StringUtils.abbreviate(this.getDetail(), CommentableModel.MAX_DETAIL_LENGTH));
}

if(StringUtils.isBlank(this.getName())){
this.setName(UUID.randomUUID().toString());
log.debug("preSave, tmp name: {}", this.getName());
}
log.debug("preSave, before: {}", this);
super.preSave();


log.debug("preSave, after: {}", this);
}

Expand Down
Loading

0 comments on commit 1a198ba

Please sign in to comment.