1 package org.argeo.connect; 2 3 import javax.jcr.Node; 4 import javax.jcr.RepositoryException; 5 import javax.jcr.Session; 6 7 /** Minimal interface that a Connect AppService must implement */ 8 public interface AppService { 9 // final static Log log = LogFactory.getLog(AppService.class); 10 11 /** Returns the current App name */ 12 public String getAppBaseName(); 13 14 public Node publishEntity(Node parent, String nodeType, Node srcNode, boolean removeSrcNode) 15 throws RepositoryException; 16 17 /** 18 * Try to save and optionally publish a business object after applying context 19 * specific rules and special behaviours (typically cache updates). 20 * 21 * @return the entity that has been saved (and optionally published): note that 22 * in some cases (typically, the first save of a draft node in the 23 * business sub tree) the returned node is not the same as the one that 24 * has been passed 25 * @param entity 26 * @param publish 27 * also publishes the corresponding node 28 * @throws PeopleException 29 * If one of the rule defined for this type is not respected. Use 30 * getMessage to display to the user if needed 31 */ 32 public Node saveEntity(Node entity, boolean publish); 33 34 /** 35 * Computes the App specific relative path for a known type based on properties 36 * of the passed node 37 */ 38 public String getDefaultRelPath(Node entity) throws RepositoryException; 39 40 /** 41 * Computes the App specific relative path for this known node type based on the 42 * passed id 43 * 44 * @param session 45 * TODO 46 */ 47 public String getDefaultRelPath(Session session, String nodeType, String id); 48 49 /** 50 * Returns a display name that is app specific and that depends on one or more 51 * of the entity properties. The user can always set a flag to force the value 52 * to something else. 53 * 54 * The Display name is usually stored in the JCR_TITLE property. 55 */ 56 public String getDisplayName(Node entity); 57 58 /** 59 * Returns (after creation if necessary) the base parent for draft nodes of this 60 * application 61 */ 62 public Node getDraftParent(Session session) throws RepositoryException; 63 64 /** 65 * Convenience method to create a Node with given mixin under the current logged 66 * in user home. Creates a UUID and set the connect:uid properties. The session 67 * is not saved. 68 */ 69 public Node createDraftEntity(Session session, String mainMixin) throws RepositoryException; 70 71 /** 72 * Simply checks if the passed entity has a primary or mixin type that is known 73 * and thus can be managed by the this App 74 */ 75 public boolean isKnownType(Node entity); 76 77 /** 78 * Simply checks if the passed type is known and thus can be managed by the this 79 * App. It might be a primary or mixin type 80 */ 81 public boolean isKnownType(String nodeType); 82 83 /** 84 * Searches the workspace corresponding to the passed session. It returns the 85 * corresponding entity or null if none has been found. This UID is 86 * implementation specific and is not a JCR Identifier. 87 * 88 * It will throw a PeopleException if more than one item with this ID has been 89 * found 90 * 91 * @param session 92 * @param parentPath 93 * can be null or empty 94 * @param uid 95 * the implementation specific UID of the searched entity 96 */ 97 public Node getEntityByUid(Session session, String parentPath, String uid); 98 99 // 100 // CANONICAL DEFAULTS 101 // 102 103 /** 104 * Returns the App specific main type of a node, that can be its primary type or 105 * one of its mixin, typically for the People App. 106 */ 107 default public String getMainNodeType(Node node) { 108 return null; 109 } 110 111 default public String getBaseRelPath(String nodeType) { 112 return getAppBaseName(); 113 } 114 115 default public Node publishEntity(Node parent, String nodeType, Node srcNode) throws RepositoryException { 116 return publishEntity(parent, nodeType, srcNode, true); 117 } 118 119 /** 120 * Draft implementation of an i18n mechanism to retrieve labels given a key 121 */ 122 default public String getLabel(String key, String... innerNames) { 123 return key; 124 } 125 126 }