import org.splat.service.DocumentTypeService;
import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.SimulationContextTypeService;
+import org.springframework.context.ResourceLoaderAware;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
/**
* SIMAN workflow configuration data service.
*/
-public class ProjectSettingsServiceImpl implements ProjectSettingsService {
+public class ProjectSettingsServiceImpl implements ProjectSettingsService,
+ ResourceLoaderAware {
/**
* The logger for the service.
*/
private final static String TYPE_ATTR = "type";
+ /**
+ * Steps configuration storage.
+ */
+ private StepsConfigService _stepsConfigService;
+ /**
+ * Resource loader injected by Spring.
+ */
+ private ResourceLoader _resourceLoader;
+
+ /**
+ * Configuration resource injected by Spring.
+ */
+ private Resource _config;
+
// Non persistent configuration information
/**
* Repository settings.
* Pattern of the presentation of version numbers.
*/
private transient String _versioning;
- /**
- * Ordered list of (transient) study steps.
- */
- private transient final List<ProjectSettingsService.Step> _steps = new ArrayList<ProjectSettingsService.Step>();
/**
* Configuration document validation cycles.
*/
// ==============================================================================================================================
/**
- * Load workflow configuration from the given file. <br/> Create necessary default staff in the database if it is not initialized yet.
+ * Load workflow configuration from the file defined by config property. <BR>
+ * Create necessary default staff in the database if it is not initialized yet.
+ *
+ * @throws IOException
+ * if there is a file reading or index creation problem
+ * @throws SQLException
+ * if there is a database population problem
+ */
+ @Transactional
+ public void configure() throws IOException, SQLException {
+ if (getConfig() != null) {
+ configure("file:" + getConfig().getFile().getAbsolutePath());
+ }
+ }
+
+ /**
+ * Load workflow configuration from the given file. <BR>
+ * Create necessary default staff in the database if it is not initialized yet.
*
* @param filename
* the workflow configuration file
@Transactional
public void configure(final String filename) throws IOException,
SQLException {
- if (!_steps.isEmpty()) {
+ if (!getStepsConfigService().getSteps().isEmpty()) {
return; // Project already configured
}
Database base = getDatabase().getCheckedDB();
- File config = new File(filename);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Loading configuration from: "
+ + getResource(filename).getFile().getAbsolutePath());
+ LOG.info("Root: " + getResource("/").getURI());
+ }
+ File config = getResource(filename).getFile();
if (config.exists()) {
loadCustomization(config);
} else {
* @return the list of steps from project settings
*/
public List<ProjectSettingsService.Step> getAllSteps() {
- return _steps;
+ return getStepsConfigService().getSteps();
}
/**
*/
public ProjectSettingsService.Step getStep(final int number) {
ProjectSettingsService.Step res = null;
- for (int i = 0; i < _steps.size(); i++) {
- ProjectSettingsService.Step step = _steps.get(i);
+ for (int i = 0; i < getStepsConfigService().getSteps().size(); i++) {
+ ProjectSettingsService.Step step = getStepsConfigService()
+ .getSteps().get(i);
if (step.getNumber() == number) {
res = step;
break;
return res;
}
- /**
- * Get steps of the given project element (study or scenario).
- *
- * @param level
- * the project element (study or scenario)
- * @return the list of steps
- */
- public List<ProjectSettingsService.Step> getStepsOf(
- final Class<? extends ProjectElement> level) {
- List<ProjectSettingsService.Step> result = new ArrayList<ProjectSettingsService.Step>();
-
- for (int i = 0; i < _steps.size(); i++) {
- ProjectSettingsService.Step step = _steps.get(i);
- if (step.appliesTo(level)) {
- result.add(step);
- }
- }
- return result;
- }
-
/**
* Check if a file of the given format should be imported during check-out of a document of the given type.
*
step.setModule(module.getAttribute("name"));
}
- _steps.add(step);
+ getStepsConfigService().getSteps().add(step);
res += 1;
}
return res;
String uses = null;
for (Iterator<NamedNodeMap> i = _flows.iterator(); i.hasNext(); snum++) {
NamedNodeMap flow = i.next();
- ProjectSettingsService.Step step = _steps.get(snum);
+ ProjectSettingsService.Step step = getStepsConfigService()
+ .getSteps().get(snum);
String[] contents = flow.getNamedItem("contents").getNodeValue()
.split(",");
for (int j = 0; j < contents.length; j++) {
// Parse uses attribute
String[] usesArr = uses.split(",");
List<DocumentType> usesTypesList = new ArrayList<DocumentType>();
- for (String usesType: usesArr) {
+ for (String usesType : usesArr) {
tdoc = maptype.get(usesType.trim());
if (tdoc == null) {
LOG.warn("Undefined \"" + usesType.trim()
}
}
}
- tprop.setUses(usesTypesList.toArray(new DocumentType[]{}));
+ tprop.setUses(usesTypesList
+ .toArray(new DocumentType[] {}));
}
if (step != null) {
tprop.setResult(step);
String[] clist = clatr.getNamedItem("context").getNodeValue()
.split(",");
for (int j = 0; j < clist.length; j++) {
- mapstep.put(clist[j], _steps.get(snum));
+ mapstep.put(clist[j], getStepsConfigService().getSteps()
+ .get(snum));
}
}
}
final DocumentTypeService documentTypeService) {
_documentTypeService = documentTypeService;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader)
+ */
+ @Override
+ public void setResourceLoader(final ResourceLoader resourceLoader) {
+ this._resourceLoader = resourceLoader;
+ }
+
+ /**
+ * Get resource by means of Spring resource loader.
+ *
+ * @param location
+ * the resource location
+ * @return the resource
+ */
+ public Resource getResource(final String location) {
+ return _resourceLoader.getResource(location);
+ }
+
+ /**
+ * Get the config.
+ *
+ * @return the config
+ */
+ public Resource getConfig() {
+ return _config;
+ }
+
+ /**
+ * Set the config.
+ *
+ * @param config
+ * the config to set
+ */
+ public void setConfig(final Resource config) {
+ _config = config;
+ }
+
+ /**
+ * Get the stepsConfigService.
+ *
+ * @return the stepsConfigService
+ */
+ public StepsConfigService getStepsConfigService() {
+ return _stepsConfigService;
+ }
+
+ /**
+ * Set the stepsConfigService.
+ *
+ * @param stepsConfigService
+ * the stepsConfigService to set
+ */
+ public void setStepsConfigService(
+ final StepsConfigService stepsConfigService) {
+ _stepsConfigService = stepsConfigService;
+ }
}
\ No newline at end of file