Skip to content

Commit

Permalink
small case improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
manos committed Jul 8, 2017
1 parent 1616d69 commit 5ef819f
Show file tree
Hide file tree
Showing 44 changed files with 1,037 additions and 268 deletions.
19 changes: 3 additions & 16 deletions restdude-boot/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,11 @@ spring:
add-mappings: true
logging:
level:
root: WARN
root: debug
com.yahoo.elide.core: WARN
org.springframework.security: WARN
org.springframework.security: debug
springfox.documentation.schema.property.CachingModelPropertiesProvider: ERROR
com.restdude:
init: WARN
mdd.service.AbstractPersistableModelServiceImpl: WARN
mdd.repository: WARN
domain.error: WARN

# test: debug
# mdd: WARN
# jsonapi: WARN
# util.email.service.AbstractEmailService: WARN
# web.filters.RestRequestNormalizerFilter: WARN

# repository: DEBUG
# validation: DEBUG
com.restdude: debug


server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.restdude.domain.error;
package com.restdude.domain.cases;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CaseUtil {


public static String getRemoteAddress(HttpServletRequest request) {
String addresss = request.getHeader("X-FORWARDED-FOR");
if (addresss == null) {
addresss = request.getRemoteAddr();
}
return addresss;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void onCaseCreated(EntityCreatedEvent<BaseCase> event) {
BaseCase model = event.getModel();
User user = model.getCreatedBy();
BaseContext context = (BaseContext) model.getParent();
Enum predicate = CasesActivity.CREATED;
Enum predicate = CasesActivity.CASE_CREATED;
MessageResource objectMessageResource = CaseInfo.from(model);

createLog(model, user, context, predicate, objectMessageResource);
Expand All @@ -178,7 +178,7 @@ public void onCaseUpdated(EntityUpdatedEvent<BaseCase> event) {
BaseCase model = event.getModel();
User user = model.getCreatedBy();
SpaceCasesApp context = (SpaceCasesApp) model.getParent();
Enum predicate = CasesActivity.UPDATED;
Enum predicate = CasesActivity.CASE_UPDATED;
MessageResource objectMessageResource = CaseInfo.from(model);

createLog(model, user, context, predicate, objectMessageResource);
Expand All @@ -194,7 +194,7 @@ public void onCaseCommentCreated(EntityCreatedEvent<BaseCaseComment> event) {
BaseCaseComment model = event.getModel();
BaseContext context = (BaseContext) model.getParent().getParent();
User user = model.getCreatedBy();
Enum predicate = CasesActivity.COMMENTED;
Enum predicate = CasesActivity.CASE_COMMENTED;
MessageResource objectMessageResource = CaseCommenttInfo.from(model);

createLog(model, user, context, predicate, objectMessageResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
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;
Expand All @@ -48,10 +46,9 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Any;
import org.hibernate.annotations.AnyMetaDef;
import org.hibernate.annotations.MetaValue;
import org.javers.core.metamodel.annotation.DiffIgnore;

import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
Expand Down Expand Up @@ -86,6 +83,15 @@ public class ActivityLog extends AbstractSystemUuidPersistableModel {
@Getter @Setter
private LocalDateTime createdDate;

@CreatedBy
@DiffIgnore
@JsonIgnore
@ApiModelProperty(value = "Created by", readOnly = true, hidden = true)
@ManyToOne(fetch = FetchType.EAGER )
@JoinColumn(name = "created_by", referencedColumnName = "id", updatable = false)
@Getter @Setter
private User createdBy;

@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@ApiModelProperty(readOnly = true)
@Column(nullable = false, updatable = false)
Expand All @@ -97,7 +103,7 @@ public class ActivityLog extends AbstractSystemUuidPersistableModel {
@Getter @Setter
private String discriminator;

@CurrentPrincipal
//@CurrentPrincipal
@NotNull
@ManyToOne
@JoinColumn(nullable = false, updatable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
package com.restdude.domain.cases.model;

import static com.restdude.domain.CommentableModel.MAX_DETAIL_LENGTH;

import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand All @@ -33,11 +35,11 @@
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.servlet.http.HttpServletRequest;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.restdude.domain.cases.model.dto.CaseStatustInfo;
import com.restdude.domain.cases.CaseUtil;
import com.restdude.domain.cms.model.Tag;
import com.restdude.domain.users.model.User;
import com.restdude.mdd.annotation.model.ModelResource;
Expand All @@ -64,6 +66,11 @@ public class BaseCase<C extends BaseCase<C, CC>, CC extends BaseCaseComment<C,
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.";

@ApiModelProperty(value = "The address the request originated from", readOnly = true)
@Column(name = "remote_address", updatable = false, length = MAX_DETAIL_LENGTH)
@Getter @Setter
private String remoteAddress;

@Formula(" (select count(*) from case_comment_base where case_comment_base.parent_case = id ) ")
@ApiModelProperty(value = "The number of open cases")
@Getter @Setter
Expand All @@ -90,6 +97,7 @@ public class BaseCase<C extends BaseCase<C, CC>, CC extends BaseCaseComment<C,
@ApiModelProperty(value = "Current case status", allowableValues = "OPEM, CLOSED, [CUSTOM_VALUE]")
@ManyToOne
@JoinColumn(referencedColumnName = "id", nullable = false, updatable = false)
@Getter @Setter
private CaseStatus status;

@ApiModelProperty(value = "Assigned to", readOnly = true, hidden = true)
Expand All @@ -99,18 +107,24 @@ public class BaseCase<C extends BaseCase<C, CC>, CC extends BaseCaseComment<C,
private User assignee;

@DiffIgnore
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_app", referencedColumnName = "id", nullable = false)
@Getter @Setter
private SpaceCasesApp parentApplication;

@JsonIgnore
@ManyToOne(optional = true)
@JoinColumn(name = "target", nullable = true)
@ApiModelProperty(value = "The target resource for this case", required = false)
@Getter @Setter
private CaseTarget target;

@JsonIgnore
@OneToMany(mappedBy = "parentCase", orphanRemoval = true)
@ApiModelProperty(value = "The case comments")
@Getter @Setter
private List<BaseCaseComment> comments;

/*
@JsonIgnore
public CaseStatus getStatus() {
return status;
Expand All @@ -124,7 +138,7 @@ public CaseStatustInfo getStatusrDTO() {
public void setStatus(CaseStatus status) {
this.status = status;
}

*/
public BaseCase() {
super();
}
Expand All @@ -136,6 +150,17 @@ public BaseCase(String title, String detail) {
this.setDetail(detail);
}

//TODO: move this to a spring adapter or something
public void addRequestInfo(HttpServletRequest request) {
// get request info
if (request != null) {

if (this.remoteAddress == null) {
this.remoteAddress = CaseUtil.getRemoteAddress(request);
}
}
}

@Override
public String toString() {
return new ToStringBuilder(this)
Expand All @@ -144,12 +169,18 @@ public String toString() {
.append("entryIndex", this.getEntryIndex())
.append("title", this.getTitle())
.append("status", this.getStatus())
.append("parentApplication", this.getParentApplication())

.toString();
}

@Override
public void preSave() {

if (StringUtils.isNotEmpty(this.remoteAddress) && this.remoteAddress.length() > MAX_DETAIL_LENGTH) {
this.remoteAddress = StringUtils.abbreviate(this.remoteAddress, MAX_DETAIL_LENGTH);
}

// TODO: tmp parent pointer to app, should point to comment
if(Objects.isNull(this.getParent())){
this.setParent(this.getParentApplication());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,39 @@
*/
package com.restdude.domain.cases.model;

import static com.restdude.domain.CommentableModel.MAX_DETAIL_LENGTH;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import com.restdude.domain.audit.model.AbstractBasicAuditedModel;
import com.restdude.mdd.annotation.model.ModelResource;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import static com.restdude.domain.CommentableModel.MAX_DETAIL_LENGTH;

/**
* BaseCase status option
*/
@Entity
@Table(name = "case_status")
@ModelResource(pathFragment = CaseStatus.API_PATH_FRAGMENT,
apiDescription = "Cases workflow management")
@ApiModel(description = CaseStatus.API_MODEL_DESCRIPTION)
public class CaseStatus extends AbstractBasicAuditedModel {

public static final String API_PATH_FRAGMENT = "caseStatuses";
public static final String API_MODEL_DESCRIPTION = "A model representing a status option of a case workflow.";

public static final String UNASSIGNED = "Unassigned";
public static final String OPEN = "Open";
public static final String CLOSED = "Closed";
public static final String ARCHIVED = "Archived";

@NotNull
@ApiModelProperty(value = "Short description, i.e. one or two words")
Expand Down

This file was deleted.

Loading

0 comments on commit 5ef819f

Please sign in to comment.