-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathDepartmentHelper.java
50 lines (38 loc) · 1.39 KB
/
DepartmentHelper.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
package com.intuit.developer.sampleapp.crud.helper;
import java.util.List;
import org.apache.commons.lang.RandomStringUtils;
import com.intuit.ipp.data.Department;
import com.intuit.ipp.data.ReferenceType;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.services.DataService;
/**
* @author dderose
*
*/
public final class DepartmentHelper {
private DepartmentHelper() {
}
public static Department getDepartmentFields() throws FMSException {
Department department = new Department();
department.setName("departmentname_" + RandomStringUtils.randomAlphanumeric(5));
department.setFullyQualifiedName("departmentname_" + RandomStringUtils.randomAlphanumeric(5));
department.setSubDepartment(false);
return department;
}
public static Department getDepartment(DataService service) throws FMSException {
List<Department> departments = (List<Department>) service.findAll(new Department());
if (!departments.isEmpty()) {
return departments.get(0);
}
return createDepartment(service);
}
private static Department createDepartment(DataService service) throws FMSException {
return service.add(getDepartmentFields());
}
public static ReferenceType getDepartmentRef(Department department) {
ReferenceType departmentRef = new ReferenceType();
departmentRef.setName(department.getName());
departmentRef.setValue(department.getId());
return departmentRef;
}
}