1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.data.impl;
20
21 import java.util.Date;
22 import java.util.List;
23
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service;
26 import org.springframework.transaction.annotation.Propagation;
27 import org.springframework.transaction.annotation.Transactional;
28
29 import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration;
30 import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration_;
31 import com.hack23.cia.model.internal.application.system.impl.ConfigurationGroup;
32 import com.hack23.cia.service.data.api.ApplicationConfigurationDAO;
33 import com.hack23.cia.service.data.api.ApplicationConfigurationService;
34
35
36
37
38 @Service
39 @Transactional(propagation=Propagation.REQUIRES_NEW)
40 final class ApplicationConfigurationServiceImpl implements ApplicationConfigurationService {
41
42
43
44 @Autowired
45 private ApplicationConfigurationDAO applicationConfigurationDAO;
46
47
48
49
50 public ApplicationConfigurationServiceImpl() {
51 super();
52 }
53
54 @Override
55 public ApplicationConfiguration checkValueOrLoadDefault(final String configTitle, final String configDescription,
56 final ConfigurationGroup configurationGroup, final String component, final String componentTitle, final String componentDescription,
57 final String propertyId, final String propertyValue) {
58
59 final List<ApplicationConfiguration> findListByProperty = applicationConfigurationDAO.findListByProperty(new Object[]{component,configurationGroup,propertyId}, ApplicationConfiguration_.component,ApplicationConfiguration_.configurationGroup,ApplicationConfiguration_.propertyId);
60
61 if (findListByProperty.isEmpty()) {
62 final ApplicationConfiguration applicationConfiguration = new ApplicationConfiguration();
63 applicationConfiguration.setCreatedDate(new Date());
64 applicationConfiguration.setUpdatedDate(new Date());
65
66 applicationConfiguration.setConfigTitle(configTitle);
67 applicationConfiguration.setConfigDescription(configDescription);
68 applicationConfiguration.setConfigurationGroup(configurationGroup);
69
70 applicationConfiguration.setComponent(component);
71 applicationConfiguration.setComponentTitle(componentTitle);
72 applicationConfiguration.setComponentDescription(componentDescription);
73
74 applicationConfiguration.setPropertyId(propertyId);
75 applicationConfiguration.setPropertyValue(propertyValue);
76
77 applicationConfigurationDAO.persist(applicationConfiguration);
78
79 return applicationConfiguration;
80 } else {
81 return findListByProperty.get(0);
82 }
83
84 }
85
86 }