]> git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.suite.core/src/org/argeo/suite/core/DefaultSuiteAppService.java
Use latest connect snapshot
[gpl/argeo-suite.git] / org.argeo.suite.core / src / org / argeo / suite / core / DefaultSuiteAppService.java
1 package org.argeo.suite.core;
2
3 import java.util.List;
4
5 import javax.jcr.Node;
6 import javax.jcr.RepositoryException;
7 import javax.jcr.Session;
8
9 import org.argeo.connect.AppService;
10 import org.argeo.connect.SystemAppService;
11 import org.argeo.suite.SuiteConstants;
12 import org.argeo.suite.SuiteException;
13
14 public class DefaultSuiteAppService implements SystemAppService {
15
16 // Injected known AppWorkbenchServices: order is important, first found
17 // result will be returned by the various methods.
18 private List<AppService> knownAppServices;
19
20 @Override
21 public Node publishEntity(Node parent, String nodeType, Node srcNode, boolean removeSrcNode)
22 throws RepositoryException {
23 for (AppService appService : knownAppServices) {
24 if (appService.isKnownType(nodeType))
25 return appService.publishEntity(parent, nodeType, srcNode, removeSrcNode);
26 }
27 return null;
28 }
29
30 @Override
31 public String getAppBaseName() {
32 return SuiteConstants.SUITE_APP_BASE_NAME;
33 }
34
35 @Override
36 public String getBaseRelPath(String nodeType) {
37 for (AppService appService : knownAppServices) {
38 if (appService.isKnownType(nodeType))
39 return appService.getBaseRelPath(nodeType);
40 }
41 return null;
42 // return getAppBaseName();
43 }
44
45 @Override
46 public String getDefaultRelPath(Node entity) throws RepositoryException {
47 for (AppService appService : knownAppServices) {
48 if (appService.isKnownType(entity))
49 return appService.getDefaultRelPath(entity);
50 }
51 return null;
52 }
53
54 @Override
55 public String getDefaultRelPath(Session session, String nodetype, String id) {
56 for (AppService appService : knownAppServices) {
57 if (appService.isKnownType(nodetype))
58 return appService.getDefaultRelPath(session, nodetype, id);
59 }
60 return null;
61 }
62
63 /** Insures the correct service is called on save */
64 @Override
65 public Node saveEntity(Node entity, boolean publish) {
66 for (AppService appService : knownAppServices) {
67 if (appService.isKnownType(entity))
68 return appService.saveEntity(entity, publish);
69 }
70 throw new SuiteException("Unknown NodeType for " + entity + ". Cannot save");
71 // return AppService.super.saveEntity(entity, publish);
72 }
73
74 @Override
75 public boolean isKnownType(Node entity) {
76 for (AppService appService : knownAppServices) {
77 if (appService.isKnownType(entity))
78 return true;
79 }
80 return false;
81 }
82
83 @Override
84 public boolean isKnownType(String nodeType) {
85 for (AppService appService : knownAppServices) {
86 if (appService.isKnownType(nodeType))
87 return true;
88 }
89 return false;
90 }
91
92 public void setKnownAppServices(List<AppService> knownAppServices) {
93 this.knownAppServices = knownAppServices;
94 }
95
96 }