Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
manos committed Jun 19, 2017
1 parent b57507d commit 8e55561
Show file tree
Hide file tree
Showing 25 changed files with 253 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
metaValues = {
@MetaValue(value = "1", targetEntity = Space.class),
@MetaValue(value = "2", targetEntity = SpaceApp.class),
@MetaValue(value = "3", targetEntity = AbstractCase.class),
@MetaValue(value = "3", targetEntity = BaseCase.class),
@MetaValue(value = "4", targetEntity = AbstractCaseComment.class),
@MetaValue(value = "5", targetEntity = Membership.class),
@MetaValue(value = "6", targetEntity = MembershipRequest.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
*/
package com.restdude.domain.cases.listener;

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

import com.restdude.domain.cases.model.AbstractCase;
import com.restdude.domain.cases.model.BaseCase;
import com.restdude.domain.cases.model.AbstractCaseComment;
import com.restdude.domain.cases.model.ActivityLog;
import com.restdude.domain.cases.model.BaseContext;
Expand Down Expand Up @@ -51,7 +52,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
* Created by manos on 16/6/2017.
Expand Down Expand Up @@ -95,7 +95,11 @@ public void setSpaceService(SpaceService spaceService) {


@EventListener
public void onUserCreated(EntityCreatedEvent<User> event) {
public final void onUserCreatedListener(EntityCreatedEvent<User> event) {
this.onUserCreated(event);
}

protected void onUserCreated(EntityCreatedEvent<User> event) {

User user = event.getModel();
log.debug("onUserCreated user: {}", user.getUsername());
Expand Down Expand Up @@ -124,6 +128,10 @@ public void onUserCreated(EntityCreatedEvent<User> event) {


@EventListener
public final void onMembershipCreatedListener(EntityCreatedEvent<Membership> event) {
this.onMembershipCreated(event);
}

public void onMembershipCreated(EntityCreatedEvent<Membership> event) {

Membership model = event.getModel();
Expand All @@ -138,10 +146,15 @@ public void onMembershipCreated(EntityCreatedEvent<Membership> event) {
}



@EventListener
public void onCaseCreated(EntityUpdatedEvent<AbstractCase> event) {
public final void onCaseCreatedListener(EntityCreatedEvent<BaseCase> event) {
this.onCaseCreated(event);
}

AbstractCase model = event.getModel();
public void onCaseCreated(EntityCreatedEvent<BaseCase> event) {

BaseCase model = event.getModel();
User user = model.getCreatedBy();
BaseContext context = model.getApplication();
Enum predicate = CasesActivity.CREATED;
Expand All @@ -152,9 +165,13 @@ public void onCaseCreated(EntityUpdatedEvent<AbstractCase> event) {
}

@EventListener
public void onCaseUpdated(EntityCreatedEvent<AbstractCase> event) {
public final void onCaseUpdatedListener(EntityUpdatedEvent<BaseCase> event) {
this.onCaseUpdated(event);
}

public void onCaseUpdated(EntityUpdatedEvent<BaseCase> event) {

AbstractCase model = event.getModel();
BaseCase model = event.getModel();
User user = model.getCreatedBy();
BaseContext context = model.getApplication();
Enum predicate = CasesActivity.UPDATED;
Expand All @@ -165,15 +182,14 @@ public void onCaseUpdated(EntityCreatedEvent<AbstractCase> event) {
}

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

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


}

protected void createLog(AbstractPersistableModel model, User user, BaseContext context, Enum predicate, MessageResource objectMessageResource) {
Expand All @@ -184,6 +200,11 @@ protected void createLog(AbstractPersistableModel model, User user, BaseContext
.subject(user)
.predicate(predicate.name())
.object(model).build());
// handle base case subclasses
if(Objects.nonNull(model) && BaseCase.class.isAssignableFrom(model.getClass())){
activityLog.setDiscriminator("3");
}

log.debug("createLog: {}", activityLog);
activityLog = this.activityLogService.create(activityLog);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.restdude.domain.cases.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.restdude.domain.PersistableModel;
import com.restdude.domain.cases.ICaseCommentModel;
import com.restdude.mdd.model.AbstractPersistableNamedModel;
import io.swagger.annotations.ApiModelProperty;
Expand Down Expand Up @@ -50,7 +49,7 @@
@Slf4j
@Data
@MappedSuperclass
public abstract class AbstractCaseComment<T extends AbstractCase, C extends AbstractCaseComment>
public abstract class AbstractCaseComment<T extends BaseCase, C extends AbstractCaseComment>
extends AbstractPersistableNamedModel implements ICaseCommentModel<T, C> {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import com.restdude.domain.PersistableModel;
import com.restdude.domain.users.model.User;
import com.restdude.mdd.annotation.model.CurrentPrincipal;
import com.restdude.mdd.annotation.model.ModelResource;
import com.restdude.mdd.model.AbstractPersistableModel;
import com.restdude.mdd.model.AbstractPersistableNamedModel;
import com.restdude.mdd.model.AbstractSystemUuidPersistableModel;
import com.restdude.websocket.message.IActivityNotificationMessage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -65,8 +67,17 @@
@Entity
@Table(name = "space_user_activity")
@EntityListeners(AuditingEntityListener.class)
@ModelResource(
pathFragment = ActivityLog.API_PATH_FRAGMENT,
apiName = "Activity Logs",
apiDescription = ActivityLog.API_MODEL_DESCRIPTION)

@ApiModel(description = ActivityLog.API_MODEL_DESCRIPTION)
public class ActivityLog extends AbstractSystemUuidPersistableModel {

public static final String API_PATH_FRAGMENT = "activityLogs";
public static final String API_MODEL_DESCRIPTION = "User space activity feeds";

@CreatedDate
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
Expand All @@ -80,6 +91,12 @@ public class ActivityLog extends AbstractSystemUuidPersistableModel {
@Column(nullable = false, updatable = false)
private String predicate;

@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@ApiModelProperty(readOnly = true)
@Column(insertable = false, updatable = false)
@Getter @Setter
private String discriminator;

@CurrentPrincipal
@NotNull
@ManyToOne
Expand All @@ -99,4 +116,4 @@ public class ActivityLog extends AbstractSystemUuidPersistableModel {
@JoinColumn( name = "object_id" )
private AbstractPersistableModel object;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.restdude.domain.CommentableModel;
import com.restdude.domain.audit.model.AbstractBasicAuditedModel;
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;
import lombok.Setter;
Expand All @@ -43,21 +43,19 @@
import java.util.UUID;


/**
* Base topic impl
*
@Slf4j
@Entity
@Table(name = "case_base")
@Inheritance(strategy = InheritanceType.JOINED)
*/

@Slf4j
@MappedSuperclass
public class AbstractCase<A extends SpaceCasesApp<C>, C extends AbstractCase<A, C, CC>, CC extends AbstractCaseComment>
@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<A, CC> {
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
Expand Down Expand Up @@ -86,7 +84,7 @@ public class AbstractCase<A extends SpaceCasesApp<C>, C extends AbstractCase<A,
@ApiModelProperty(value = "The application this case belongs to")
@ManyToOne(optional = false)
@JoinColumn(name = "application", nullable=false)
private A application;
private SpaceCasesApp application;

@JsonIgnore
@OneToMany(mappedBy="subject", fetch= FetchType.LAZY)
Expand Down Expand Up @@ -124,26 +122,26 @@ public BaseContextInfo getApplicationDTO() {

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

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




public AbstractCase() {
public BaseCase() {
}

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

public AbstractCase(String title, String detail) {
public BaseCase(String title, String detail) {
this.title = title;
this.detail = detail;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
@Table(name = "context_base")
@Inheritance(strategy = InheritanceType.JOINED)
@ModelResource(pathFragment = BaseContext.API_PATH_FRAGMENT,
apiName = "AbstractContext",
apiDescription = "Contexts management")
@ApiModel(description = BaseContext.API_MODEL_DESCRIPTION)
public class BaseContext extends AbstractPersistableHierarchicalModel<BaseContext> implements IBaseContext<User, Membership, MembershipRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static com.restdude.domain.CommentableModel.MAX_DETAIL_LENGTH;

/**
* AbstractCase status option
* BaseCase status option
*/
@Entity
@Table(name = "case_status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
apiName = "ApplicationContext",
apiDescription = "Space applications")
@ApiModel(description = SpaceApp.API_MODEL_DESCRIPTION)
public class SpaceApp extends BaseContext {
public class SpaceApp extends BaseContext {


public static final String API_PATH_FRAGMENT = "spaceApps";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

@Entity
@Table(name = "context_cases_app")
public class SpaceCasesApp<C extends AbstractCase> extends SpaceApp {
public class SpaceCasesApp extends SpaceApp {

public static final String API_PATH_FRAGMENT = "caseApplications";
public static final String API_MODEL_DESCRIPTION = "A model representing an case management application of a some context";
Expand All @@ -51,21 +51,13 @@ public class SpaceCasesApp<C extends AbstractCase> extends SpaceApp {
@ApiModelProperty(value = "The cases owned by this business application")
@OneToMany(mappedBy="application")
@OrderBy("entryIndex ASC")
private List<C> cases;

public List<C> getCases() {
return cases;
}

public void setCases(List<C> cases) {
this.cases = cases;
}
private List<BaseCase> cases;

public SpaceCasesApp(){
}

public SpaceCasesApp(String name, String title, String description, String avatarUrl, String bannerUrl, ContextVisibilityType visibility, User owner,
Set<Membership> memberships, List<MembershipRequest> membershipRequests, CaseWorkflow workflow, List<C> cases) {
Set<Membership> memberships, List<MembershipRequest> membershipRequests, CaseWorkflow workflow, List<BaseCase> cases) {
super(name, title, description, avatarUrl, bannerUrl, visibility, owner, memberships, membershipRequests);
this.workflow = workflow;
this.cases = cases;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.restdude.domain.cases.model.AbstractCase;
import com.restdude.domain.cases.model.BaseCase;
import com.restdude.domain.users.model.UserDTO;
import com.restdude.websocket.message.MessageResource;
import io.swagger.annotations.ApiModel;
Expand All @@ -46,7 +46,7 @@ public class CaseInfo extends MessageResource<String> {
private static final Logger LOGGER = LoggerFactory.getLogger(CaseInfo.class);


public static CaseInfo from(AbstractCase resource) {
public static CaseInfo from(BaseCase resource) {
return resource != null ? new CaseInfo(resource) : null;
}

Expand All @@ -66,7 +66,7 @@ public CaseInfo() {
}


public CaseInfo(AbstractCase resource) {
public CaseInfo(BaseCase resource) {
this(resource.getId(), resource.getName(), resource.getTitle(), resource.getDetail(), resource.getCreatedDate(), UserDTO.fromUser(resource.getCreatedBy()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
*/
package com.restdude.domain.cases.repository;

import com.restdude.domain.cases.model.AbstractCase;
import com.restdude.domain.cases.model.BaseCase;
import com.restdude.mdd.repository.ModelRepository;
import org.springframework.data.repository.NoRepositoryBean;

@NoRepositoryBean
public interface AbstractCaseModelRepository<T extends AbstractCase<?,?,?>> extends ModelRepository<T, String> {
public interface AbstractCaseModelRepository<T extends BaseCase<?,?>> extends ModelRepository<T, String> {



Expand Down
Loading

0 comments on commit 8e55561

Please sign in to comment.