Skip to content

Commit 47508bc

Browse files
committed
Merge branch 'develop' into Bug51-export-creation
# Conflicts: # src/main/java/main/controllers/AuditController.java
2 parents e44c4d1 + a296be6 commit 47508bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+267
-324
lines changed

src/main/java/main/controllers/Administration/AppSettingsController.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,43 +26,46 @@ public AppSettingsController(UserDto user) {
2626
}
2727

2828
public LdapDto getLdap() throws AqualityException {
29-
if(baseUser.isAdmin()){
29+
if (baseUser.isAdmin()) {
3030
return ldapDao.getAll().get(0);
31-
}else{
31+
} else {
3232
throw new AqualityPermissionsException("Account is not allowed to view LDAP Settings", baseUser);
3333
}
3434
}
35+
3536
public AppSettingsDto getApp() throws AqualityException {
3637
return appSettingsDao.getAll().get(0);
3738
}
3839

3940
public LdapDto create(LdapDto template) throws AqualityException {
40-
if(baseUser.isAdmin()){
41+
if (baseUser.isAdmin()) {
4142
template.setAdminSecret(template.getAdminSecret() == null || template.getAdminSecret().equals("")
4243
? ""
4344
: hideAdminSecret(template.getAdminSecret()));
4445
return ldapDao.create(template);
45-
}else{
46+
} else {
4647
throw new AqualityPermissionsException("Account is not allowed to update LDAP Settings", baseUser);
4748
}
4849
}
4950

5051

5152
@Override
5253
public AppSettingsDto create(AppSettingsDto template) throws AqualityException {
53-
if(baseUser.isAdmin()){
54+
if (baseUser.isAdmin()) {
5455
return appSettingsDao.create(template);
55-
}else{
56+
} else {
5657
throw new AqualityPermissionsException("Account is not allowed to update Application Settings", baseUser);
5758
}
5859
}
5960

60-
@Override @NotImplemented
61+
@Override
62+
@NotImplemented
6163
public List<AppSettingsDto> get(AppSettingsDto entity) throws AqualityException {
6264
throw new UnsupportedOperationException();
6365
}
6466

65-
@Override @NotImplemented
67+
@Override
68+
@NotImplemented
6669
public boolean delete(AppSettingsDto entity) throws AqualityException {
6770
throw new UnsupportedOperationException();
6871
}
@@ -79,11 +82,11 @@ public String getAdminSecret() throws AqualityException {
7982
}
8083

8184
private String hideAdminSecret(String secret) throws AqualityException {
82-
try{
85+
try {
8386
Base64 base64 = new Base64();
84-
secret = base64.encodeToString(("JmbGFzYmRmamtiYXNsZA"+secret+"qYXNkaGxma2poYXNka2xqZmJka2").getBytes("utf-8"));
85-
return base64.encodeToString(("YXNkamhmbGtqYXNkaGx"+secret+"a2poYXNka2xqZmJka2phc2JmbGFzYmRmamtiYXNsZA").getBytes("utf-8"));
86-
}catch (UnsupportedEncodingException e){
87+
secret = base64.encodeToString(("JmbGFzYmRmamtiYXNsZA" + secret + "qYXNkaGxma2poYXNka2xqZmJka2").getBytes("utf-8"));
88+
return base64.encodeToString(("YXNkamhmbGtqYXNkaGx" + secret + "a2poYXNka2xqZmJka2phc2JmbGFzYmRmamtiYXNsZA").getBytes("utf-8"));
89+
} catch (UnsupportedEncodingException e) {
8790
throw new AqualityException("Cannot hide Admin Secret.");
8891
}
8992
}

src/main/java/main/controllers/Administration/EmailSettingsController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public EmailSettingsDto create(EmailSettingsDto template) throws AqualityExcepti
2929
return emailSettingsDao.create(template);
3030
}
3131

32-
@Override @NotImplemented
32+
@Override
33+
@NotImplemented
3334
public boolean delete(EmailSettingsDto entity) throws AqualityException {
3435
throw new UnsupportedOperationException();
3536
}

src/main/java/main/controllers/Administration/UserController.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public UserController(UserDto user) {
3838

3939
@Override
4040
public UserDto create(UserDto template) throws AqualityException {
41-
if(baseUser.isAdmin() || baseUser.getId().equals(template.getId())){
42-
if(template.getPassword() != null){
41+
if (baseUser.isAdmin() || baseUser.getId().equals(template.getId())) {
42+
if (template.getPassword() != null) {
4343
template.setPassword(saltPassword(template, template.getPassword()));
4444
}
4545
return userDao.create(template);
46-
}else{
46+
} else {
4747
throw new AqualityPermissionsException("Account is not allowed to create User", baseUser);
4848
}
4949
}
@@ -55,9 +55,9 @@ public List<UserDto> get(UserDto template) throws AqualityException {
5555

5656
@Override
5757
public boolean delete(UserDto template) throws AqualityException {
58-
if(baseUser.isAdmin()){
58+
if (baseUser.isAdmin()) {
5959
return userDao.delete(template);
60-
}else{
60+
} else {
6161
throw new AqualityPermissionsException("Account is not allowed to delete User", baseUser);
6262
}
6363
}
@@ -77,7 +77,7 @@ public UserDto updatePassword(PasswordDto password) throws AqualityException {
7777
}
7878

7979
UserDto auth(String authString, boolean ldap) throws AqualityException {
80-
Base64 base64= new Base64();
80+
Base64 base64 = new Base64();
8181
String authStringDecoded = StringUtils.newStringUtf8(base64.decode(authString));
8282
String[] authStringSplit = authStringDecoded.split(":");
8383
ConnectionUrlParser.Pair<String, PrivateKey> privateKeyPair
@@ -94,7 +94,7 @@ UserDto auth(String authString, boolean ldap) throws AqualityException {
9494

9595
UserDto user = ldap ? handleLDAPAuthorization(authStringSplit[0], password) : checkUser(authStringSplit[0], password);
9696

97-
if(user != null){
97+
if (user != null) {
9898
user.setSession_code(generateSessionCode(user));
9999
updateSession(user);
100100
return user;
@@ -113,7 +113,7 @@ private List<UserDto> toPublicUsers(List<UserDto> users) {
113113
}
114114

115115
private String generateSessionCode(UserDto user) {
116-
Base64 base64= new Base64();
116+
Base64 base64 = new Base64();
117117
DateUtils dates = new DateUtils();
118118
String encode = null;
119119
try {
@@ -124,21 +124,21 @@ private String generateSessionCode(UserDto user) {
124124
return encode;
125125
}
126126

127-
private String saltPassword(UserDto user, String password){
127+
private String saltPassword(UserDto user, String password) {
128128
String passHash = DigestUtils.md5Hex(password);
129-
return DigestUtils.md5Hex(user.getEmail()+passHash+"kjr1fdd00das");
129+
return DigestUtils.md5Hex(user.getEmail() + passHash + "kjr1fdd00das");
130130
}
131131

132132
private UserDto checkUser(String user_name, String password) throws AqualityException {
133133
UserDto user = new UserDto();
134134
user.setUser_name(user_name);
135135
List<UserDto> users = userDao.searchAll(user);
136136

137-
if(users.size() > 0){
137+
if (users.size() > 0) {
138138
user = users.get(0);
139139
String correctHex = user.getPassword();
140140
String actualHex = saltPassword(user, password);
141-
if(correctHex.equals(actualHex)){
141+
if (correctHex.equals(actualHex)) {
142142
return user;
143143
}
144144
}
@@ -150,12 +150,12 @@ private UserDto handleLDAPAuthorization(String userName, String password) throws
150150
LDAPAuthenticator ldap = new LDAPAuthenticator();
151151
UserDto user;
152152
user = ldap.tryAuthWithLdap(userName, password);
153-
if(user != null){
153+
if (user != null) {
154154
UserDto templateUser = new UserDto();
155155
templateUser.setUser_name(user.getUser_name());
156156
List<UserDto> users = get(templateUser);
157157

158-
if(users.size() > 0){
158+
if (users.size() > 0) {
159159
user.setId(users.get(0).getId());
160160
}
161161

src/main/java/main/controllers/AuditController.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,9 @@ public List<AuditStatisticDto> get(AuditStatisticDto template) throws AqualityEx
8181
}
8282
}
8383

84-
public List<AuditAttachmentDto> get(AuditAttachmentDto searchTemplate) throws AqualityException {
84+
public List<AuditAttachmentDto> get(AuditAttachmentDto searchTemplate, Integer projectId) throws AqualityException {
8585
AuditDto audit = new AuditDto();
8686
audit.setId(searchTemplate.getAudit_id());
87-
Integer projectId;
88-
try {
89-
projectId = auditDao.searchAll(audit).get(0).getProject_id();
90-
} catch (IndexOutOfBoundsException e) {
91-
throw new AqualityException("The Audit you trying to access is not present!");
92-
}
9387
if (baseUser.isFromGlobalManagement() || baseUser.getProjectUser(projectId).isViewer()) {
9488
return auditAttachmentsDao.searchAll(searchTemplate);
9589
} else {
@@ -131,6 +125,7 @@ public String create(boolean all, boolean xls) throws AqualityException {
131125
AuditStatusDto auditStatusDto = new AuditStatusDto();
132126
auditStatusDto.setId(4);
133127
auditDto.setStatus(auditStatusDto);
128+
134129
List<AuditDto> audits = get(auditDto);
135130
if (!all) {
136131
audits = getLatestAudits(audits);
@@ -166,10 +161,10 @@ public boolean delete(AuditDto template) throws AqualityException {
166161
}
167162
}
168163

169-
public boolean delete(AuditAttachmentDto template) throws AqualityException {
164+
public boolean delete(AuditAttachmentDto template, Integer projectId) throws AqualityException {
170165
if (baseUser.isAuditor() || baseUser.isAuditAdmin()) {
171166
FileUtils fileUtils = new FileUtils();
172-
List<AuditAttachmentDto> attachments = get(template);
167+
List<AuditAttachmentDto> attachments = get(template, projectId);
173168
List<String> pathes = new ArrayList<>();
174169
pathes.add(attachments.get(0).getPath());
175170
fileUtils.removeFiles(pathes);
@@ -355,10 +350,8 @@ private List<Pair<String, String>> processExportArrayCreation(JSONArray resArray
355350
jsonObject.put("project_name", auditDto.getProject().getName());
356351
if (auditDto.getCreated() != null) jsonObject.put("created", formatter.format(auditDto.getCreated()));
357352
if (auditDto.getStarted() != null) jsonObject.put("started", formatter.format(auditDto.getStarted()));
358-
if (auditDto.getProgress_finished() != null)
359-
jsonObject.put("finished", formatter.format(auditDto.getProgress_finished()));
360-
if (auditDto.getSubmitted() != null)
361-
jsonObject.put("submitted", formatter.format(auditDto.getSubmitted()));
353+
if (auditDto.getProgress_finished() != null) jsonObject.put("finished", formatter.format(auditDto.getProgress_finished()));
354+
if (auditDto.getSubmitted() != null) jsonObject.put("submitted", formatter.format(auditDto.getSubmitted()));
362355
jsonObject.put("result", auditDto.getResult());
363356
String auditorsString = "";
364357
List<AuditorDto> auditors = auditDto.getAuditors();

src/main/java/main/controllers/BaseController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import main.model.dto.BaseDto;
44
import main.model.dto.UserDto;
55

6-
public abstract class BaseController<T extends BaseDto> implements IController<T> {
6+
public abstract class BaseController<T extends BaseDto> implements IController<T>{
77
protected UserDto baseUser;
88
protected PermissionsChecker permissionsChecker;
99

10-
protected BaseController(UserDto user){
10+
protected BaseController(UserDto user) {
1111
baseUser = user;
1212
permissionsChecker = new PermissionsChecker(baseUser);
1313
}

src/main/java/main/controllers/CustomerController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ public List<CustomerDto> get(CustomerDto template, boolean withChildren) throws
3636

3737
@Override
3838
public CustomerDto create(CustomerDto template) throws AqualityException {
39-
if(baseUser.isCoordinator()){
39+
if (baseUser.isCoordinator()) {
4040
return fillCustomer(customerDao.create(template));
41-
}else{
41+
} else {
4242
throw new AqualityPermissionsException("Account is not allowed to create Customers", baseUser);
4343
}
4444
}
4545

4646
@Override
4747
public boolean delete(CustomerDto template) throws AqualityException {
48-
if(baseUser.isCoordinator()){
48+
if (baseUser.isCoordinator()) {
4949
return customerDao.delete(template);
50-
}else{
50+
} else {
5151
throw new AqualityPermissionsException("Account is not allowed to delete Customers", baseUser);
5252
}
5353
}
5454

5555
private List<CustomerDto> fillCustomers(List<CustomerDto> customers) throws AqualityException {
5656
List<UserDto> users = userDao.getAll();
57-
for (CustomerDto customer: customers){
57+
for (CustomerDto customer : customers) {
5858
customer.setCoordinator(users.stream().filter(x -> x.getId().equals(customer.getCoordinator_id())).findFirst().orElse(null));
5959
customer.getCoordinator().toPublic();
60-
if(baseUser.isCoordinator()){
60+
if (baseUser.isCoordinator()) {
6161
customer.setProjects(getProjects(customer));
6262
}
6363
}

src/main/java/main/controllers/Project/APITokenController.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
public class APITokenController extends BaseController<APITokenDto> {
1616
private APITokenDao apiTokenDao;
17+
1718
public APITokenController(UserDto user) {
1819
super(user);
1920
apiTokenDao = new APITokenDao();
@@ -26,14 +27,15 @@ public List<APITokenDto> get(APITokenDto entity) throws AqualityException {
2627

2728
@Override
2829
public APITokenDto create(APITokenDto template) throws AqualityException {
29-
if(baseUser.isAdmin() || baseUser.isManager() || baseUser.getProjectUser(template.getId()).isManager() || baseUser.getProjectUser(template.getId()).isAdmin()){
30+
if (baseUser.isAdmin() || baseUser.isManager() || baseUser.getProjectUser(template.getId()).isManager() || baseUser.getProjectUser(template.getId()).isAdmin()) {
3031
return apiTokenDao.create(template);
31-
}else{
32+
} else {
3233
throw new AqualityPermissionsException("Account is not allowed to create API Token", baseUser);
3334
}
3435
}
3536

36-
@Override @NotImplemented
37+
@Override
38+
@NotImplemented
3739
public boolean delete(APITokenDto entity) throws AqualityException {
3840
throw new UnsupportedOperationException();
3941
}
@@ -44,7 +46,7 @@ public boolean isTokenValid(String token, Integer projectId) throws AqualityExce
4446
tokenDTO.setId(projectId);
4547
List<APITokenDto> apiTokens = apiTokenDao.searchAll(tokenDTO);
4648

47-
if(apiTokens.size() > 0){
49+
if (apiTokens.size() > 0) {
4850
String expectedHash = (apiTokens.get(0)).getApi_token();
4951
return Objects.equals(actualHash, expectedHash);
5052
}

src/main/java/main/controllers/Project/BodyPatternController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,35 @@
1111

1212
public class BodyPatternController extends BaseController<BodyPatternDto> {
1313
private BodyPatternDao bodyPatternDao;
14+
1415
public BodyPatternController(UserDto user) {
1516
super(user);
1617
bodyPatternDao = new BodyPatternDao();
1718
}
1819

1920
@Override
2021
public BodyPatternDto create(BodyPatternDto template) throws AqualityException {
21-
if(baseUser.isAdmin() || baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isEditor()){
22+
if (baseUser.isAdmin() || baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isEditor()) {
2223
return bodyPatternDao.create(template);
23-
}else{
24+
} else {
2425
throw new AqualityPermissionsException("Account is not allowed to create Body Pattern", baseUser);
2526
}
2627
}
2728

2829
@Override
2930
public List<BodyPatternDto> get(BodyPatternDto template) throws AqualityException {
30-
if(baseUser.isAdmin() || baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isViewer()){
31+
if (baseUser.isAdmin() || baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isViewer()) {
3132
return bodyPatternDao.searchAll(template);
32-
}else{
33+
} else {
3334
throw new AqualityPermissionsException("Account is not allowed to view Body Patterns", baseUser);
3435
}
3536
}
3637

3738
@Override
3839
public boolean delete(BodyPatternDto template) throws AqualityException {
39-
if(baseUser.isAdmin() || baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isEditor()){
40+
if (baseUser.isAdmin() || baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isEditor()) {
4041
return bodyPatternDao.delete(template);
41-
}else{
42+
} else {
4243
throw new AqualityPermissionsException("Account is not allowed to delete Body Pattern", baseUser);
4344
}
4445
}

src/main/java/main/controllers/Project/FinalResultController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public FinalResultController(UserDto user) {
1919

2020
@Override
2121
public FinalResultDto create(FinalResultDto template) throws AqualityException {
22-
if(baseUser.isAdmin()){
22+
if (baseUser.isAdmin()) {
2323
return finalResultDao.create(template);
24-
}else{
24+
} else {
2525
throw new AqualityPermissionsException("Account is not allowed to create Final Result", baseUser);
2626
}
2727
}
@@ -33,9 +33,9 @@ public List<FinalResultDto> get(FinalResultDto template) throws AqualityExceptio
3333

3434
@Override
3535
public boolean delete(FinalResultDto template) throws AqualityException {
36-
if(baseUser.isAdmin()){
36+
if (baseUser.isAdmin()) {
3737
return finalResultDao.delete(template);
38-
}else{
38+
} else {
3939
throw new AqualityPermissionsException("Account is not allowed to delete Final Result", baseUser);
4040
}
4141
}

0 commit comments

Comments
 (0)