}
+ boolean exists() {
+ try {
+ return provider.getJcrSession(session, jcrWorkspace).itemExists(jcrPath);
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot check whether " + jcrPath + " exists", e);
+ }
+ }
+
/*
* ADAPTERS
*/
import javax.jcr.Session;
import javax.xml.namespace.NamespaceContext;
+import org.argeo.api.acr.Content;
import org.argeo.api.acr.spi.ContentProvider;
import org.argeo.api.acr.spi.ProvidedContent;
import org.argeo.api.acr.spi.ProvidedSession;
}
@Override
- public ProvidedContent get(ProvidedSession contentSession, String mountPath, String relativePath) {
+ public ProvidedContent get(ProvidedSession contentSession, String relativePath) {
String jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
String jcrPath = "/" + relativePath;
return new JcrContent(contentSession, this, jcrWorkspace, jcrPath);
}
+ @Override
+ public boolean exists(ProvidedSession contentSession, String relativePath) {
+ String jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
+ String jcrPath = "/" + relativePath;
+ return new JcrContent(contentSession, this, jcrWorkspace, jcrPath).exists();
+ }
+
public Session getJcrSession(ProvidedSession contentSession, String jcrWorkspace) {
JcrSessionAdapter sessionAdapter = sessionAdapters.get(contentSession);
if (sessionAdapter == null) {
return jcrSession;
}
+ public Session getJcrSession(Content content, String jcrWorkspace) {
+ return getJcrSession(((ProvidedContent) content).getSession(), jcrWorkspace);
+ }
+
@Override
public String getMountPath() {
return mountPath;
import org.eclipse.swt.widgets.Control;
/** Stateless factory building an SWT user interface given a JCR context. */
-@FunctionalInterface
public interface CmsUiProvider extends SwtUiProvider {
/**
* Initialises a user interface.
* @param parent the parent composite
* @param context a context node (holding the JCR underlying session), or null
*/
- Control createUi(Composite parent, Node context) throws RepositoryException;
+ default Control createUi(Composite parent, Node context) throws RepositoryException {
+ // does nothing by default
+ return null;
+ }
default Control createUiPart(Composite parent, Node context) {
try {
Node node = ((JcrContent) context).getJcrNode();
return createUiPart(parent, node);
} else {
- throw new IllegalArgumentException("Content " + context + " is not compatible with JCR");
+// CmsLog.getLog(CmsUiProvider.class)
+// .warn("In " + getClass() + ", content " + context + " is not compatible with JCR.");
+// return createUiPart(parent, (Node) null);
+
+ throw new IllegalArgumentException(
+ "In " + getClass() + ", content " + context + " is not compatible with JCR");
}
}
Locale getLocale();
Content get(String path);
+
+ boolean exists(String path);
CompletionStage<ContentSession> edit(Consumer<ContentSession> work);
}
public interface ContentProvider extends NamespaceContext {
- ProvidedContent get(ProvidedSession session, String mountPath, String relativePath);
+ ProvidedContent get(ProvidedSession session, String relativePath);
+
+ boolean exists(ProvidedSession session, String relativePath);
String getMountPath();
package org.argeo.api.acr.spi;
import java.util.Iterator;
+import java.util.UUID;
import java.util.concurrent.CompletionStage;
import org.argeo.api.acr.Content;
void notifyModification(ProvidedContent content);
+ UUID getUuid();
+
+ Content getSessionRunDir();
+
/*
* NAMESPACE CONTEXT
*/
/** Get the CMS session of this subject. */
CmsSession getCmsSession(Subject subject);
+
+ CmsState getCmsState();
}
package org.argeo.api.cms;
+import java.util.UUID;
+
/** A running node process. */
public interface CmsState {
String getHostname();
Long getAvailableSince();
+ UUID getUuid();
}
</service>
<reference bind="setCmsState" cardinality="1..1" interface="org.argeo.api.cms.CmsState" name="CmsState" policy="static"/>
<reference bind="setUserAdmin" cardinality="1..1" interface="org.osgi.service.useradmin.UserAdmin" name="UserAdmin" policy="static"/>
+ <reference bind="setUuidFactory" cardinality="1..1" interface="org.argeo.api.uuid.UuidFactory" name="UuidFactory" policy="static"/>
+ <reference bind="setContentRepository" cardinality="1..1" interface="org.argeo.api.acr.spi.ProvidedRepository" name="ProvidedRepository" policy="static"/>
</scr:component>
<service>
<provide interface="org.argeo.api.cms.CmsState"/>
</service>
+ <reference bind="setUuidFactory" cardinality="1..1" interface="org.argeo.api.uuid.UuidFactory" name="UuidFactory" policy="static"/>
</scr:component>
import org.argeo.api.acr.spi.ProvidedContent;
import org.argeo.api.acr.spi.ProvidedRepository;
import org.argeo.api.cms.CmsLog;
-import org.argeo.api.uuid.UuidFactory;
import org.argeo.cms.acr.xml.DomContentProvider;
import org.argeo.cms.acr.xml.DomUtils;
import org.w3c.dom.DOMException;
public abstract class AbstractContentRepository implements ProvidedRepository {
private final static CmsLog log = CmsLog.getLog(AbstractContentRepository.class);
- private UuidFactory uuidFactory;
-
private MountManager mountManager;
private TypesManager typesManager;
TypesManager getTypesManager() {
return typesManager;
}
-
- public void setUuidFactory(UuidFactory uuidFactory) {
- this.uuidFactory = uuidFactory;
- }
-
}
import org.argeo.api.acr.spi.ProvidedRepository;
import org.argeo.api.cms.CmsAuth;
import org.argeo.api.cms.CmsSession;
+import org.argeo.api.cms.CmsState;
+import org.argeo.api.uuid.UuidFactory;
import org.argeo.cms.auth.CurrentUser;
import org.argeo.cms.internal.runtime.CmsContextImpl;
* Multi-session {@link ProvidedRepository}, integrated with a CMS.
*/
public class CmsContentRepository extends AbstractContentRepository {
+ public final static String RUN_BASE = "/run";
private Map<CmsSession, CmsContentSession> userSessions = Collections.synchronizedMap(new HashMap<>());
+ private CmsState cmsState;
+ private UuidFactory uuidFactory;
+
/*
* REPOSITORY
*/
CmsSession cmsSession = CurrentUser.getCmsSession();
CmsContentSession contentSession = userSessions.get(cmsSession);
if (contentSession == null) {
- final CmsContentSession newContentSession = new CmsContentSession(this, cmsSession.getSubject(), locale);
+ final CmsContentSession newContentSession = new CmsContentSession(this, cmsSession.getUuid(),
+ cmsSession.getSubject(), locale);
cmsSession.addOnCloseCallback((c) -> {
newContentSession.close();
userSessions.remove(cmsSession);
throw new RuntimeException("Could not login as data admin", e1);
} finally {
}
- return new CmsContentSession(this, loginContext.getSubject(), Locale.getDefault());
+ return new CmsContentSession(this, getCmsState().getUuid(), loginContext.getSubject(),
+ Locale.getDefault());
+ }
+
+ protected CmsState getCmsState() {
+ return cmsState;
+ }
+
+ public void setCmsState(CmsState cmsState) {
+ this.cmsState = cmsState;
+ }
+
+ public void setUuidFactory(UuidFactory uuidFactory) {
+ this.uuidFactory = uuidFactory;
}
}
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Consumer;
import org.argeo.api.acr.Content;
import org.argeo.api.acr.ContentSession;
+import org.argeo.api.acr.CrName;
import org.argeo.api.acr.NamespaceUtils;
import org.argeo.api.acr.spi.ContentProvider;
import org.argeo.api.acr.spi.ProvidedContent;
class CmsContentSession implements ProvidedSession {
final private AbstractContentRepository contentRepository;
+ private final UUID uuid;
private Subject subject;
private Locale locale;
private Set<ContentProvider> modifiedProviders = new TreeSet<>();
- public CmsContentSession(AbstractContentRepository contentRepository, Subject subject, Locale locale) {
+ private Content sessionRunDir;
+
+ public CmsContentSession(AbstractContentRepository contentRepository, UUID uuid, Subject subject, Locale locale) {
this.contentRepository = contentRepository;
this.subject = subject;
this.locale = locale;
+ this.uuid = uuid;
+
}
public void close() {
closed.complete(this);
+
+ if (sessionRunDir != null)
+ sessionRunDir.remove();
}
@Override
public Content get(String path) {
ContentProvider contentProvider = contentRepository.getMountManager().findContentProvider(path);
String mountPath = contentProvider.getMountPath();
+ String relativePath = extractRelativePath(mountPath, path);
+ ProvidedContent content = contentProvider.get(CmsContentSession.this, relativePath);
+ return content;
+ }
+
+ @Override
+ public boolean exists(String path) {
+ ContentProvider contentProvider = contentRepository.getMountManager().findContentProvider(path);
+ String mountPath = contentProvider.getMountPath();
+ String relativePath = extractRelativePath(mountPath, path);
+ return contentProvider.exists(this, relativePath);
+ }
+
+ private String extractRelativePath(String mountPath, String path) {
String relativePath = path.substring(mountPath.length());
if (relativePath.length() > 0 && relativePath.charAt(0) == '/')
relativePath = relativePath.substring(1);
- ProvidedContent content = contentProvider.get(CmsContentSession.this, mountPath, relativePath);
- return content;
+ return relativePath;
}
@Override
modifiedProviders.add(contentProvider);
}
+ @Override
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ @Override
+ public Content getSessionRunDir() {
+ if (sessionRunDir == null) {
+ String runDirPath = CmsContentRepository.RUN_BASE + '/' + uuid.toString();
+ if (exists(runDirPath))
+ sessionRunDir = get(runDirPath);
+ else {
+ Content runDir = get(CmsContentRepository.RUN_BASE);
+ // TODO deal with no run dir available?
+ sessionRunDir = runDir.add(uuid.toString(), CrName.COLLECTION.get());
+ }
+ }
+ return sessionRunDir;
+ }
+
// @Override
// public String findNamespace(String prefix) {
// return prefixes.get(prefix);
import javax.xml.namespace.QName;
import org.argeo.api.acr.Content;
+import org.argeo.api.cms.CmsSession;
/** Utilities and routines around {@link Content}. */
public class ContentUtils {
import java.nio.file.Paths;
import java.util.Locale;
import java.util.Objects;
+import java.util.UUID;
import javax.security.auth.Subject;
import javax.security.auth.x500.X500Principal;
private final Subject subject;
private final Locale locale;
+ private UUID uuid;
+
// the single session
private CmsContentSession contentSession;
this.subject = subject;
this.locale = locale;
+
+ // TODO use an UUID factory
+ this.uuid = UUID.randomUUID();
}
@Override
initRootContentProvider(null);
if (contentSession != null)
throw new IllegalStateException("Repository is already started, stop it first.");
- contentSession = new CmsContentSession(this, subject, locale);
+ contentSession = new CmsContentSession(this, uuid, subject, locale);
}
@Override
@Override
protected CmsContentSession newSystemSession() {
- return new CmsContentSession(this, subject, Locale.getDefault());
+ return new CmsContentSession(this, uuid, subject, Locale.getDefault());
}
public static void main(String... args) {
QName[] classes = null;
ContentProvider contentProvider = session.getRepository().getMountContentProvider(fsContent,
false, classes);
- Content mountedContent = contentProvider.get(session, fsContent.getPath(), "");
+ Content mountedContent = contentProvider.get(session, "");
return mountedContent;
} else {
return (Content) fsContent;
if (session.getRepository().shouldMount(classes)) {
ContentProvider contentProvider = session.getRepository().getMountContentProvider(fsContent, true, classes);
- Content mountedContent = contentProvider.get(session, fsContent.getPath(), "");
+ Content mountedContent = contentProvider.get(session, "");
fsContent.put(CrName.MOUNT.get(), "true");
return mountedContent;
public FsContentProvider(String mountPath, Path rootPath) {
Objects.requireNonNull(mountPath);
Objects.requireNonNull(rootPath);
-
+
this.mountPath = mountPath;
this.rootPath = rootPath;
// FIXME make it more robust
}
@Override
- public ProvidedContent get(ProvidedSession session, String mountPath, String relativePath) {
+ public ProvidedContent get(ProvidedSession session, String relativePath) {
return new FsContent(session, this, rootPath.resolve(relativePath));
}
* NAMESPACE CONTEXT
*/
+ @Override
+ public boolean exists(ProvidedSession session, String relativePath) {
+ return Files.exists(rootPath.resolve(relativePath));
+ }
+
@Override
public String getNamespaceURI(String prefix) {
return NamespaceUtils.getNamespaceURI((p) -> prefixes.get(p), prefix);
// }
@Override
- public ProvidedContent get(ProvidedSession session, String mountPath, String relativePath) {
+ public ProvidedContent get(ProvidedSession session, String relativePath) {
if ("".equals(relativePath))
return new DomContent(session, this, document.getDocumentElement());
+
+ NodeList nodes = findContent(relativePath);
+ if (nodes.getLength() > 1)
+ throw new IllegalArgumentException("Multiple content found for " + relativePath + " under " + mountPath);
+ if (nodes.getLength() == 0)
+ throw new ContentNotFoundException("Path " + relativePath + " under " + mountPath + " was not found");
+ Element element = (Element) nodes.item(0);
+ return new DomContent(session, this, element);
+ }
+
+ protected NodeList findContent(String relativePath) {
if (relativePath.startsWith("/"))
throw new IllegalArgumentException("Relative path cannot start with /");
-
String xPathExpression = '/' + relativePath;
if ("/".equals(mountPath))
xPathExpression = "/cr:root" + xPathExpression;
try {
NodeList nodes = (NodeList) xPath.get().evaluate(xPathExpression, document, XPathConstants.NODESET);
- if (nodes.getLength() > 1)
- throw new IllegalArgumentException(
- "Multiple content found for " + relativePath + " under " + mountPath);
- if (nodes.getLength() == 0)
- throw new ContentNotFoundException("Path " + relativePath + " under " + mountPath + " was not found");
- Element element = (Element) nodes.item(0);
- return new DomContent(session, this, element);
+ return nodes;
} catch (XPathExpressionException e) {
throw new IllegalArgumentException("XPath expression " + xPathExpression + " cannot be evaluated", e);
}
+
+ }
+
+ @Override
+ public boolean exists(ProvidedSession session, String relativePath) {
+ if ("".equals(relativePath))
+ return true;
+ NodeList nodes = findContent(relativePath);
+ return nodes.getLength() != 0;
}
public void persist(ProvidedSession session) {
if (currentLocalSessionAnonymous) {
currentLocalSession.close();
// new CMS session
- cmsSession = new WebCmsSessionImpl(subject, authorization, locale, request);
+ UUID cmsSessionUuid = CmsContextImpl.getCmsContext().getUuidFactory().timeUUID();
+ cmsSession = new WebCmsSessionImpl(cmsSessionUuid, subject, authorization, locale, request);
CmsContextImpl.getCmsContext().registerCmsSession(cmsSession);
} else if (!authorization.getName().equals(currentLocalSession.getAuthorization().getName())) {
throw new IllegalStateException("Inconsistent user " + authorization.getName()
}
} else {
// new CMS session
- cmsSession = new WebCmsSessionImpl(subject, authorization, locale, request);
+ UUID cmsSessionUuid = CmsContextImpl.getCmsContext().getUuidFactory().timeUUID();
+ cmsSession = new WebCmsSessionImpl(cmsSessionUuid, subject, authorization, locale, request);
CmsContextImpl.getCmsContext().registerCmsSession(cmsSession);
}
} else {
CmsSessionImpl cmsSession = CmsContextImpl.getCmsContext().getCmsSessionByLocalId(SINGLE_USER_LOCAL_ID);
if (cmsSession == null) {
- cmsSession = new CmsSessionImpl(subject, authorization, locale, SINGLE_USER_LOCAL_ID);
+ UUID cmsSessionUuid = CmsContextImpl.getCmsContext().getUuidFactory().timeUUID();
+ cmsSession = new CmsSessionImpl(cmsSessionUuid, subject, authorization, locale, SINGLE_USER_LOCAL_ID);
CmsContextImpl.getCmsContext().registerCmsSession(cmsSession);
}
CmsSessionId nodeSessionId = new CmsSessionId(cmsSession.getUuid());
import java.security.PrivilegedAction;
import java.time.ZonedDateTime;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import org.argeo.api.cms.CmsSession;
import org.argeo.cms.internal.runtime.CmsContextImpl;
import org.argeo.cms.security.NodeSecurityUtils;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.useradmin.Authorization;
private List<Consumer<CmsSession>> onCloseCallbacks = Collections.synchronizedList(new ArrayList<>());
- public CmsSessionImpl(Subject initialSubject, Authorization authorization, Locale locale, String localSessionId) {
+ public CmsSessionImpl(UUID uuid, Subject initialSubject, Authorization authorization, Locale locale,
+ String localSessionId) {
+ Objects.requireNonNull(uuid);
+
this.creationTime = ZonedDateTime.now();
this.locale = locale;
this.accessControlContext = Subject.doAs(initialSubject, new PrivilegedAction<AccessControlContext>() {
this.userDn = NodeSecurityUtils.ROLE_ANONYMOUS_NAME;
this.anonymous = true;
}
- // TODO use time-based UUID?
- this.uuid = UUID.randomUUID();
- // register as service
-// Hashtable<String, String> props = new Hashtable<>();
-// props.put(CmsSession.USER_DN, userDn.toString());
-// props.put(CmsSession.SESSION_UUID, uuid.toString());
-// props.put(CmsSession.SESSION_LOCAL_ID, localSessionId);
-// serviceRegistration = bc.registerService(CmsSession.class, this, props);
+ this.uuid = uuid;
}
public void close() {
public String toString() {
return "CMS Session " + userDn + " localId=" + localSessionId + ", uuid=" + uuid;
}
-
-// public static CmsSessionImpl getByLocalId(String localId) {
-// Collection<ServiceReference<CmsSession>> sr;
-// try {
-// sr = bc.getServiceReferences(CmsSession.class, "(" + CmsSession.SESSION_LOCAL_ID + "=" + localId + ")");
-// } catch (InvalidSyntaxException e) {
-// throw new IllegalArgumentException("Cannot get CMS session for id " + localId, e);
-// }
-// ServiceReference<CmsSession> cmsSessionRef;
-// if (sr.size() == 1) {
-// cmsSessionRef = sr.iterator().next();
-// return (CmsSessionImpl) bc.getService(cmsSessionRef);
-// } else if (sr.size() == 0) {
-// return null;
-// } else
-// throw new IllegalStateException(sr.size() + " CMS sessions registered for " + localId);
-//
-// }
-//
-// public static CmsSessionImpl getByUuid(Object uuid) {
-// Collection<ServiceReference<CmsSession>> sr;
-// try {
-// sr = bc.getServiceReferences(CmsSession.class, "(" + CmsSession.SESSION_UUID + "=" + uuid + ")");
-// } catch (InvalidSyntaxException e) {
-// throw new IllegalArgumentException("Cannot get CMS session for uuid " + uuid, e);
-// }
-// ServiceReference<CmsSession> cmsSessionRef;
-// if (sr.size() == 1) {
-// cmsSessionRef = sr.iterator().next();
-// return (CmsSessionImpl) bc.getService(cmsSessionRef);
-// } else if (sr.size() == 0) {
-// return null;
-// } else
-// throw new IllegalStateException(sr.size() + " CMS sessions registered for " + uuid);
-//
-// }
-//
-// public static void closeInvalidSessions() {
-// Collection<ServiceReference<CmsSession>> srs;
-// try {
-// srs = bc.getServiceReferences(CmsSession.class, null);
-// for (ServiceReference<CmsSession> sr : srs) {
-// CmsSession cmsSession = bc.getService(sr);
-// if (!cmsSession.isValid()) {
-// ((CmsSessionImpl) cmsSession).close();
-// if (log.isDebugEnabled())
-// log.debug("Closed expired CMS session " + cmsSession);
-// }
-// }
-// } catch (InvalidSyntaxException e) {
-// throw new IllegalArgumentException("Cannot get CMS sessions", e);
-// }
-// }
}
package org.argeo.cms.internal.http;
import java.util.Locale;
+import java.util.UUID;
import javax.security.auth.Subject;
private static final long serialVersionUID = -5178883380637048025L;
private RemoteAuthSession httpSession;
- public WebCmsSessionImpl(Subject initialSubject, Authorization authorization, Locale locale,
+ public WebCmsSessionImpl(UUID uuid, Subject initialSubject, Authorization authorization, Locale locale,
RemoteAuthRequest request) {
- super(initialSubject, authorization, locale, request.getSession().getId());
+ super(uuid, initialSubject, authorization, locale, request.getSession().getId());
httpSession = request.getSession();
}
return false;
return httpSession.isValid();
}
-
-// public static CmsSessionImpl getCmsSession(RemoteAuthRequest request) {
-// return CmsSessionImpl.getByLocalId(request.getSession().getId());
-// }
}
import javax.security.auth.Subject;
+import org.argeo.api.acr.spi.ProvidedContent;
+import org.argeo.api.acr.spi.ProvidedRepository;
import org.argeo.api.cms.CmsConstants;
import org.argeo.api.cms.CmsContext;
import org.argeo.api.cms.CmsDeployment;
import org.argeo.api.cms.CmsSession;
import org.argeo.api.cms.CmsSessionId;
import org.argeo.api.cms.CmsState;
+import org.argeo.api.uuid.UuidFactory;
import org.argeo.cms.LocaleUtils;
import org.argeo.cms.internal.auth.CmsSessionImpl;
import org.ietf.jgss.GSSCredential;
private CmsState cmsState;
private CmsDeployment cmsDeployment;
private UserAdmin userAdmin;
+ private UuidFactory uuidFactory;
+ private ProvidedRepository contentRepository;
// i18n
private Locale defaultLocale;
this.userAdmin = userAdmin;
}
+ public UuidFactory getUuidFactory() {
+ return uuidFactory;
+ }
+
+ public void setUuidFactory(UuidFactory uuidFactory) {
+ this.uuidFactory = uuidFactory;
+ }
+
+ public ProvidedRepository getContentRepository() {
+ return contentRepository;
+ }
+
+ public void setContentRepository(ProvidedRepository contentRepository) {
+ this.contentRepository = contentRepository;
+ }
+
@Override
public Locale getDefaultLocale() {
return defaultLocale;
return availableSince != null;
}
+ @Override
+ public CmsState getCmsState() {
+ return cmsState;
+ }
+
/*
* STATIC
*/
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
+import java.util.UUID;
import javax.security.auth.login.Configuration;
import org.argeo.api.cms.CmsLog;
import org.argeo.api.cms.CmsState;
+import org.argeo.api.uuid.UuidFactory;
import org.argeo.cms.auth.ident.IdentClient;
-import org.osgi.framework.Constants;
/**
* Implementation of a {@link CmsState}, initialising the required services.
// REFERENCES
private Long availableSince;
- private String stateUuid;
+ private UUID uuid;
// private final boolean cleanState;
private String hostname;
+ private UuidFactory uuidFactory;
+
public void start() {
// Runtime.getRuntime().addShutdownHook(new CmsShutdown());
if (log.isTraceEnabled())
log.trace("CMS State started");
- this.stateUuid = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
+// String stateUuidStr = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
+// this.uuid = UUID.fromString(stateUuidStr);
+ this.uuid = uuidFactory.timeUUID();
// this.cleanState = stateUuid.equals(frameworkUuid);
try {
this.hostname = InetAddress.getLocalHost().getHostName();
if (log.isDebugEnabled())
// log.debug("## CMS starting... stateUuid=" + this.stateUuid + (cleanState ? "
// (clean state) " : " "));
- log.debug("## CMS starting... (" + stateUuid + ")");
+ log.debug("## CMS starting... (" + uuid + ")");
// initI18n();
// initServices();
public void stop() {
if (log.isDebugEnabled())
- log.debug("CMS stopping... (" + this.stateUuid + ")");
+ log.debug("CMS stopping... (" + this.uuid + ")");
long duration = ((System.currentTimeMillis() - availableSince) / 1000) / 60;
log.info("## ARGEO CMS STOPPED after " + (duration / 60) + "h " + (duration % 60) + "min uptime ##");
}
-
@Override
public Long getAvailableSince() {
return availableSince;
return hostname;
}
+ @Override
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ public void setUuidFactory(UuidFactory uuidFactory) {
+ this.uuidFactory = uuidFactory;
+ }
+
/*
* STATIC
*/
package org.argeo.cms.internal.runtime;
+import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import org.argeo.api.acr.spi.ContentProvider;
-import org.argeo.api.cms.CmsConstants;
-import org.argeo.api.cms.CmsState;
import org.argeo.cms.acr.CmsContentRepository;
import org.argeo.cms.acr.fs.FsContentProvider;
+import org.argeo.util.OS;
public class DeployedContentRepository extends CmsContentRepository {
private final static String ROOT_XML = "cr:root.xml";
- private CmsState cmsState;
@Override
public void start() {
- super.start();
- Path rootXml = KernelUtils.getOsgiInstancePath(ROOT_XML);
- initRootContentProvider(null);
+ try {
+ super.start();
+ Path rootXml = KernelUtils.getOsgiInstancePath(ROOT_XML);
+ initRootContentProvider(null);
// Path srvPath = KernelUtils.getOsgiInstancePath(CmsConstants.SRV_WORKSPACE);
// FsContentProvider srvContentProvider = new FsContentProvider("/" + CmsConstants.SRV_WORKSPACE, srvPath, false);
// addProvider(srvContentProvider);
+
+ Path runDirPath = KernelUtils.getOsgiInstancePath(CmsContentRepository.RUN_BASE);
+ Files.createDirectories(runDirPath);
+ FsContentProvider runContentProvider = new FsContentProvider(CmsContentRepository.RUN_BASE, runDirPath);
+ addProvider(runContentProvider);
+ } catch (IOException e) {
+ throw new IllegalStateException("Cannot start content repository", e);
+ }
}
@Override
public void removeContentProvider(ContentProvider provider, Map<String, Object> properties) {
}
- public void setCmsState(CmsState cmsState) {
- this.cmsState = cmsState;
- }
-
}
private CompletableFuture<Void> stopped = new CompletableFuture<Void>();
public void start() {
+ // UID factory
+ CmsUuidFactory uuidFactory = new CmsUuidFactory();
+ Component<CmsUuidFactory> uuidFactoryC = new Component.Builder<>(uuidFactory) //
+ .addType(UuidFactory.class) //
+ .build(register);
+
// CMS State
CmsStateImpl cmsState = new CmsStateImpl();
Component<CmsStateImpl> cmsStateC = new Component.Builder<>(cmsState) //
.addType(CmsState.class) //
.addActivation(cmsState::start) //
.addDeactivation(cmsState::stop) //
+ .addDependency(uuidFactoryC.getType(UuidFactory.class), cmsState::setUuidFactory, null) //
.build(register);
// Deployment Configuration
}, null) //
.build(register);
+ // Content Repository
+ DeployedContentRepository contentRepository = new DeployedContentRepository();
+ Component<DeployedContentRepository> contentRepositoryC = new Component.Builder<>(contentRepository) //
+ .addType(ProvidedRepository.class) //
+ .addType(ContentRepository.class) //
+ .addActivation(contentRepository::start) //
+ .addDeactivation(contentRepository::stop) //
+ .addDependency(cmsStateC.getType(CmsState.class), contentRepository::setCmsState, null) //
+ .addDependency(uuidFactoryC.getType(UuidFactory.class), contentRepository::setUuidFactory, null) //
+ .build(register);
+
// CMS Context
CmsContextImpl cmsContext = new CmsContextImpl();
Component<CmsContextImpl> cmsContextC = new Component.Builder<>(cmsContext) //
.addDependency(cmsStateC.getType(CmsState.class), cmsContext::setCmsState, null) //
.addDependency(cmsDeploymentC.getType(CmsDeployment.class), cmsContext::setCmsDeployment, null) //
.addDependency(userAdminC.getType(UserAdmin.class), cmsContext::setUserAdmin, null) //
+ .addDependency(uuidFactoryC.getType(UuidFactory.class), cmsContext::setUuidFactory, null) //
+ .addDependency(contentRepositoryC.getType(ProvidedRepository.class), cmsContext::setContentRepository,
+ null) //
.build(register);
assert cmsContextC.get() == cmsContext;
- // UID factory
- CmsUuidFactory uuidFactory = new CmsUuidFactory();
- Component<CmsUuidFactory> uuidFactoryC = new Component.Builder<>(uuidFactory) //
- .addType(UuidFactory.class) //
- .build(register);
-
- // Content Repository
- DeployedContentRepository contentRepository = new DeployedContentRepository();
- Component<DeployedContentRepository> contentRepositoryC = new Component.Builder<>(contentRepository) //
- .addType(ProvidedRepository.class) //
- .addType(ContentRepository.class) //
- .addActivation(contentRepository::start) //
- .addDeactivation(contentRepository::stop) //
- .addDependency(cmsStateC.getType(CmsState.class), contentRepository::setCmsState, null) //
- .addDependency(uuidFactoryC.getType(UuidFactory.class), contentRepository::setUuidFactory, null) //
- .build(register);
-
register.activate();
}