Commit 8be3df09 authored by Matija Obreza's avatar Matija Obreza
Browse files

Web: Removed obsolete WebAuditedModel and WebAuditedModelFilter

parent 7ce332a0
......@@ -25,25 +25,21 @@ import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.model.AclSid;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.genesys.blocks.util.JsonSidConverter;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@MappedSuperclass
public abstract class WebOwnedModel extends WebAuditedModel {
public abstract class WebOwnedModel extends AuditedModel implements LazyLoading<WebOwnedModel> {
private static final long serialVersionUID = -2708780479620558305L;
@ManyToOne(fetch = FetchType.EAGER, cascade = {})
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "owned_by", nullable = false)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonIdentityInfo(scope = AclSid.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = false)
@Field(type = FieldType.Object)
@JsonSerialize(converter = JsonSidConverter.class)
private AclSid ownedBy;
@Basic
......@@ -56,7 +52,7 @@ public abstract class WebOwnedModel extends WebAuditedModel {
@PrePersist
private void prePersist() {
if (ownedBy == null) {
ownedBy = new WebUser(this.getCreatedBy());
ownedBy = SecurityContextUtil.getCurrentUser();
}
if (ownedDate == null) {
ownedDate = this.getCreatedDate();
......@@ -81,7 +77,6 @@ public abstract class WebOwnedModel extends WebAuditedModel {
@Override
public void lazyLoad() {
super.lazyLoad();
if (this.ownedBy != null) {
this.ownedBy.getId();
}
......
/*
* Copyright 2020 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gringlobal.service.filter;
import java.util.List;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.DateFilter;
import org.genesys.blocks.model.filters.EmptyModelFilter;
import org.gringlobal.model.QWebAuditedModel;
import org.gringlobal.model.WebAuditedModel;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.EntityPathBase;
/**
* {@link WebAuditedModel} match by sample filters.
*
* @param <T> the generic type
* @param <R> the generic type
*/
public abstract class WebAuditedModelFilter<T extends WebAuditedModelFilter<T, R>, R extends WebAuditedModel> extends EmptyModelFilter<T, R> {
/** The created by. */
public Set<Long> createdBy;
/** The created date. */
public DateFilter createdDate;
/** The last modified by. */
public Set<Long> modifiedBy;
/** The last modified date. */
public DateFilter modifiedDate;
protected List<Predicate> collectPredicates(final EntityPathBase<R> instance, final QWebAuditedModel webAuditedModel) {
List<Predicate> predicates = super.collectPredicates(instance);
if (CollectionUtils.isNotEmpty(createdBy)) {
predicates.add(webAuditedModel.createdBy.in(createdBy));
}
if (CollectionUtils.isNotEmpty(modifiedBy)) {
predicates.add(webAuditedModel.modifiedBy.in(modifiedBy));
}
if (createdDate != null) {
predicates.add(createdDate.buildQuery(webAuditedModel.createdDate));
}
if (modifiedDate != null) {
predicates.add(modifiedDate.buildQuery(webAuditedModel.modifiedDate));
}
return predicates;
}
/**
* Created date.
*
* @return the date filter
*/
public synchronized DateFilter createdDate() {
if (createdDate == null) {
createdDate = new DateFilter();
}
return createdDate;
}
/**
* Last modified date.
*
* @return the date filter
*/
public synchronized DateFilter modifiedDate() {
if (modifiedDate == null) {
modifiedDate = new DateFilter();
}
return modifiedDate;
}
}
......@@ -20,6 +20,7 @@ import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.DateFilter;
import org.genesys.blocks.model.filters.EmptyModelFilter;
import org.gringlobal.model.QWebOwnedModel;
import org.gringlobal.model.WebOwnedModel;
......@@ -32,7 +33,7 @@ import com.querydsl.core.types.dsl.EntityPathBase;
* @param <T> the generic type
* @param <R> the generic type
*/
public abstract class WebOwnedModelFilter<T extends WebOwnedModelFilter<T, R>, R extends WebOwnedModel> extends WebAuditedModelFilter<T, R> {
public abstract class WebOwnedModelFilter<T extends WebOwnedModelFilter<T, R>, R extends WebOwnedModel> extends EmptyModelFilter<T, R> {
/** The owned by. */
public Set<Long> ownedBy;
......@@ -40,6 +41,15 @@ public abstract class WebOwnedModelFilter<T extends WebOwnedModelFilter<T, R>, R
/** The owned date. */
public DateFilter ownedDate;
/** The created by. */
public Set<Long> createdBy;
/** The created date. */
public DateFilter createdDate;
/** The last modified by. */
public Set<Long> modifiedBy;
/** The last modified date. */
public DateFilter modifiedDate;
/**
* Collects list of filter predicates
*
......@@ -86,4 +96,28 @@ public abstract class WebOwnedModelFilter<T extends WebOwnedModelFilter<T, R>, R
return value ? "Y" : "N";
}
/**
* Created date.
*
* @return the date filter
*/
public synchronized DateFilter createdDate() {
if (createdDate == null) {
createdDate = new DateFilter();
}
return createdDate;
}
/**
* Last modified date.
*
* @return the date filter
*/
public synchronized DateFilter modifiedDate() {
if (modifiedDate == null) {
modifiedDate = new DateFilter();
}
return modifiedDate;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment