This repository has been archived by the owner on Oct 17, 2018. It is now read-only.
/
StandardOutlineService.java
75 lines (65 loc) · 3.47 KB
/
StandardOutlineService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*******************************************************************************
* Copyright (c) 2013 BSI Business Systems Integration AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* BSI Business Systems Integration AG - initial API and implementation
******************************************************************************/
package org.eclipsescout.demo.minicrm.server.services;
import org.eclipse.scout.commons.StringUtility;
import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.commons.holders.NVPair;
import org.eclipse.scout.rt.server.services.common.jdbc.SQL;
import org.eclipse.scout.service.AbstractService;
import org.eclipsescout.demo.minicrm.shared.services.IStandardOutlineService;
import org.eclipsescout.demo.minicrm.shared.ui.desktop.outlines.pages.CompanyTablePageData;
import org.eclipsescout.demo.minicrm.shared.ui.desktop.outlines.pages.PersonTablePageData;
import org.eclipsescout.demo.minicrm.shared.ui.desktop.outlines.pages.searchform.CompanySearchFormData;
import org.eclipsescout.demo.minicrm.shared.ui.desktop.outlines.pages.searchform.PersonSearchFormData;
public class StandardOutlineService extends AbstractService implements IStandardOutlineService {
@Override
public CompanyTablePageData getCompanyTableData(CompanySearchFormData formData) throws ProcessingException {
StringBuilder statement = new StringBuilder();
statement.append(
"SELECT COMPANY_NR, " +
" SHORT_NAME, " +
" NAME, " +
" TYPE_UID " +
" FROM COMPANY " +
" WHERE 1 = 1 ");
if (!StringUtility.isNullOrEmpty(formData.getShortName().getValue())) {
statement.append("AND UPPER(SHORT_NAME) LIKE UPPER(:shortName || '%') ");
}
if (!StringUtility.isNullOrEmpty(formData.getName().getValue())) {
statement.append("AND UPPER(NAME) LIKE UPPER(:name || '%')");
}
statement.append("INTO :{page.companyNr}, :{page.shortName}, :{page.name}, :{page.companyType}");
CompanyTablePageData pageData = new CompanyTablePageData();
SQL.selectInto(statement.toString(), formData, new NVPair("page", pageData));
return pageData;
}
@Override
public PersonTablePageData getPersonTableData(PersonSearchFormData formData) throws ProcessingException {
StringBuilder statement = new StringBuilder();
statement.append("SELECT PERSON_NR, LAST_NAME, FIRST_NAME FROM PERSON WHERE 1=1 ");
if (!StringUtility.isNullOrEmpty(formData.getFirstName().getValue())) {
statement.append("AND UPPER(FIRST_NAME) LIKE UPPER(:firstName || '%') ");
}
if (!StringUtility.isNullOrEmpty(formData.getLastName().getValue())) {
statement.append("AND UPPER(LAST_NAME) LIKE UPPER(:lastName || '%') ");
}
if (formData.getEmployer().getValue() != null) {
statement.append("AND COMPANY_NR = :employer ");
}
else if (formData.getEmployerType().getValue() != null) {
statement.append("AND COMPANY_NR IN (SELECT COMPANY_NR FROM COMPANY WHERE TYPE_UID = :employerType) ");
}
statement.append("INTO :{page.personNr}, :{page.lastName}, :{page.firstName}");
PersonTablePageData pageData = new PersonTablePageData();
SQL.select(statement.toString(), formData, new NVPair("page", pageData));
return pageData;
}
}