Skip to content

Commit

Permalink
Fixed some smells
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Jul 17, 2023
1 parent c594420 commit 248d1d3
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,8 @@ public ObjectList getContentChanges(String repositoryId, Holder<String> changeLo

validateSession();

try {
ObjectList ret = getRepository().getContentChanges(changeLogToken,
maxItems != null ? (int) maxItems.doubleValue() : 2000);
return ret;
} catch (Exception e) {
throw e;
}
return getRepository().getContentChanges(changeLogToken,
maxItems != null ? (int) maxItems.doubleValue() : 2000);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ServiceFactory extends AbstractServiceFactory {

private static final BigInteger DEFAULT_DEPTH_OBJECTS = BigInteger.valueOf(10);

private static final Logger log = LoggerFactory.getLogger(CmisService.class);
private static final Logger log = LoggerFactory.getLogger(ServiceFactory.class);

public ServiceFactory() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public TypeManager() {
* Creates the base types.
*/
private void setup() {
types = new HashMap<String, TypeDefinitionContainerImpl>();
typesList = new ArrayList<TypeDefinitionContainer>();
types = new HashMap<>();
typesList = new ArrayList<>();

// folder type
FolderTypeDefinitionImpl folderType = new FolderTypeDefinitionImpl();
Expand Down Expand Up @@ -474,7 +474,7 @@ private void addTypeInteral(AbstractTypeDefinition type) {
TypeDefinitionContainerImpl tdc = types.get(type.getParentTypeId());
if (tdc != null) {
if (tdc.getChildren() == null) {
tdc.setChildren(new ArrayList<TypeDefinitionContainer>());
tdc.setChildren(new ArrayList<>());
}
tdc.getChildren().add(tc);
}
Expand All @@ -500,7 +500,7 @@ private void addTypeInteral(AbstractTypeDefinition type) {
public TypeDefinitionList getTypesChildren(CallContext context, String typeId, boolean includePropertyDefinitions,
BigInteger maxItems, BigInteger skipCount) {
TypeDefinitionContainer tc = types.get(typeId);
TypeDefinitionListImpl result = new TypeDefinitionListImpl(new ArrayList<TypeDefinition>());
TypeDefinitionListImpl result = new TypeDefinitionListImpl(new ArrayList<>());
if (typeId == null) {
result.getList().add(copyTypeDefintion(types.get(FOLDER_TYPE_ID).getTypeDefinition()));
result.getList().add(copyTypeDefintion(types.get(DOCUMENT_TYPE_ID).getTypeDefinition()));
Expand All @@ -512,7 +512,7 @@ public TypeDefinitionList getTypesChildren(CallContext context, String typeId, b
.map(c -> copyTypeDefintion(c.getTypeDefinition())).collect(Collectors.toList()));
}

result.setHasMoreItems(tc != null ? result.getList().size() < tc.getChildren().size() : false);
result.setHasMoreItems(tc != null && result.getList().size() < tc.getChildren().size());
result.setNumItems(BigInteger.valueOf(tc != null ? tc.getChildren().size() : result.getList().size()));

if (!includePropertyDefinitions) {
Expand Down Expand Up @@ -546,7 +546,7 @@ public List<TypeDefinitionContainer> getTypesDescendants(CallContext context, St
}

// set property definition flag to default value if not set
boolean ipd = (includePropertyDefinitions == null ? false : includePropertyDefinitions.booleanValue());
boolean ipd = (includePropertyDefinitions != null && includePropertyDefinitions.booleanValue());

if (typeId == null) {
result.add(getTypesDescendants(d, types.get(FOLDER_TYPE_ID), ipd));
Expand Down Expand Up @@ -583,7 +583,7 @@ private TypeDefinitionContainer getTypesDescendants(int depth, TypeDefinitionCon
result.setTypeDefinition(type);

if (depth != 0 && tc.getChildren() != null) {
result.setChildren(new ArrayList<TypeDefinitionContainer>());
result.setChildren(new ArrayList<>());
for (TypeDefinitionContainer tdc : tc.getChildren()) {
result.getChildren()
.add(getTypesDescendants(depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<Long> findAllIds() {
return findIdsByWhere("", "", null);
} catch (Exception e) {
log.error(e.getMessage(), e);
return new ArrayList<Long>();
return new ArrayList<>();
}
}

Expand All @@ -118,7 +118,7 @@ public List<Long> findAllIds(long tenantId) {
return findIdsByWhere(" " + ENTITY + ".tenantId=" + tenantId, "", null);
} catch (Exception e) {
log.error(e.getMessage(), e);
return new ArrayList<Long>();
return new ArrayList<>();
}
}

Expand Down Expand Up @@ -217,7 +217,7 @@ protected void logQuery(String query) {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List findByQuery(String query, Object[] values, Integer max) throws PersistenceException {
List<Object> coll = new ArrayList<Object>();
List<Object> coll = new ArrayList<>();
try {
logQuery(query);
Query queryObject = prepareQuery(query, values, max);
Expand All @@ -231,7 +231,7 @@ public List findByQuery(String query, Object[] values, Integer max) throws Persi
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List findByQuery(String query, Map<String, Object> parameters, Integer max) throws PersistenceException {
List<Object> coll = new ArrayList<Object>();
List<Object> coll = new ArrayList<>();
try {
logQuery(query);
Query queryObject = prepareQuery(query, parameters, max);
Expand All @@ -244,13 +244,13 @@ public List findByQuery(String query, Map<String, Object> parameters, Integer ma

@Override
public List<Long> findIdsByWhere(String where, String order, Integer max) throws PersistenceException {
return findIdsByWhere(where, new Object[0], order, max);
return findIdsByWhere(where, new HashMap<>(), order, max);
}

@Override
public List<Long> findIdsByWhere(String where, Object[] values, String order, Integer max)
public List<Long> findIdsByWhere(String where, Map<String, Object> parameters, String order, Integer max)
throws PersistenceException {
List<Long> coll = new ArrayList<Long>();
List<Long> coll = new ArrayList<>();
try {
String sorting = StringUtils.isNotEmpty(order) && !order.toLowerCase().contains(ORDER_BY)
? ORDER_BY + " " + order
Expand All @@ -259,7 +259,7 @@ public List<Long> findIdsByWhere(String where, Object[] values, String order, In
+ (StringUtils.isNotEmpty(where) ? AND + where + ") " : " ")
+ (StringUtils.isNotEmpty(sorting) ? sorting : " ");
logQuery(query);
Query<Long> queryObject = prepareQueryForLong(query, values, max);
Query<Long> queryObject = prepareQueryForLong(query, parameters, max);
coll = queryObject.list();
return coll;
} catch (Exception e) {
Expand Down Expand Up @@ -407,25 +407,6 @@ protected Query<Object[]> prepareQuery(String expression, Object[] values, Integ
return queryObject;
}

/**
* Utility method useful for preparing an Hibernate query for longs
*
* @param expression The expression for the query
* @param values The parameters values to be used (optional, if the query is
* parametric)
* @param max Optional maximum number of wanted results
*
* @return The Hibernate query
*/
protected Query<Long> prepareQueryForLong(String expression, Object[] values, Integer max) {
if (values != null)
for (int i = 0; i < values.length; i++)
expression = expression.replace("?" + (i + 1), PARAM + (i + 1));
Query<Long> queryObject = sessionFactory.getCurrentSession().createQuery(expression, Long.class);
applyParamsAndLimit(values, max, queryObject);
return queryObject;
}

/**
* Applies the params
*
Expand All @@ -435,7 +416,7 @@ protected Query<Long> prepareQueryForLong(String expression, Object[] values, In
*
* @deprecated
*/
@Deprecated(since = "8.9")
@Deprecated(since = "8.8")
private void applyParamsAndLimit(Object[] values, Integer max, @SuppressWarnings("rawtypes")
Query queryObject) {
if (values != null && values.length > 0)
Expand All @@ -462,6 +443,23 @@ protected Query<Object[]> prepareQuery(String expression, Map<String, Object> va
return queryObject;
}

/**
* Utility method useful for preparing an Hibernate query for returning a
* long
*
* @param expression The expression for the query
* @param values The parameters values to be used (optional, if the query is
* parametric)
* @param max Optional maximum number of wanted results
*
* @return The Hibernate query
*/
protected Query<Long> prepareQueryForLong(String expression, Map<String, Object> values, Integer max) {
Query<Long> queryObject = sessionFactory.getCurrentSession().createQuery(expression, Long.class);
applyParamsAndLimit(values, max, queryObject);
return queryObject;
}

/**
* Utility method useful for preparing an Hibernate query for objects of
* this type
Expand Down
34 changes: 23 additions & 11 deletions logicaldoc-core/src/main/java/com/logicaldoc/core/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setFileVersion(String fileVersion) {
// collector
private boolean notifyEvent = true;

public static String ASPECT = "saveHistory";
public static final String ASPECT = "saveHistory";

private String ip;

Expand Down Expand Up @@ -290,8 +290,8 @@ public int getIsNew() {
return isNew;
}

public void setIsNew(int _new) {
this.isNew = _new;
public void setIsNew(int nnew) {
this.isNew = nnew;
}

public String getFilename() {
Expand Down Expand Up @@ -425,13 +425,7 @@ public String getColor() {
public void setColor(String color) {
this.color = color;
}

@Override
public int compareTo(History other) {
return getDate().compareTo(other.getDate());
}



protected void copyAttributesFrom(History source) {
setTenantId(source.getTenantId());
setDate(source.getDate());
Expand Down Expand Up @@ -465,6 +459,24 @@ protected void copyAttributesFrom(History source) {

@Override
public String toString() {
return getId() +" - " + event;
return getId() + " - " + event;
}

@Override
public int compareTo(History other) {
return getDate().compareTo(other.getDate());
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof History))
return false;
History other = (History) obj;
return other.getId() == this.getId();
}

@Override
public int hashCode() {
return Long.valueOf(getId()).hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ public void setRecordVersion(long recordVersion) {
this.recordVersion = recordVersion;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof PersistentObject))
return false;
PersistentObject other = (PersistentObject) obj;
return other.getId() == this.getId();
}

@Override
public int hashCode() {
return Long.valueOf(getId()).hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public interface PersistentObjectDAO<T extends PersistentObject> {
*
* @deprecated
*/
@Deprecated(since = "8.9")
@Deprecated(since = "8.8")
public List<T> findByWhere(String where, Object[] values, String order, Integer max) throws PersistenceException;

/**
Expand Down Expand Up @@ -145,6 +145,7 @@ public List<T> findByWhere(String where, Map<String, Object> parameters, String
*
* @throws PersistenceException raised in case of errors in the database
*/
@Deprecated(since = "8.8")
public List<T> findByObjectQuery(String query, Object[] values, Integer max) throws PersistenceException;

/**
Expand Down Expand Up @@ -175,7 +176,7 @@ public List<T> findByObjectQuery(String query, Map<String, Object> parameters, I
*
* @deprecated
*/
@Deprecated(since = "8.9")
@Deprecated(since = "8.8")
public List<Object> findByQuery(String query, Object[] values, Integer max) throws PersistenceException;

/**
Expand Down Expand Up @@ -213,14 +214,15 @@ public List<Object> findByQuery(String query, Map<String, Object> parameters, In
* @param where The where clause expression (for positional parameters,
* please use JPA-style: ?1, ?2 ...)
* @param values Parameters used in the where expression
* @param parameters The map of the parameters
* @param order The order clause expression
* @param max Maximum results number (optional)
*
* @return The list of marching entities ids
*
* @throws PersistenceException raised in case of errors in the database
*/
public List<Long> findIdsByWhere(String where, Object[] values, String order, Integer max)
public List<Long> findIdsByWhere(String where, Map<String, Object> parameters, String order, Integer max)
throws PersistenceException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static List<String> getAspects() {
PluginRegistry registry = PluginRegistry.getInstance();
Collection<Extension> exts = registry.getExtensions("logicaldoc-core", "Aspect");

List<String> aspects = new ArrayList<String>();
List<String> aspects = new ArrayList<>();
for (Extension ext : exts)
aspects.add(ext.getParameter("code").valueAsString());
Collections.sort(aspects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static SystemInfo get(long tenantId) {
*/
if (info.getFeatures() == null || info.getFeatures().length == 0)
try {
List<String> features = new ArrayList<String>();
List<String> features = new ArrayList<>();
PluginRegistry registry = PluginRegistry.getInstance();
Collection<Extension> exts = registry.getExtensions("logicaldoc-core", "Feature");
for (Extension extension : exts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CollectionTool {
*/
public List<Object> toList(Object[] array) {
if (array == null)
return new ArrayList<Object>();
return new ArrayList<>();
else
return Arrays.asList(array);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,8 @@ public void copyAttributes(AbstractDocument docVO) {
setWorkflowStatusDisplay(docVO.getWorkflowStatusDisplay());
setColor(docVO.getColor());

setAttributes(new HashMap<String, Attribute>());
setTags(new HashSet<Tag>());
setAttributes(new HashMap<>());
setTags(new HashSet<>());

try {
for (Entry<String, Attribute> entry : docVO.getAttributes().entrySet())
Expand Down
Loading

0 comments on commit 248d1d3

Please sign in to comment.