Skip to content

Commit

Permalink
Remove comments and fix some things
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed May 16, 2024
1 parent 1e67685 commit f0933d6
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 1,321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void searchForParentProcesses() {
return;
}
try {
List<ProcessInterface> processes = ServiceManager.getProcessService().findLinkableParentProcesses(searchQuery,
List<Process> processes = ServiceManager.getProcessService().findLinkableParentProcesses(searchQuery,
createProcessForm.getProject().getId(), createProcessForm.getTemplate().getRuleset().getId());
if (processes.isEmpty()) {
Helper.setMessage("createProcessForm.titleRecordLinkTab.searchButtonClick.noHits");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,52 +81,13 @@ public List<Batch> loadData(int first, int pageSize, String sortField, SortOrder
* @param batches
* to remove
*/
@Override
public void removeAll(Collection<Batch> batches) throws DataException {
for (Batch batch : batches) {
remove(batch);
}
}

// /**
// * Find batches by id of process.
// *
// * @param id
// * of process
// * @return list of JSON objects with batches for specific process id
// */
// public List<Map<String, Object>> findByProcessId(Integer id) throws DataException {
// QueryBuilder query = createSimpleQuery("processes.id", id, true);
// return findDocuments(query);
// }

// /**
// * Find batches by title of process.
// *
// * @param title
// * of process
// * @return list of JSON objects with batches for specific process title
// */
// public List<Map<String, Object>> findByProcessTitle(String title) throws DataException {
// QueryBuilder query = createSimpleQuery("processes.title", title, true, Operator.AND);
// return findDocuments(query);
// }

// @Override
// public BatchInterface convertJSONObjectToInterface(Map<String, Object> jsonObject, boolean related) throws DataException {
// BatchInterface batchInterface = DTOFactory.instance().newBatch();
// batchInterface.setId(getIdFromJSONObject(jsonObject));
// batchInterface.setTitle(BatchTypeField.TITLE.getStringValue(jsonObject));
// if (!related) {
// convertRelatedJSONObjects(jsonObject, batchInterface);
// }
// return batchInterface;
// }

// private void convertRelatedJSONObjects(Map<String, Object> jsonObject, BatchInterface batchInterface) throws DataException {
// batchInterface.setProcesses(convertRelatedJSONObjectToInterface(jsonObject, BatchTypeField.PROCESSES.getKey(),
// ServiceManager.getProcessService()));
// }

/**
* Returns true if the title (if set) or the
* id-based label contain the specified sequence of char values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,41 @@ public BeanQuery(Class<? extends BaseBean> beanClass) {
varName = objectClass.toLowerCase();
}

public void addInCollectionRestriction(String column, Collection<Integer> values) {
String parameterName = varName(column);
restrictions.add(varName + '.' + column + " IN (:" + parameterName + ')');
parameters.put(parameterName, values);
}

public void addIntegerRestriction(String column, int value) {
String parameterName = varName(column);
restrictions.add(varName + '.' + column + " = :" + parameterName);
parameters.put(parameterName, value);
}

public void addNotInCollectionRestriction(String column, Collection<Integer> values) {
String parameterName = varName(column);
restrictions.add(varName + '.' + column + " NOT IN (:" + parameterName + ')');
parameters.put(parameterName, values);
}


public void addNullRestriction(String column) {
restrictions.add(varName + '.' + column + " IS NULL");
}

public void forIdOrInTitle(String searchInput) {
try {
Integer possibleId = Integer.valueOf(searchInput);
restrictions.add('(' + varName + ".id = :possibleId OR " + varName + ".title LIKE '%:searchInput%')");
parameters.put("possibleId", possibleId);
parameters.put("searchInput", searchInput);
} catch (NumberFormatException e) {
restrictions.add(varName + ".title LIKE '%:searchInput%'");
parameters.put("searchInput", searchInput);
}
}

public void restrictToClient(int sessionClientId) {
switch (objectClass) {
case "Process":
Expand All @@ -50,6 +85,10 @@ public void restrictToClient(int sessionClientId) {
parameters.put("sessionClientId", sessionClientId);
}

public void restrictToNotCompletedProcesses() {
restrictions.add(varName + ".sortHelperStatus != '100000000000'");
}

public void restrictToProjects(Collection<Integer> projectIDs) {
switch (objectClass) {
case "Process":
Expand All @@ -64,28 +103,13 @@ public void restrictToProjects(Collection<Integer> projectIDs) {
parameters.put("projectIDs", projectIDs);
}

public void restrictToNotCompletedProcesses() {
restrictions.add(varName + ".sortHelperStatus != '100000000000'");
}

public void restrictWithUserFilterString(String s) {
// not yet implemented
}

public void addIntegerRestriction(String column, int value) {
String parameterName = varName(column);
restrictions.add(varName + '.' + column + " = :" + parameterName);
parameters.put(parameterName, value);
}

public void addInCollectionRestriction(String column, List<Integer> values) {
String parameterName = varName(column);
restrictions.add(varName + '.' + column + " IN (:" + parameterName + ')');
parameters.put(parameterName, values);
// full user filters not yet implemented
forIdOrInTitle(s);
}

public void defineSorting(String sortField, SortOrder sortOrder) {
sorting = Pair.of(sortField, SortOrder.DESCENDING.equals(sortOrder) ? "DESC" : "ASC");
sorting = Pair.of(varName + '.' + sortField, SortOrder.DESCENDING.equals(sortOrder) ? "DESC" : "ASC");
}

public String formCountQuery() {
Expand All @@ -96,16 +120,19 @@ public String formCountQuery() {
return query;
}

public String formWindowQuery(int offset, int limit) {
String query = "SELECT COUNT(*) FROM " + objectClass;
public String formQueryForAll() {
String query = "SELECT COUNT(*) FROM " + objectClass + " AS " + varName;
if (!restrictions.isEmpty()) {
query += " AS " + varName + " WHERE " + String.join(" AND ", restrictions);
query += " WHERE " + String.join(" AND ", restrictions);
}
query += " ORDER BY " + sorting.getKey() + ' ' + sorting.getValue()
+ " LIMIT " + limit + " OFFSET " + offset;
query += " ORDER BY " + sorting.getKey() + ' ' + sorting.getValue();
return query;
}

public String formWindowQuery(int offset, int limit) {
return formQueryForAll() + " LIMIT " + limit + (offset > 0 ? " OFFSET " + offset : "");
}

public Map<String, Object> getQueryParameters() {
return parameters;
}
Expand Down
Loading

0 comments on commit f0933d6

Please sign in to comment.