<groupId>org.argeo.tp.misc</groupId>
<artifactId>org.eclipse.jgit</artifactId>
</dependency>
-
-
- <!-- For target platform generation -->
- <dependency>
- <groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.unit</artifactId>
- <version>2.1.17-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<profiles>
<profile>
<version>2.1.17-SNAPSHOT</version>
</dependency>
+ <!-- OSGi Boot for platform generation only, as it could be used by regular
+ Java applications to launch an OSGi runtime. -->
+ <dependency>
+ <groupId>org.argeo.commons</groupId>
+ <artifactId>org.argeo.osgi.boot</artifactId>
+ <version>2.1.86-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
<!-- ALM Third Parties -->
<!-- <dependency> -->
<!-- <groupId>org.argeo.tp.apache.ant</groupId> -->
<!-- <artifactId>org.apache.ant.launch</artifactId> -->
<!-- </dependency> -->
-<!-- <dependency> -->
-<!-- <groupId>org.argeo.tp.sdk</groupId> -->
-<!-- <artifactId>biz.aQute.bndlib</artifactId> -->
-<!-- </dependency> -->
-<!-- <dependency> -->
-<!-- <groupId>org.argeo.tp.sdk</groupId> -->
-<!-- <artifactId>org.junit</artifactId> -->
-<!-- </dependency> -->
-<!-- <dependency> -->
-<!-- <groupId>org.argeo.tp.sdk</groupId> -->
-<!-- <artifactId>org.redline-rpm</artifactId> -->
-<!-- </dependency> -->
-<!-- <dependency> -->
-<!-- <groupId>org.argeo.tp.misc</groupId> -->
-<!-- <artifactId>com.googlecode.javaewah.JavaEWAH</artifactId> -->
-<!-- </dependency> -->
-<!-- <dependency> -->
-<!-- <groupId>org.argeo.tp.misc</groupId> -->
-<!-- <artifactId>org.eclipse.jgit</artifactId> -->
-<!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.sdk</groupId> -->
+ <!-- <artifactId>biz.aQute.bndlib</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.sdk</groupId> -->
+ <!-- <artifactId>org.junit</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.sdk</groupId> -->
+ <!-- <artifactId>org.redline-rpm</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.misc</groupId> -->
+ <!-- <artifactId>com.googlecode.javaewah.JavaEWAH</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.misc</groupId> -->
+ <!-- <artifactId>org.eclipse.jgit</artifactId> -->
+ <!-- </dependency> -->
</dependencies>
<profiles>
<profile>
<artifactId>org.argeo.slc.api</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.support</artifactId>
- <version>2.1.17-SNAPSHOT</version>
- </dependency>
<!-- CLI Agent -->
<!-- <dependency> -->
<!-- Spring-based Agent -->
<dependency>
<groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.core</artifactId>
+ <artifactId>org.argeo.slc.spring</artifactId>
+ <version>2.1.17-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.slc</groupId>
+ <artifactId>org.argeo.slc.support</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
<dependency>
<version>2.1.17-SNAPSHOT</version>
</dependency>
+ <!-- Not strictly Spring dependencies but used by the old approach -->
+ <dependency>
+ <groupId>org.argeo.tp.apache.ant</groupId>
+ <artifactId>org.apache.ant</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.tp.apache.ant</groupId>
+ <artifactId>org.apache.ant.launch</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.tp.javax</groupId>
+ <artifactId>javax.mail</artifactId>
+ </dependency>
+
<!-- Base Spring dependency -->
<dependency>
<groupId>org.argeo.tp.spring</groupId>
<!-- <groupId>org.argeo.tp.apache</groupId> -->
<!-- <artifactId>org.apache.tika.parser</artifactId> -->
<!-- </dependency> -->
- <dependency>
- <groupId>org.argeo.tp.bouncycastle</groupId>
- <artifactId>bcmail</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.bouncycastle</groupId>
- <artifactId>bcpg</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.apache.ant</groupId>
- <artifactId>org.apache.ant</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.apache.ant</groupId>
- <artifactId>org.apache.ant.launch</artifactId>
- </dependency>
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.bouncycastle</groupId> -->
+ <!-- <artifactId>bcmail</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.bouncycastle</groupId> -->
+ <!-- <artifactId>bcpg</artifactId> -->
+ <!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.argeo.tp.misc</groupId> -->
<!-- <artifactId>org.quartz-scheduler.quartz</artifactId> -->
<!-- <groupId>org.argeo.tp.misc</groupId> -->
<!-- <artifactId>org.quartz-scheduler.quartz.jobs</artifactId> -->
<!-- </dependency> -->
- <dependency>
- <groupId>org.argeo.tp.javax</groupId>
- <artifactId>javax.mail</artifactId>
- </dependency>
<!-- Base Spring dependency -->
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.beans</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.javax</groupId>
- <artifactId>javax.el</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.gemini</groupId>
- <artifactId>org.eclipse.gemini.blueprint.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.gemini</groupId>
- <artifactId>org.eclipse.gemini.blueprint.extender</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.gemini</groupId>
- <artifactId>org.eclipse.gemini.blueprint.io</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.misc</groupId>
- <artifactId>org.aspectj.weaver</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.misc</groupId>
- <artifactId>org.aopalliance</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.aop</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.context</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.expression</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.instrument</artifactId>
- </dependency>
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.beans</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.core</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.javax</groupId> -->
+ <!-- <artifactId>javax.el</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.gemini</groupId> -->
+ <!-- <artifactId>org.eclipse.gemini.blueprint.core</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.gemini</groupId> -->
+ <!-- <artifactId>org.eclipse.gemini.blueprint.extender</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.gemini</groupId> -->
+ <!-- <artifactId>org.eclipse.gemini.blueprint.io</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.misc</groupId> -->
+ <!-- <artifactId>org.aspectj.weaver</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.misc</groupId> -->
+ <!-- <artifactId>org.aopalliance</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.aop</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.context</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.expression</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.instrument</artifactId> -->
+ <!-- </dependency> -->
<!-- Spring -->
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.aspects</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.context.support</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.jdbc</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.tp.spring</groupId>
- <artifactId>org.springframework.tx</artifactId>
- </dependency>
+
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.aspects</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.context.support</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.jdbc</artifactId> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.argeo.tp.spring</groupId> -->
+ <!-- <artifactId>org.springframework.tx</artifactId> -->
+ <!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.argeo.tp.spring</groupId> -->
<!-- <artifactId>org.springframework.web</artifactId> -->
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.attachment;
+
+public interface Attachment {
+ public String getUuid();
+
+ public void setUuid(String uuid);
+
+ public String getName();
+
+ public String getContentType();
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.attachment;
+
+public interface AttachmentsEnabled {
+ public void addAttachment(Attachment attachment);
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.attachment;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public interface AttachmentsStorage {
+ public void retrieveAttachment(Attachment attachment,
+ OutputStream outputStream);
+
+ /** Does NOT close the provided input stream. */
+ public void storeAttachment(Attachment attachment, InputStream inputStream);
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.execution;
+
+import java.io.Serializable;
+
+/** Value to be used by an execution */
+public abstract class AbstractExecutionValue implements Serializable {
+ private static final long serialVersionUID = 1558444746120706961L;
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.execution;
+
+import java.io.Serializable;
+
+/** Canonical implementation of the execution spec attribute booleans. */
+public abstract class AbstractSpecAttribute implements ExecutionSpecAttribute,
+ Serializable {
+ private static final long serialVersionUID = 6494963738891709440L;
+ private Boolean isImmutable = false;
+ private Boolean isConstant = false;
+ private Boolean isHidden = false;
+
+ private String description;
+
+ /** Has to be set at instantiation */
+ public Boolean getIsImmutable() {
+ return isImmutable;
+ }
+
+ public void setIsImmutable(Boolean isImmutable) {
+ this.isImmutable = isImmutable;
+ }
+
+ /** Cannot be overridden at runtime */
+ public Boolean getIsConstant() {
+ return isConstant;
+ }
+
+ public void setIsConstant(Boolean isConstant) {
+ this.isConstant = isConstant;
+ }
+
+ /** Should not be shown to the end user */
+ public Boolean getIsHidden() {
+ return isHidden;
+ }
+
+ public void setIsHidden(Boolean isHidden) {
+ this.isHidden = isHidden;
+ }
+
+ /*
+ * DEPRECATED
+ */
+ /** @deprecated use {@link #getIsImmutable()} instead */
+ public Boolean getIsParameter() {
+ return isImmutable;
+ }
+
+ /** @deprecated use {@link #getIsConstant()} instead */
+ public Boolean getIsFrozen() {
+ return isConstant;
+ }
+
+ /** @deprecated use {@link #setIsImmutable(Boolean)} instead */
+ public void setIsParameter(Boolean isParameter) {
+ this.isImmutable = isParameter;
+ }
+
+ /** @deprecated use {@link #setIsConstant(Boolean)} instead */
+ public void setIsFrozen(Boolean isFrozen) {
+ this.isConstant = isFrozen;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.execution;
+
+import java.util.List;
+
+/** A spec attribute whose value is a reference to a full fledged object. */
+public class RefSpecAttribute extends AbstractSpecAttribute implements
+ Cloneable {
+ private static final long serialVersionUID = -3427797452955753574L;
+ private transient Class<?> targetClass = String.class;
+ /** Read only. */
+ private String targetClassName;
+ private transient Object value = null;
+
+ /** List to be chosen from */
+ private List<RefValueChoice> choices = null;
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ /** Default is {@link String} */
+ public Class<?> getTargetClass() {
+ return targetClass;
+ }
+
+ public void setTargetClass(Class<?> targetClass) {
+ this.targetClass = targetClass;
+ this.targetClassName = targetClass.getName();
+ }
+
+ public String getTargetClassName() {
+ return targetClassName;
+ }
+
+ /** @return can be null */
+ public List<RefValueChoice> getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List<RefValueChoice> choices) {
+ this.choices = choices;
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException {
+ RefSpecAttribute rsa = new RefSpecAttribute();
+ rsa.setTargetClass(targetClass);
+ rsa.setChoices(choices);
+ return rsa;
+ }
+
+ @Override
+ public String toString() {
+ return "Ref spec attribute [" + targetClass + "]"
+ + (value != null ? "=" + value : "");
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.execution;
+
+/** Reference value to be used by an execution */
+public class RefValue extends AbstractExecutionValue {
+ private static final long serialVersionUID = -8951231456757181687L;
+ private String ref;
+ private String type;
+
+ public RefValue() {
+ }
+
+ public RefValue(String ref) {
+ super();
+ this.ref = ref;
+ }
+
+ public String getRef() {
+ return ref;
+ }
+
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return "Ref Value [" + type + "=" + ref + "]";
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.execution;
+
+import java.io.Serializable;
+
+/** A choice of ref value to be shown to the end user. */
+public class RefValueChoice implements Serializable {
+ private static final long serialVersionUID = -1133645722307507774L;
+ private String name;
+ private String description;
+
+ public RefValueChoice() {
+ }
+
+ public RefValueChoice(String name, String description) {
+ this.name = name;
+ this.description = description;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.primitive;
+
+/** Abstraction of access to primitive values */
+public interface PrimitiveAccessor {
+ public final static String TYPE_STRING = "string";
+ /**
+ * As of Argeo 1, passwords are NOT stored encrypted, just hidden in the UI,
+ * but stored in plain text in JCR. Use keyring instead.
+ */
+ public final static String TYPE_PASSWORD = "password";
+ public final static String TYPE_INTEGER = "integer";
+ public final static String TYPE_LONG = "long";
+ public final static String TYPE_FLOAT = "float";
+ public final static String TYPE_DOUBLE = "double";
+ public final static String TYPE_BOOLEAN = "boolean";
+
+ public String getType();
+
+ public Object getValue();
+
+ public void setValue(Object value);
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.primitive;
+
+import org.argeo.slc.SlcException;
+import org.argeo.slc.execution.AbstractSpecAttribute;
+
+/**
+ * A spec attribute wrapping a primitive value.
+ *
+ * @see PrimitiveAccessor
+ */
+public class PrimitiveSpecAttribute extends AbstractSpecAttribute implements
+ PrimitiveAccessor {
+ private static final long serialVersionUID = -566676381839825483L;
+ private String type = "string";
+ private Object value = null;
+
+ public PrimitiveSpecAttribute() {
+ }
+
+ public PrimitiveSpecAttribute(String type, Object value) {
+ this.type = type;
+ this.value = value;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ // check whether type is recognized.
+ if (PrimitiveUtils.typeAsClass(type) == null)
+ throw new SlcException("Unrecognized type " + type);
+ this.type = type;
+
+ }
+
+ @Override
+ public String toString() {
+ return "Primitive spec attribute [" + type + "]"
+ + (value != null ? "=" + value : "");
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.primitive;
+
+/** Converts to and from primitive types. */
+public class PrimitiveUtils {
+ /**
+ * @deprecated Use {@link PrimitiveAccessor#TYPE_STRING} instead
+ */
+ public final static String TYPE_STRING = PrimitiveAccessor.TYPE_STRING;
+ /**
+ * @deprecated Use {@link PrimitiveAccessor#TYPE_INTEGER} instead
+ */
+ public final static String TYPE_INTEGER = PrimitiveAccessor.TYPE_INTEGER;
+ /**
+ * @deprecated Use {@link PrimitiveAccessor#TYPE_LONG} instead
+ */
+ public final static String TYPE_LONG = PrimitiveAccessor.TYPE_LONG;
+ /**
+ * @deprecated Use {@link PrimitiveAccessor#TYPE_FLOAT} instead
+ */
+ public final static String TYPE_FLOAT = PrimitiveAccessor.TYPE_FLOAT;
+ /**
+ * @deprecated Use {@link PrimitiveAccessor#TYPE_DOUBLE} instead
+ */
+ public final static String TYPE_DOUBLE = PrimitiveAccessor.TYPE_DOUBLE;
+ /**
+ * @deprecated Use {@link PrimitiveAccessor#TYPE_BOOLEAN} instead
+ */
+ public final static String TYPE_BOOLEAN = PrimitiveAccessor.TYPE_BOOLEAN;
+
+ private PrimitiveUtils() {
+
+ }
+
+ /** @return the class or null if the provided type is not a primitive */
+ public static Class<?> typeAsClass(String type) {
+ if (PrimitiveAccessor.TYPE_STRING.equals(type))
+ return String.class;
+ else if (PrimitiveAccessor.TYPE_PASSWORD.equals(type))
+ return char[].class;
+ else if (PrimitiveAccessor.TYPE_INTEGER.equals(type))
+ return Integer.class;
+ else if (PrimitiveAccessor.TYPE_LONG.equals(type))
+ return Long.class;
+ else if (PrimitiveAccessor.TYPE_FLOAT.equals(type))
+ return Float.class;
+ else if (PrimitiveAccessor.TYPE_DOUBLE.equals(type))
+ return Double.class;
+ else if (PrimitiveAccessor.TYPE_BOOLEAN.equals(type))
+ return Boolean.class;
+ else
+ return null;
+ }
+
+ /** @return the type or null if the provided class is not a primitive */
+ public static String classAsType(Class<?> clss) {
+ if (String.class.isAssignableFrom(clss))
+ return PrimitiveAccessor.TYPE_STRING;
+ else if (char[].class.isAssignableFrom(clss))
+ return PrimitiveAccessor.TYPE_PASSWORD;
+ else if (Integer.class.isAssignableFrom(clss))
+ return PrimitiveAccessor.TYPE_INTEGER;
+ else if (Long.class.isAssignableFrom(clss))
+ return PrimitiveAccessor.TYPE_LONG;
+ else if (Float.class.isAssignableFrom(clss))
+ return PrimitiveAccessor.TYPE_FLOAT;
+ else if (Double.class.isAssignableFrom(clss))
+ return PrimitiveAccessor.TYPE_DOUBLE;
+ else if (Boolean.class.isAssignableFrom(clss))
+ return PrimitiveAccessor.TYPE_BOOLEAN;
+ else
+ return null;
+ }
+
+ /** Parse string as an object. Passwords are returned as String.*/
+ public static Object convert(String type, String str) {
+ if (PrimitiveAccessor.TYPE_STRING.equals(type)) {
+ return str;
+ } else if (PrimitiveAccessor.TYPE_PASSWORD.equals(type)) {
+ return str;
+ } else if (PrimitiveAccessor.TYPE_INTEGER.equals(type)) {
+ return (Integer.parseInt(str));
+ } else if (PrimitiveAccessor.TYPE_LONG.equals(type)) {
+ return (Long.parseLong(str));
+ } else if (PrimitiveAccessor.TYPE_FLOAT.equals(type)) {
+ return (Float.parseFloat(str));
+ } else if (PrimitiveAccessor.TYPE_DOUBLE.equals(type)) {
+ return (Double.parseDouble(str));
+ } else if (PrimitiveAccessor.TYPE_BOOLEAN.equals(type)) {
+ return (Boolean.parseBoolean(str));
+ } else {
+ return str;
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.primitive;
+
+import org.argeo.slc.execution.AbstractExecutionValue;
+
+/** Primitive value to be used by an execution. */
+public class PrimitiveValue extends AbstractExecutionValue implements
+ PrimitiveAccessor {
+ private static final long serialVersionUID = 533414290998374166L;
+
+ private String type;
+
+ private Object value;
+
+ public PrimitiveValue() {
+ }
+
+ public PrimitiveValue(String type, Object value) {
+ super();
+ this.type = type;
+ this.value = value;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+}
<!-- SLC -->
<dependency>
<groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.core</artifactId>
+ <artifactId>org.argeo.slc.spring</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
import org.argeo.slc.SlcNames;
import org.argeo.slc.SlcTypes;
import org.argeo.slc.client.ui.SlcImages;
-import org.argeo.slc.core.execution.PrimitiveAccessor;
-import org.argeo.slc.core.execution.PrimitiveUtils;
+import org.argeo.slc.primitive.PrimitiveAccessor;
+import org.argeo.slc.primitive.PrimitiveUtils;
import org.argeo.slc.execution.ExecutionProcess;
import org.argeo.slc.jcr.SlcJcrUtils;
import org.eclipse.jface.viewers.CellEditor;
<!-- SLC -->
<dependency>
<groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.core</artifactId>
+ <artifactId>org.argeo.slc.jcr</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+/bin/
+/target/
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.slc.jcr</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+/MANIFEST.MF
--- /dev/null
+Import-Package: javax.jcr.nodetype,\
+*
\ No newline at end of file
--- /dev/null
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.argeo.slc</groupId>
+ <artifactId>argeo-slc</artifactId>
+ <version>2.1.17-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>org.argeo.slc.jcr</artifactId>
+ <name>SLC JCR implementations</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <!-- Commons -->
+ <dependency>
+ <groupId>org.argeo.commons</groupId>
+ <artifactId>org.argeo.enterprise</artifactId>
+ <version>${version.argeo-commons}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.commons</groupId>
+ <artifactId>org.argeo.node.api</artifactId>
+ <version>${version.argeo-commons}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.commons</groupId>
+ <artifactId>org.argeo.cms</artifactId>
+ <version>${version.argeo-commons}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.commons</groupId>
+ <artifactId>org.argeo.jcr</artifactId>
+ <version>${version.argeo-commons}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.commons</groupId>
+ <artifactId>org.argeo.util</artifactId>
+ <version>${version.argeo-commons}</version>
+ </dependency>
+
+ <!-- SLC -->
+ <dependency>
+ <groupId>org.argeo.slc</groupId>
+ <artifactId>org.argeo.slc.api</artifactId>
+ <version>2.1.17-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.jcr;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.SlcNames;
+
+/**
+ * Writes arbitrary metadata into a child node of a given node (or the node
+ * itself if metadata node name is set to null)
+ */
+public class JcrMetadataWriter implements Runnable {
+ private final static Log log = LogFactory.getLog(JcrMetadataWriter.class);
+
+ private Node baseNode;
+ private String metadataNodeName = SlcNames.SLC_METADATA;
+
+ private Map<String, String> metadata = new HashMap<String, String>();
+
+ public void run() {
+ try {
+ Node metadataNode;
+ if (metadataNodeName != null)
+ metadataNode = baseNode.hasNode(metadataNodeName) ? baseNode
+ .getNode(metadataNodeName) : baseNode
+ .addNode(metadataNodeName);
+ else
+ metadataNode = baseNode;
+
+ for (String key : metadata.keySet())
+ metadataNode.setProperty(key, metadata.get(key));
+
+ baseNode.getSession().save();
+
+ if (log.isDebugEnabled())
+ log.debug("Wrote " + metadata.size() + " metadata entries to "
+ + metadataNode);
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot write metadata to " + baseNode, e);
+ } finally {
+ JcrUtils.discardUnderlyingSessionQuietly(baseNode);
+ }
+
+ }
+
+ public void setBaseNode(Node baseNode) {
+ this.baseNode = baseNode;
+ }
+
+ public void setMetadataNodeName(String metadataNodeName) {
+ this.metadataNodeName = metadataNodeName;
+ }
+
+ public void setMetadata(Map<String, String> metadata) {
+ this.metadata = metadata;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.jcr;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.jcr.Credentials;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.SlcNames;
+import org.argeo.slc.SlcTypes;
+import org.argeo.slc.attachment.Attachment;
+import org.argeo.slc.attachment.AttachmentsEnabled;
+import org.argeo.slc.test.TestResult;
+import org.argeo.slc.test.TestResultPart;
+import org.argeo.slc.test.TestRun;
+import org.argeo.slc.test.TestStatus;
+
+/**
+ * {@link TestResult} wrapping a JCR node of type
+ * {@link SlcTypes#SLC_TEST_RESULT}.
+ */
+public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled {
+ private final static Log log = LogFactory.getLog(JcrTestResult.class);
+
+ /** Should only be set for an already existing result. */
+ private String uuid;
+ private Repository repository;
+ private Session session;
+ /**
+ * For testing purposes, best practice is to not set them explicitely but
+ * via other mechanisms such as JAAS or SPring Security.
+ */
+ private Credentials credentials = null;
+ private String resultType = SlcTypes.SLC_TEST_RESULT;
+
+ /** cached for performance purposes */
+ private String nodeIdentifier = null;
+
+ private Map<String, String> attributes = new HashMap<String, String>();
+
+ public void init() {
+ try {
+ session = repository.login(credentials);
+ if (uuid == null) {
+ // create new result
+ uuid = UUID.randomUUID().toString();
+ String path = SlcJcrUtils.createResultPath(session, uuid);
+ Node resultNode = JcrUtils.mkdirs(session, path, resultType);
+ resultNode.setProperty(SLC_UUID, uuid);
+ for (String attr : attributes.keySet()) {
+ String property = attr;
+ // compatibility with legacy applications
+ if ("testCase".equals(attr))
+ property = SLC_TEST_CASE;
+ else if ("testCaseType".equals(attr))
+ property = SLC_TEST_CASE_TYPE;
+ resultNode.setProperty(property, attributes.get(attr));
+ }
+ session.save();
+ if (log.isDebugEnabled())
+ log.debug("Created test result " + uuid);
+ }
+ } catch (Exception e) {
+ JcrUtils.discardQuietly(session);
+ throw new SlcException("Cannot initialize JCR result", e);
+ }
+ }
+
+ public void destroy() {
+ JcrUtils.logoutQuietly(session);
+ if (log.isTraceEnabled())
+ log.trace("Logged out session for result " + uuid);
+ }
+
+ public Node getNode() {
+ try {
+ Node resultNode;
+ if (nodeIdentifier != null) {
+ return session.getNodeByIdentifier(nodeIdentifier);
+ } else {
+ QueryManager qm = session.getWorkspace().getQueryManager();
+ Query q = qm.createQuery("select * from ["
+ + SlcTypes.SLC_TEST_RESULT + "] where [slc:uuid]='"
+ + uuid + "'", Query.JCR_SQL2);
+ resultNode = JcrUtils.querySingleNode(q);
+ if (resultNode != null)
+ nodeIdentifier = resultNode.getIdentifier();
+ }
+ return resultNode;
+ } catch (Exception e) {
+ throw new SlcException("Cannot get result node", e);
+ }
+ }
+
+ public void notifyTestRun(TestRun testRun) {
+ // TODO store meta data about the test running
+ // if (log.isDebugEnabled())
+ // log.debug("Running test "
+ // + testRun.getTestDefinition().getClass().getName() + "...");
+ }
+
+ public void addResultPart(TestResultPart testResultPart) {
+ Node node = getNode();
+
+ try {
+ // error : revert all unsaved changes on the resultNode to be sure
+ // it is in a consistant state
+ if (testResultPart.getExceptionMessage() != null)
+ JcrUtils.discardQuietly(node.getSession());
+ node.getSession().save();
+
+ // add the new result part, retrieving status information
+ Node resultPartNode = node.addNode(SlcNames.SLC_RESULT_PART,
+ SlcTypes.SLC_CHECK);
+ resultPartNode.setProperty(SLC_SUCCESS, testResultPart.getStatus()
+ .equals(TestStatus.PASSED));
+ if (testResultPart.getMessage() != null)
+ resultPartNode.setProperty(SLC_MESSAGE,
+ testResultPart.getMessage());
+ if (testResultPart.getStatus().equals(TestStatus.ERROR)) {
+ resultPartNode.setProperty(SLC_ERROR_MESSAGE,
+ (testResultPart.getExceptionMessage() == null) ? ""
+ : testResultPart.getExceptionMessage());
+ }
+
+ // helper update aggregate status node
+ Node mainStatus;
+ if (!node.hasNode(SLC_AGGREGATED_STATUS)) {
+
+ mainStatus = node.addNode(SLC_AGGREGATED_STATUS,
+ SlcTypes.SLC_CHECK);
+ mainStatus.setProperty(SLC_SUCCESS,
+ resultPartNode.getProperty(SLC_SUCCESS).getBoolean());
+ if (resultPartNode.hasProperty(SLC_MESSAGE))
+ mainStatus.setProperty(SLC_MESSAGE, resultPartNode
+ .getProperty(SLC_MESSAGE).getString());
+ if (resultPartNode.hasProperty(SLC_ERROR_MESSAGE))
+ mainStatus.setProperty(SLC_ERROR_MESSAGE, resultPartNode
+ .getProperty(SLC_ERROR_MESSAGE).getString());
+ } else {
+ mainStatus = node.getNode(SLC_AGGREGATED_STATUS);
+ if (mainStatus.hasProperty(SLC_ERROR_MESSAGE)) {
+ // main status already in error we do nothing
+ } else if (resultPartNode.hasProperty(SLC_ERROR_MESSAGE)) {
+ // main status was not in error and new result part is in
+ // error; we update main status
+ mainStatus.setProperty(SLC_SUCCESS, false);
+ mainStatus.setProperty(SLC_ERROR_MESSAGE, resultPartNode
+ .getProperty(SLC_ERROR_MESSAGE).getString());
+ if (resultPartNode.hasProperty(SLC_MESSAGE))
+ mainStatus.setProperty(SLC_MESSAGE, resultPartNode
+ .getProperty(SLC_MESSAGE).getString());
+ else
+ // remove old message to remain consistent
+ mainStatus.setProperty(SLC_MESSAGE, "");
+ } else if (!mainStatus.getProperty(SLC_SUCCESS).getBoolean()) {
+ // main status was already failed and new result part is not
+ // in error, we do nothing
+ } else if (!resultPartNode.getProperty(SLC_SUCCESS)
+ .getBoolean()) {
+ // new resultPart that is failed
+ mainStatus.setProperty(SLC_SUCCESS, false);
+ if (resultPartNode.hasProperty(SLC_MESSAGE))
+ mainStatus.setProperty(SLC_MESSAGE, resultPartNode
+ .getProperty(SLC_MESSAGE).getString());
+ else
+ // remove old message to remain consistent
+ mainStatus.setProperty(SLC_MESSAGE, "");
+ } else if (resultPartNode.hasProperty(SLC_MESSAGE)
+ && (!mainStatus.hasProperty(SLC_MESSAGE) || (""
+ .equals(mainStatus.getProperty(SLC_MESSAGE)
+ .getString().trim())))) {
+ mainStatus.setProperty(SLC_MESSAGE, resultPartNode
+ .getProperty(SLC_MESSAGE).getString());
+ }
+ }
+ JcrUtils.updateLastModified(node);
+ node.getSession().save();
+ } catch (Exception e) {
+ JcrUtils.discardUnderlyingSessionQuietly(node);
+ throw new SlcException("Cannot add ResultPart to node " + node, e);
+ }
+ }
+
+ public String getUuid() {
+ Node node = getNode();
+ try {
+ return node.getProperty(SLC_UUID).getString();
+ } catch (Exception e) {
+ throw new SlcException("Cannot get UUID from " + node, e);
+ }
+ }
+
+ /** JCR session is NOT logged out */
+ public void close() {
+ Node node = getNode();
+ try {
+ if (node.hasNode(SLC_COMPLETED))
+ return;
+ node.setProperty(SLC_COMPLETED, new GregorianCalendar());
+ JcrUtils.updateLastModified(node);
+ node.getSession().save();
+ } catch (Exception e) {
+ JcrUtils.discardUnderlyingSessionQuietly(node);
+ throw new SlcException("Cannot get close date from " + node, e);
+ }
+ }
+
+ public Date getCloseDate() {
+ Node node = getNode();
+ try {
+ if (!node.hasNode(SLC_COMPLETED))
+ return null;
+ return node.getProperty(SLC_COMPLETED).getDate().getTime();
+ } catch (Exception e) {
+ throw new SlcException("Cannot get close date from " + node, e);
+ }
+ }
+
+ public Map<String, String> getAttributes() {
+ Node node = getNode();
+ try {
+ Map<String, String> map = new HashMap<String, String>();
+ PropertyIterator pit = node.getProperties();
+ while (pit.hasNext()) {
+ Property p = pit.nextProperty();
+ if (!p.isMultiple())
+ map.put(p.getName(), p.getValue().getString());
+ }
+ return map;
+ } catch (Exception e) {
+ throw new SlcException("Cannot get close date from " + node, e);
+ }
+ }
+
+ public void addAttachment(Attachment attachment) {
+ // TODO implement it
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public void setRepository(Repository repository) {
+ this.repository = repository;
+ }
+
+ public void setResultType(String resultType) {
+ this.resultType = resultType;
+ }
+
+ public void setAttributes(Map<String, String> attributes) {
+ if (uuid != null)
+ throw new SlcException(
+ "Attributes cannot be set on an already initialized test result."
+ + " Update the related JCR node directly instead.");
+ this.attributes = attributes;
+ }
+
+ public void setCredentials(Credentials credentials) {
+ this.credentials = credentials;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.jcr;
+
+import org.argeo.slc.SlcNames;
+
+/** JCR related constants used across SLC */
+public interface SlcJcrConstants {
+ public final static String PROPERTY_PATH = "argeo.slc.jcr.path";
+
+ public final static String SLC_BASE_PATH = "/" + SlcNames.SLC_SYSTEM;
+ public final static String AGENTS_BASE_PATH = SLC_BASE_PATH + "/"
+ + SlcNames.SLC_AGENTS;
+ public final static String VM_AGENT_FACTORY_PATH = AGENTS_BASE_PATH + "/"
+ + SlcNames.SLC_VM;
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.jcr.JcrUtils;
+import org.argeo.node.NodeUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.SlcNames;
+import org.argeo.slc.SlcTypes;
+
+/**
+ * Utilities around the SLC JCR Result model. Note that it relies on fixed base
+ * paths (convention over configuration) for optimization purposes.
+ */
+public class SlcJcrResultUtils {
+
+ /**
+ * Returns the path to the current slc:result node
+ */
+ public static String getSlcResultsBasePath(Session session) {
+ try {
+ Node userHome = NodeUtils.getUserHome(session);
+ if (userHome == null)
+ throw new SlcException("No user home available for "
+ + session.getUserID());
+ return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
+ + SlcNames.SLC_RESULTS;
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while getting Slc Results Base Path.", re);
+ }
+ }
+
+ /**
+ * Returns the base node to store SlcResults. If it does not exists, it is
+ * created. If a node already exists at the given path with the wrong type,
+ * it throws an exception.
+ *
+ * @param session
+ * @return
+ */
+ public static Node getSlcResultsParentNode(Session session) {
+ try {
+ String absPath = getSlcResultsBasePath(session);
+ if (session.nodeExists(absPath)) {
+ Node currNode = session.getNode(absPath);
+ if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
+ return currNode;
+ else
+ throw new SlcException(
+ "A node already exists at this path : " + absPath
+ + " that has the wrong type. ");
+ } else {
+ Node slcResParNode = JcrUtils.mkdirs(session, absPath);
+ slcResParNode.setPrimaryType(NodeType.NT_UNSTRUCTURED);
+ session.save();
+ return slcResParNode;
+ }
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while creating slcResult root parent node.",
+ re);
+ }
+ }
+
+ /**
+ * Returns the path to the current Result UI specific node, depending the
+ * current user
+ */
+ public static String getMyResultsBasePath(Session session) {
+ try {
+ Node userHome = NodeUtils.getUserHome(session);
+ if (userHome == null)
+ throw new SlcException("No user home available for "
+ + session.getUserID());
+ return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
+ + SlcNames.SLC_MY_RESULTS;
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while getting Slc Results Base Path.", re);
+ }
+ }
+
+ /**
+ * Creates a new node with type SlcTypes.SLC_MY_RESULT_ROOT_FOLDER at the
+ * given absolute path. If a node already exists at the given path, returns
+ * that node if it has the correct type and throws an exception otherwise.
+ *
+ * @param session
+ * @return
+ */
+ public static Node getMyResultParentNode(Session session) {
+ try {
+ String absPath = getMyResultsBasePath(session);
+ if (session.nodeExists(absPath)) {
+ Node currNode = session.getNode(absPath);
+ if (currNode.isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER))
+ return currNode;
+ else
+ throw new SlcException(
+ "A node already exists at this path : " + absPath
+ + " that has the wrong type. ");
+ } else {
+ Node myResParNode = JcrUtils.mkdirs(session, absPath);
+ myResParNode.setPrimaryType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER);
+ session.save();
+ return myResParNode;
+ }
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while creating user MyResult base node.",
+ re);
+ }
+ }
+
+ /**
+ * Creates a new node with type SlcTypes.SLC_RESULT_FOLDER at the given
+ * absolute path. If a node already exists at the given path, returns that
+ * node if it has the correct type and throws an exception otherwise.
+ *
+ * @param session
+ * @param absPath
+ * @return
+ */
+ public static synchronized Node createResultFolderNode(Session session,
+ String absPath) {
+ try {
+ if (session.nodeExists(absPath)) {
+ // Sanity check
+ Node currNode = session.getNode(absPath);
+ if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER))
+ return currNode;
+ else
+ throw new SlcException(
+ "A node already exists at this path : " + absPath
+ + " that has the wrong type. ");
+ }
+ Node rfNode = JcrUtils.mkdirs(session, absPath);
+ rfNode.setPrimaryType(SlcTypes.SLC_RESULT_FOLDER);
+ Node statusNode = rfNode.addNode(SlcNames.SLC_AGGREGATED_STATUS,
+ SlcTypes.SLC_CHECK);
+ statusNode.setProperty(SlcNames.SLC_SUCCESS, true);
+ session.save();
+ return rfNode;
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while creating Result Folder node.", re);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.jcr;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.jcr.JcrUtils;
+import org.argeo.node.NodeUtils;
+import org.argeo.slc.DefaultNameVersion;
+import org.argeo.slc.NameVersion;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.SlcNames;
+import org.argeo.slc.SlcTypes;
+import org.argeo.slc.deploy.ModuleDescriptor;
+import org.argeo.slc.primitive.PrimitiveAccessor;
+import org.argeo.slc.primitive.PrimitiveUtils;
+import org.argeo.slc.test.TestStatus;
+
+/**
+ * Utilities around the SLC JCR model. Note that it relies on fixed base paths
+ * (convention over configuration) for optimization purposes.
+ */
+public class SlcJcrUtils implements SlcNames {
+ public final static Integer AGENT_FACTORY_DEPTH = 3;
+
+ /** Extracts the path of a flow relative to its execution module */
+ public static String flowRelativePath(String fullFlowPath) {
+ String[] tokens = fullFlowPath.split("/");
+ StringBuffer buf = new StringBuffer(fullFlowPath.length());
+ for (int i = AGENT_FACTORY_DEPTH + 3; i < tokens.length; i++) {
+ buf.append('/').append(tokens[i]);
+ }
+ return buf.toString();
+ }
+
+ /** Extracts the path to the related execution module */
+ public static String modulePath(String fullFlowPath) {
+ String[] tokens = fullFlowPath.split("/");
+ StringBuffer buf = new StringBuffer(fullFlowPath.length());
+ for (int i = 0; i < AGENT_FACTORY_DEPTH + 3; i++) {
+ if (!tokens[i].equals(""))
+ buf.append('/').append(tokens[i]);
+ }
+ return buf.toString();
+ }
+
+ /** Extracts the module name from a flow path */
+ public static String moduleName(String fullFlowPath) {
+ String[] tokens = fullFlowPath.split("/");
+ String moduleName = tokens[AGENT_FACTORY_DEPTH + 2];
+ moduleName = moduleName.substring(0, moduleName.indexOf('_'));
+ return moduleName;
+ }
+
+ /** Extracts the module name and version from a flow path */
+ public static NameVersion moduleNameVersion(String fullFlowPath) {
+ String[] tokens = fullFlowPath.split("/");
+ String module = tokens[AGENT_FACTORY_DEPTH + 2];
+ String moduleName = module.substring(0, module.indexOf('_'));
+ String moduleVersion = module.substring(module.indexOf('_') + 1);
+ return new DefaultNameVersion(moduleName, moduleVersion);
+ }
+
+ /** Module node name based on module name and version */
+ public static String getModuleNodeName(ModuleDescriptor moduleDescriptor) {
+ return moduleDescriptor.getName() + "_" + moduleDescriptor.getVersion();
+ }
+
+ /** Extracts the agent factory of a flow */
+ public static String flowAgentFactoryPath(String fullFlowPath) {
+ String[] tokens = fullFlowPath.split("/");
+ StringBuffer buf = new StringBuffer(fullFlowPath.length());
+ // first token is always empty
+ for (int i = 1; i < AGENT_FACTORY_DEPTH + 1; i++) {
+ buf.append('/').append(tokens[i]);
+ }
+ return buf.toString();
+ }
+
+ /** Create a new execution process path based on the current time */
+ public static String createExecutionProcessPath(Session session, String uuid) {
+ Calendar now = new GregorianCalendar();
+ return getSlcProcessesBasePath(session) + '/'
+ + JcrUtils.dateAsPath(now, true) + uuid;
+ }
+
+ /** Get the base for the user processi. */
+ public static String getSlcProcessesBasePath(Session session) {
+ try {
+ Node userHome = NodeUtils.getUserHome(session);
+ if (userHome == null)
+ throw new SlcException("No user home available for "
+ + session.getUserID());
+ return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
+ + SlcNames.SLC_PROCESSES;
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while getting Slc Results Base Path.", re);
+ }
+ }
+
+ /**
+ * Create a new execution result path in the user home based on the current
+ * time
+ */
+ public static String createResultPath(Session session, String uuid)
+ throws RepositoryException {
+ Calendar now = new GregorianCalendar();
+ StringBuffer absPath = new StringBuffer(
+ SlcJcrResultUtils.getSlcResultsBasePath(session) + '/');
+ // Remove hours and add title property to the result process path on
+ // request of O. Capillon
+ // return getSlcProcessesBasePath(session) + '/'
+ // + JcrUtils.dateAsPath(now, true) + uuid;
+ String relPath = JcrUtils.dateAsPath(now, false);
+ List<String> names = JcrUtils.tokenize(relPath);
+ for (String name : names) {
+ absPath.append(name + "/");
+ Node node = JcrUtils.mkdirs(session, absPath.toString());
+ try {
+ node.addMixin(NodeType.MIX_TITLE);
+ node.setProperty(Property.JCR_TITLE, name.substring(1));
+ } catch (RepositoryException e) {
+ throw new SlcException(
+ "unable to create execution process path", e);
+ }
+ }
+ return absPath.toString() + uuid;
+ }
+
+ /**
+ * Set the value of the primitive accessor as a JCR property. Does nothing
+ * if the value is null.
+ */
+ public static void setPrimitiveAsProperty(Node node, String propertyName,
+ PrimitiveAccessor primitiveAccessor) {
+ String type = primitiveAccessor.getType();
+ Object value = primitiveAccessor.getValue();
+ setPrimitiveAsProperty(node, propertyName, type, value);
+ }
+
+ /** Map a primitive value to JCR property value. */
+ public static void setPrimitiveAsProperty(Node node, String propertyName,
+ String type, Object value) {
+ if (value == null)
+ return;
+ if (value instanceof CharSequence)
+ value = PrimitiveUtils.convert(type,
+ ((CharSequence) value).toString());
+ if (value instanceof char[])
+ value = new String((char[]) value);
+
+ try {
+ if (type.equals(PrimitiveAccessor.TYPE_STRING))
+ node.setProperty(propertyName, value.toString());
+ else if (type.equals(PrimitiveAccessor.TYPE_PASSWORD))
+ node.setProperty(propertyName, value.toString());
+ else if (type.equals(PrimitiveAccessor.TYPE_INTEGER))
+ node.setProperty(propertyName, (long) ((Integer) value));
+ else if (type.equals(PrimitiveAccessor.TYPE_LONG))
+ node.setProperty(propertyName, ((Long) value));
+ else if (type.equals(PrimitiveAccessor.TYPE_FLOAT))
+ node.setProperty(propertyName, (double) ((Float) value));
+ else if (type.equals(PrimitiveAccessor.TYPE_DOUBLE))
+ node.setProperty(propertyName, ((Double) value));
+ else if (type.equals(PrimitiveAccessor.TYPE_BOOLEAN))
+ node.setProperty(propertyName, ((Boolean) value));
+ else
+ throw new SlcException("Unsupported type " + type);
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot set primitive of " + type
+ + " as property " + propertyName + " on " + node, e);
+ }
+ }
+
+ /** Aggregates the {@link TestStatus} of this sub-tree. */
+ public static Integer aggregateTestStatus(Node node) {
+ try {
+ Integer status = TestStatus.PASSED;
+ if (node.isNodeType(SlcTypes.SLC_CHECK))
+ if (node.getProperty(SLC_SUCCESS).getBoolean())
+ status = TestStatus.PASSED;
+ else if (node.hasProperty(SLC_ERROR_MESSAGE))
+ status = TestStatus.ERROR;
+ else
+ status = TestStatus.FAILED;
+
+ NodeIterator it = node.getNodes();
+ while (it.hasNext()) {
+ Node curr = it.nextNode();
+
+ // Manually skip aggregated status
+ if (!SlcNames.SLC_AGGREGATED_STATUS.equals(curr.getName())) {
+ Integer childStatus = aggregateTestStatus(curr);
+ if (childStatus > status)
+ status = childStatus;
+ }
+ }
+ return status;
+ } catch (Exception e) {
+ throw new SlcException("Could not aggregate test status from "
+ + node, e);
+ }
+ }
+
+ /**
+ * Aggregates the {@link TestStatus} of this sub-tree.
+ *
+ * @return the same {@link StringBuffer}, for convenience (typically calling
+ * toString() on it)
+ */
+ public static StringBuffer aggregateTestMessages(Node node,
+ StringBuffer messages) {
+ try {
+ if (node.isNodeType(SlcTypes.SLC_CHECK)) {
+ if (node.hasProperty(SLC_MESSAGE)) {
+ if (messages.length() > 0)
+ messages.append('\n');
+ messages.append(node.getProperty(SLC_MESSAGE).getString());
+ }
+ if (node.hasProperty(SLC_ERROR_MESSAGE)) {
+ if (messages.length() > 0)
+ messages.append('\n');
+ messages.append(node.getProperty(SLC_ERROR_MESSAGE)
+ .getString());
+ }
+ }
+ NodeIterator it = node.getNodes();
+ while (it.hasNext()) {
+ Node child = it.nextNode();
+ // Manually skip aggregated status
+ if (!SlcNames.SLC_AGGREGATED_STATUS.equals(child.getName())) {
+ aggregateTestMessages(child, messages);
+ }
+ }
+ return messages;
+ } catch (Exception e) {
+ throw new SlcException("Could not aggregate test messages from "
+ + node, e);
+ }
+ }
+
+ /** Prevents instantiation */
+ private SlcJcrUtils() {
+ }
+}
\ No newline at end of file
<artifactId>org.argeo.slc.repo</artifactId>
<name>SLC Repo</name>
<dependencies>
- <!-- SLC Runtime -->
+ <!-- SLC API -->
<dependency>
<groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.support</artifactId>
+ <artifactId>org.argeo.slc.api</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.core</artifactId>
+ <artifactId>org.argeo.slc.spring</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
Import-Package: javax.jcr.nodetype,\
javax.jcr.security,\
+org.argeo.node,\
org.apache.tools.ant.*;resolution:="optional",\
junit.framework;resolution:="optional",\
org.osgi.*;version=0.0.0,\
<version>${version.argeo-commons}</version>
</dependency>
+ <!-- Commons -->
+ <dependency>
+ <groupId>org.argeo.commons</groupId>
+ <artifactId>org.argeo.osgi.boot</artifactId>
+ <version>${version.argeo-commons}</version>
+ <scope>provided</scope>
+ </dependency>
+
<!-- SLC -->
<dependency>
<groupId>org.argeo.slc</groupId>
<artifactId>org.argeo.slc.api</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.argeo.slc</groupId>
+ <artifactId>org.argeo.slc.jcr</artifactId>
+ <version>2.1.17-SNAPSHOT</version>
+ </dependency>
<!-- Spring -->
<dependency>
<groupId>org.argeo.tp.apache.ant</groupId>
<artifactId>org.apache.ant</artifactId>
</dependency>
-
</dependencies>
</project>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.attachment;
-
-public interface Attachment {
- public String getUuid();
-
- public void setUuid(String uuid);
-
- public String getName();
-
- public String getContentType();
-}
*/
package org.argeo.slc.core.attachment;
+import org.argeo.slc.attachment.Attachment;
import org.springframework.core.io.Resource;
public interface AttachmentUploader {
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.attachment;
-
-public interface AttachmentsEnabled {
- public void addAttachment(Attachment attachment);
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.attachment;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-
-public interface AttachmentsStorage {
- public void retrieveAttachment(Attachment attachment,
- OutputStream outputStream);
-
- /** Does NOT close the provided input stream. */
- public void storeAttachment(Attachment attachment, InputStream inputStream);
-}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.SlcException;
+import org.argeo.slc.attachment.Attachment;
+import org.argeo.slc.attachment.AttachmentsStorage;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import java.io.Serializable;
import java.util.UUID;
+import org.argeo.slc.attachment.Attachment;
+
public class SimpleAttachment implements Attachment, Serializable {
private static final long serialVersionUID = 6615155908800610606L;
private String uuid = UUID.randomUUID().toString();
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-import java.io.Serializable;
-
-/** Value to be used by an execution */
-public abstract class AbstractExecutionValue implements Serializable {
- private static final long serialVersionUID = 1558444746120706961L;
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-import java.io.Serializable;
-
-import org.argeo.slc.execution.ExecutionSpecAttribute;
-
-/** Canonical implementation of the execution spec attribute booleans. */
-public abstract class AbstractSpecAttribute implements ExecutionSpecAttribute,
- Serializable {
- private static final long serialVersionUID = 6494963738891709440L;
- private Boolean isImmutable = false;
- private Boolean isConstant = false;
- private Boolean isHidden = false;
-
- private String description;
-
- /** Has to be set at instantiation */
- public Boolean getIsImmutable() {
- return isImmutable;
- }
-
- public void setIsImmutable(Boolean isImmutable) {
- this.isImmutable = isImmutable;
- }
-
- /** Cannot be overridden at runtime */
- public Boolean getIsConstant() {
- return isConstant;
- }
-
- public void setIsConstant(Boolean isConstant) {
- this.isConstant = isConstant;
- }
-
- /** Should not be shown to the end user */
- public Boolean getIsHidden() {
- return isHidden;
- }
-
- public void setIsHidden(Boolean isHidden) {
- this.isHidden = isHidden;
- }
-
- /*
- * DEPRECATED
- */
- /** @deprecated use {@link #getIsImmutable()} instead */
- public Boolean getIsParameter() {
- return isImmutable;
- }
-
- /** @deprecated use {@link #getIsConstant()} instead */
- public Boolean getIsFrozen() {
- return isConstant;
- }
-
- /** @deprecated use {@link #setIsImmutable(Boolean)} instead */
- public void setIsParameter(Boolean isParameter) {
- this.isImmutable = isParameter;
- }
-
- /** @deprecated use {@link #setIsConstant(Boolean)} instead */
- public void setIsFrozen(Boolean isFrozen) {
- this.isConstant = isFrozen;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getDescription() {
- return description;
- }
-
-}
import org.argeo.slc.execution.ExecutionModuleDescriptor;
import org.argeo.slc.execution.ExecutionSpec;
import org.argeo.slc.execution.ExecutionSpecAttribute;
+import org.argeo.slc.execution.RefSpecAttribute;
+import org.argeo.slc.execution.RefValue;
+import org.argeo.slc.primitive.PrimitiveSpecAttribute;
+import org.argeo.slc.primitive.PrimitiveUtils;
+import org.argeo.slc.primitive.PrimitiveValue;
import org.springframework.aop.scope.ScopedObject;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.execution.ExecutionSpec;
import org.argeo.slc.execution.ExecutionSpecAttribute;
+import org.argeo.slc.execution.RefSpecAttribute;
+import org.argeo.slc.execution.RefValueChoice;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.argeo.slc.SlcException;\r
import org.argeo.slc.execution.ExecutionFlow;\r
import org.argeo.slc.execution.ExecutionSpecAttribute;\r
+import org.argeo.slc.execution.RefSpecAttribute;\r
+import org.argeo.slc.primitive.PrimitiveSpecAttribute;\r
+import org.argeo.slc.primitive.PrimitiveUtils;\r
\r
/** Manage parameters that need to be set during the instantiation of a flow */\r
public class InstantiationManager {\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-/** Abstraction of access to primitive values */
-public interface PrimitiveAccessor {
- public final static String TYPE_STRING = "string";
- /**
- * As of Argeo 1, passwords are NOT stored encrypted, just hidden in the UI,
- * but stored in plain text in JCR. Use keyring instead.
- */
- public final static String TYPE_PASSWORD = "password";
- public final static String TYPE_INTEGER = "integer";
- public final static String TYPE_LONG = "long";
- public final static String TYPE_FLOAT = "float";
- public final static String TYPE_DOUBLE = "double";
- public final static String TYPE_BOOLEAN = "boolean";
-
- public String getType();
-
- public Object getValue();
-
- public void setValue(Object value);
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-import org.argeo.slc.SlcException;
-
-/**
- * A spec attribute wrapping a primitive value.
- *
- * @see PrimitiveAccessor
- */
-public class PrimitiveSpecAttribute extends AbstractSpecAttribute implements
- PrimitiveAccessor {
- private static final long serialVersionUID = -566676381839825483L;
- private String type = "string";
- private Object value = null;
-
- public PrimitiveSpecAttribute() {
- }
-
- public PrimitiveSpecAttribute(String type, Object value) {
- this.type = type;
- this.value = value;
- }
-
- public Object getValue() {
- return value;
- }
-
- public void setValue(Object value) {
- this.value = value;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- // check whether type is recognized.
- if (PrimitiveUtils.typeAsClass(type) == null)
- throw new SlcException("Unrecognized type " + type);
- this.type = type;
-
- }
-
- @Override
- public String toString() {
- return "Primitive spec attribute [" + type + "]"
- + (value != null ? "=" + value : "");
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-/** Converts to and from primitive types. */
-public class PrimitiveUtils {
- /**
- * @deprecated Use {@link PrimitiveAccessor#TYPE_STRING} instead
- */
- public final static String TYPE_STRING = PrimitiveAccessor.TYPE_STRING;
- /**
- * @deprecated Use {@link PrimitiveAccessor#TYPE_INTEGER} instead
- */
- public final static String TYPE_INTEGER = PrimitiveAccessor.TYPE_INTEGER;
- /**
- * @deprecated Use {@link PrimitiveAccessor#TYPE_LONG} instead
- */
- public final static String TYPE_LONG = PrimitiveAccessor.TYPE_LONG;
- /**
- * @deprecated Use {@link PrimitiveAccessor#TYPE_FLOAT} instead
- */
- public final static String TYPE_FLOAT = PrimitiveAccessor.TYPE_FLOAT;
- /**
- * @deprecated Use {@link PrimitiveAccessor#TYPE_DOUBLE} instead
- */
- public final static String TYPE_DOUBLE = PrimitiveAccessor.TYPE_DOUBLE;
- /**
- * @deprecated Use {@link PrimitiveAccessor#TYPE_BOOLEAN} instead
- */
- public final static String TYPE_BOOLEAN = PrimitiveAccessor.TYPE_BOOLEAN;
-
- private PrimitiveUtils() {
-
- }
-
- /** @return the class or null if the provided type is not a primitive */
- public static Class<?> typeAsClass(String type) {
- if (PrimitiveAccessor.TYPE_STRING.equals(type))
- return String.class;
- else if (PrimitiveAccessor.TYPE_PASSWORD.equals(type))
- return char[].class;
- else if (PrimitiveAccessor.TYPE_INTEGER.equals(type))
- return Integer.class;
- else if (PrimitiveAccessor.TYPE_LONG.equals(type))
- return Long.class;
- else if (PrimitiveAccessor.TYPE_FLOAT.equals(type))
- return Float.class;
- else if (PrimitiveAccessor.TYPE_DOUBLE.equals(type))
- return Double.class;
- else if (PrimitiveAccessor.TYPE_BOOLEAN.equals(type))
- return Boolean.class;
- else
- return null;
- }
-
- /** @return the type or null if the provided class is not a primitive */
- public static String classAsType(Class<?> clss) {
- if (String.class.isAssignableFrom(clss))
- return PrimitiveAccessor.TYPE_STRING;
- else if (char[].class.isAssignableFrom(clss))
- return PrimitiveAccessor.TYPE_PASSWORD;
- else if (Integer.class.isAssignableFrom(clss))
- return PrimitiveAccessor.TYPE_INTEGER;
- else if (Long.class.isAssignableFrom(clss))
- return PrimitiveAccessor.TYPE_LONG;
- else if (Float.class.isAssignableFrom(clss))
- return PrimitiveAccessor.TYPE_FLOAT;
- else if (Double.class.isAssignableFrom(clss))
- return PrimitiveAccessor.TYPE_DOUBLE;
- else if (Boolean.class.isAssignableFrom(clss))
- return PrimitiveAccessor.TYPE_BOOLEAN;
- else
- return null;
- }
-
- /** Parse string as an object. Passwords are returned as String.*/
- public static Object convert(String type, String str) {
- if (PrimitiveAccessor.TYPE_STRING.equals(type)) {
- return str;
- } else if (PrimitiveAccessor.TYPE_PASSWORD.equals(type)) {
- return str;
- } else if (PrimitiveAccessor.TYPE_INTEGER.equals(type)) {
- return (Integer.parseInt(str));
- } else if (PrimitiveAccessor.TYPE_LONG.equals(type)) {
- return (Long.parseLong(str));
- } else if (PrimitiveAccessor.TYPE_FLOAT.equals(type)) {
- return (Float.parseFloat(str));
- } else if (PrimitiveAccessor.TYPE_DOUBLE.equals(type)) {
- return (Double.parseDouble(str));
- } else if (PrimitiveAccessor.TYPE_BOOLEAN.equals(type)) {
- return (Boolean.parseBoolean(str));
- } else {
- return str;
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-/** Primitive value to be used by an execution. */
-public class PrimitiveValue extends AbstractExecutionValue implements
- PrimitiveAccessor {
- private static final long serialVersionUID = 533414290998374166L;
-
- private String type;
-
- private Object value;
-
- public PrimitiveValue() {
- }
-
- public PrimitiveValue(String type, Object value) {
- super();
- this.type = type;
- this.value = value;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public Object getValue() {
- return value;
- }
-
- public void setValue(Object value) {
- this.value = value;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-import java.util.List;
-
-/** A spec attribute whose value is a reference to a full fledged object. */
-public class RefSpecAttribute extends AbstractSpecAttribute implements
- Cloneable {
- private static final long serialVersionUID = -3427797452955753574L;
- private transient Class<?> targetClass = String.class;
- /** Read only. */
- private String targetClassName;
- private transient Object value = null;
-
- /** List to be chosen from */
- private List<RefValueChoice> choices = null;
-
- public Object getValue() {
- return value;
- }
-
- public void setValue(Object value) {
- this.value = value;
- }
-
- /** Default is {@link String} */
- public Class<?> getTargetClass() {
- return targetClass;
- }
-
- public void setTargetClass(Class<?> targetClass) {
- this.targetClass = targetClass;
- this.targetClassName = targetClass.getName();
- }
-
- public String getTargetClassName() {
- return targetClassName;
- }
-
- /** @return can be null */
- public List<RefValueChoice> getChoices() {
- return choices;
- }
-
- public void setChoices(List<RefValueChoice> choices) {
- this.choices = choices;
- }
-
- @Override
- protected Object clone() throws CloneNotSupportedException {
- RefSpecAttribute rsa = new RefSpecAttribute();
- rsa.setTargetClass(targetClass);
- rsa.setChoices(choices);
- return rsa;
- }
-
- @Override
- public String toString() {
- return "Ref spec attribute [" + targetClass + "]"
- + (value != null ? "=" + value : "");
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-/** Reference value to be used by an execution */
-public class RefValue extends AbstractExecutionValue {
- private static final long serialVersionUID = -8951231456757181687L;
- private String ref;
- private String type;
-
- public RefValue() {
- }
-
- public RefValue(String ref) {
- super();
- this.ref = ref;
- }
-
- public String getRef() {
- return ref;
- }
-
- public void setRef(String ref) {
- this.ref = ref;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- @Override
- public String toString() {
- return "Ref Value [" + type + "=" + ref + "]";
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.core.execution;
-
-import java.io.Serializable;
-
-/** A choice of ref value to be shown to the end user. */
-public class RefValueChoice implements Serializable {
- private static final long serialVersionUID = -1133645722307507774L;
- private String name;
- private String description;
-
- public RefValueChoice() {
- }
-
- public RefValueChoice(String name, String description) {
- this.name = name;
- this.description = description;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
-}
import java.util.UUID;
import org.argeo.slc.SlcException;
-import org.argeo.slc.core.attachment.Attachment;
+import org.argeo.slc.attachment.Attachment;
+import org.argeo.slc.attachment.AttachmentsEnabled;
import org.argeo.slc.core.attachment.AttachmentUploader;
-import org.argeo.slc.core.attachment.AttachmentsEnabled;
import org.springframework.core.io.Resource;
public class UploadAttachments implements Runnable {
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.core.execution.DefaultExecutionSpec;
-import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
-import org.argeo.slc.core.execution.RefSpecAttribute;
-import org.argeo.slc.core.execution.RefValueChoice;
+import org.argeo.slc.execution.RefSpecAttribute;
+import org.argeo.slc.execution.RefValueChoice;
+import org.argeo.slc.primitive.PrimitiveSpecAttribute;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.SlcNames;
-
-/**
- * Writes arbitrary metadata into a child node of a given node (or the node
- * itself if metadata node name is set to null)
- */
-public class JcrMetadataWriter implements Runnable {
- private final static Log log = LogFactory.getLog(JcrMetadataWriter.class);
-
- private Node baseNode;
- private String metadataNodeName = SlcNames.SLC_METADATA;
-
- private Map<String, String> metadata = new HashMap<String, String>();
-
- public void run() {
- try {
- Node metadataNode;
- if (metadataNodeName != null)
- metadataNode = baseNode.hasNode(metadataNodeName) ? baseNode
- .getNode(metadataNodeName) : baseNode
- .addNode(metadataNodeName);
- else
- metadataNode = baseNode;
-
- for (String key : metadata.keySet())
- metadataNode.setProperty(key, metadata.get(key));
-
- baseNode.getSession().save();
-
- if (log.isDebugEnabled())
- log.debug("Wrote " + metadata.size() + " metadata entries to "
- + metadataNode);
- } catch (RepositoryException e) {
- throw new SlcException("Cannot write metadata to " + baseNode, e);
- } finally {
- JcrUtils.discardUnderlyingSessionQuietly(baseNode);
- }
-
- }
-
- public void setBaseNode(Node baseNode) {
- this.baseNode = baseNode;
- }
-
- public void setMetadataNodeName(String metadataNodeName) {
- this.metadataNodeName = metadataNodeName;
- }
-
- public void setMetadata(Map<String, String> metadata) {
- this.metadata = metadata;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr;
-
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.jcr.Credentials;
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.Repository;
-import javax.jcr.Session;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.SlcNames;
-import org.argeo.slc.SlcTypes;
-import org.argeo.slc.core.attachment.Attachment;
-import org.argeo.slc.core.attachment.AttachmentsEnabled;
-import org.argeo.slc.test.TestResult;
-import org.argeo.slc.test.TestResultPart;
-import org.argeo.slc.test.TestRun;
-import org.argeo.slc.test.TestStatus;
-
-/**
- * {@link TestResult} wrapping a JCR node of type
- * {@link SlcTypes#SLC_TEST_RESULT}.
- */
-public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled {
- private final static Log log = LogFactory.getLog(JcrTestResult.class);
-
- /** Should only be set for an already existing result. */
- private String uuid;
- private Repository repository;
- private Session session;
- /**
- * For testing purposes, best practice is to not set them explicitely but
- * via other mechanisms such as JAAS or SPring Security.
- */
- private Credentials credentials = null;
- private String resultType = SlcTypes.SLC_TEST_RESULT;
-
- /** cached for performance purposes */
- private String nodeIdentifier = null;
-
- private Map<String, String> attributes = new HashMap<String, String>();
-
- public void init() {
- try {
- session = repository.login(credentials);
- if (uuid == null) {
- // create new result
- uuid = UUID.randomUUID().toString();
- String path = SlcJcrUtils.createResultPath(session, uuid);
- Node resultNode = JcrUtils.mkdirs(session, path, resultType);
- resultNode.setProperty(SLC_UUID, uuid);
- for (String attr : attributes.keySet()) {
- String property = attr;
- // compatibility with legacy applications
- if ("testCase".equals(attr))
- property = SLC_TEST_CASE;
- else if ("testCaseType".equals(attr))
- property = SLC_TEST_CASE_TYPE;
- resultNode.setProperty(property, attributes.get(attr));
- }
- session.save();
- if (log.isDebugEnabled())
- log.debug("Created test result " + uuid);
- }
- } catch (Exception e) {
- JcrUtils.discardQuietly(session);
- throw new SlcException("Cannot initialize JCR result", e);
- }
- }
-
- public void destroy() {
- JcrUtils.logoutQuietly(session);
- if (log.isTraceEnabled())
- log.trace("Logged out session for result " + uuid);
- }
-
- public Node getNode() {
- try {
- Node resultNode;
- if (nodeIdentifier != null) {
- return session.getNodeByIdentifier(nodeIdentifier);
- } else {
- QueryManager qm = session.getWorkspace().getQueryManager();
- Query q = qm.createQuery("select * from ["
- + SlcTypes.SLC_TEST_RESULT + "] where [slc:uuid]='"
- + uuid + "'", Query.JCR_SQL2);
- resultNode = JcrUtils.querySingleNode(q);
- if (resultNode != null)
- nodeIdentifier = resultNode.getIdentifier();
- }
- return resultNode;
- } catch (Exception e) {
- throw new SlcException("Cannot get result node", e);
- }
- }
-
- public void notifyTestRun(TestRun testRun) {
- // TODO store meta data about the test running
- // if (log.isDebugEnabled())
- // log.debug("Running test "
- // + testRun.getTestDefinition().getClass().getName() + "...");
- }
-
- public void addResultPart(TestResultPart testResultPart) {
- Node node = getNode();
-
- try {
- // error : revert all unsaved changes on the resultNode to be sure
- // it is in a consistant state
- if (testResultPart.getExceptionMessage() != null)
- JcrUtils.discardQuietly(node.getSession());
- node.getSession().save();
-
- // add the new result part, retrieving status information
- Node resultPartNode = node.addNode(SlcNames.SLC_RESULT_PART,
- SlcTypes.SLC_CHECK);
- resultPartNode.setProperty(SLC_SUCCESS, testResultPart.getStatus()
- .equals(TestStatus.PASSED));
- if (testResultPart.getMessage() != null)
- resultPartNode.setProperty(SLC_MESSAGE,
- testResultPart.getMessage());
- if (testResultPart.getStatus().equals(TestStatus.ERROR)) {
- resultPartNode.setProperty(SLC_ERROR_MESSAGE,
- (testResultPart.getExceptionMessage() == null) ? ""
- : testResultPart.getExceptionMessage());
- }
-
- // helper update aggregate status node
- Node mainStatus;
- if (!node.hasNode(SLC_AGGREGATED_STATUS)) {
-
- mainStatus = node.addNode(SLC_AGGREGATED_STATUS,
- SlcTypes.SLC_CHECK);
- mainStatus.setProperty(SLC_SUCCESS,
- resultPartNode.getProperty(SLC_SUCCESS).getBoolean());
- if (resultPartNode.hasProperty(SLC_MESSAGE))
- mainStatus.setProperty(SLC_MESSAGE, resultPartNode
- .getProperty(SLC_MESSAGE).getString());
- if (resultPartNode.hasProperty(SLC_ERROR_MESSAGE))
- mainStatus.setProperty(SLC_ERROR_MESSAGE, resultPartNode
- .getProperty(SLC_ERROR_MESSAGE).getString());
- } else {
- mainStatus = node.getNode(SLC_AGGREGATED_STATUS);
- if (mainStatus.hasProperty(SLC_ERROR_MESSAGE)) {
- // main status already in error we do nothing
- } else if (resultPartNode.hasProperty(SLC_ERROR_MESSAGE)) {
- // main status was not in error and new result part is in
- // error; we update main status
- mainStatus.setProperty(SLC_SUCCESS, false);
- mainStatus.setProperty(SLC_ERROR_MESSAGE, resultPartNode
- .getProperty(SLC_ERROR_MESSAGE).getString());
- if (resultPartNode.hasProperty(SLC_MESSAGE))
- mainStatus.setProperty(SLC_MESSAGE, resultPartNode
- .getProperty(SLC_MESSAGE).getString());
- else
- // remove old message to remain consistent
- mainStatus.setProperty(SLC_MESSAGE, "");
- } else if (!mainStatus.getProperty(SLC_SUCCESS).getBoolean()) {
- // main status was already failed and new result part is not
- // in error, we do nothing
- } else if (!resultPartNode.getProperty(SLC_SUCCESS)
- .getBoolean()) {
- // new resultPart that is failed
- mainStatus.setProperty(SLC_SUCCESS, false);
- if (resultPartNode.hasProperty(SLC_MESSAGE))
- mainStatus.setProperty(SLC_MESSAGE, resultPartNode
- .getProperty(SLC_MESSAGE).getString());
- else
- // remove old message to remain consistent
- mainStatus.setProperty(SLC_MESSAGE, "");
- } else if (resultPartNode.hasProperty(SLC_MESSAGE)
- && (!mainStatus.hasProperty(SLC_MESSAGE) || (""
- .equals(mainStatus.getProperty(SLC_MESSAGE)
- .getString().trim())))) {
- mainStatus.setProperty(SLC_MESSAGE, resultPartNode
- .getProperty(SLC_MESSAGE).getString());
- }
- }
- JcrUtils.updateLastModified(node);
- node.getSession().save();
- } catch (Exception e) {
- JcrUtils.discardUnderlyingSessionQuietly(node);
- throw new SlcException("Cannot add ResultPart to node " + node, e);
- }
- }
-
- public String getUuid() {
- Node node = getNode();
- try {
- return node.getProperty(SLC_UUID).getString();
- } catch (Exception e) {
- throw new SlcException("Cannot get UUID from " + node, e);
- }
- }
-
- /** JCR session is NOT logged out */
- public void close() {
- Node node = getNode();
- try {
- if (node.hasNode(SLC_COMPLETED))
- return;
- node.setProperty(SLC_COMPLETED, new GregorianCalendar());
- JcrUtils.updateLastModified(node);
- node.getSession().save();
- } catch (Exception e) {
- JcrUtils.discardUnderlyingSessionQuietly(node);
- throw new SlcException("Cannot get close date from " + node, e);
- }
- }
-
- public Date getCloseDate() {
- Node node = getNode();
- try {
- if (!node.hasNode(SLC_COMPLETED))
- return null;
- return node.getProperty(SLC_COMPLETED).getDate().getTime();
- } catch (Exception e) {
- throw new SlcException("Cannot get close date from " + node, e);
- }
- }
-
- public Map<String, String> getAttributes() {
- Node node = getNode();
- try {
- Map<String, String> map = new HashMap<String, String>();
- PropertyIterator pit = node.getProperties();
- while (pit.hasNext()) {
- Property p = pit.nextProperty();
- if (!p.isMultiple())
- map.put(p.getName(), p.getValue().getString());
- }
- return map;
- } catch (Exception e) {
- throw new SlcException("Cannot get close date from " + node, e);
- }
- }
-
- public void addAttachment(Attachment attachment) {
- // TODO implement it
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- public void setRepository(Repository repository) {
- this.repository = repository;
- }
-
- public void setResultType(String resultType) {
- this.resultType = resultType;
- }
-
- public void setAttributes(Map<String, String> attributes) {
- if (uuid != null)
- throw new SlcException(
- "Attributes cannot be set on an already initialized test result."
- + " Update the related JCR node directly instead.");
- this.attributes = attributes;
- }
-
- public void setCredentials(Credentials credentials) {
- this.credentials = credentials;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr;
-
-import org.argeo.slc.SlcNames;
-
-/** JCR related constants used across SLC */
-public interface SlcJcrConstants {
- public final static String PROPERTY_PATH = "argeo.slc.jcr.path";
-
- public final static String SLC_BASE_PATH = "/" + SlcNames.SLC_SYSTEM;
- public final static String AGENTS_BASE_PATH = SLC_BASE_PATH + "/"
- + SlcNames.SLC_AGENTS;
- public final static String VM_AGENT_FACTORY_PATH = AGENTS_BASE_PATH + "/"
- + SlcNames.SLC_VM;
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
-
-import org.argeo.jcr.JcrUtils;
-import org.argeo.node.NodeUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.SlcNames;
-import org.argeo.slc.SlcTypes;
-
-/**
- * Utilities around the SLC JCR Result model. Note that it relies on fixed base
- * paths (convention over configuration) for optimization purposes.
- */
-public class SlcJcrResultUtils {
-
- /**
- * Returns the path to the current slc:result node
- */
- public static String getSlcResultsBasePath(Session session) {
- try {
- Node userHome = NodeUtils.getUserHome(session);
- if (userHome == null)
- throw new SlcException("No user home available for "
- + session.getUserID());
- return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
- + SlcNames.SLC_RESULTS;
- } catch (RepositoryException re) {
- throw new SlcException(
- "Unexpected error while getting Slc Results Base Path.", re);
- }
- }
-
- /**
- * Returns the base node to store SlcResults. If it does not exists, it is
- * created. If a node already exists at the given path with the wrong type,
- * it throws an exception.
- *
- * @param session
- * @return
- */
- public static Node getSlcResultsParentNode(Session session) {
- try {
- String absPath = getSlcResultsBasePath(session);
- if (session.nodeExists(absPath)) {
- Node currNode = session.getNode(absPath);
- if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
- return currNode;
- else
- throw new SlcException(
- "A node already exists at this path : " + absPath
- + " that has the wrong type. ");
- } else {
- Node slcResParNode = JcrUtils.mkdirs(session, absPath);
- slcResParNode.setPrimaryType(NodeType.NT_UNSTRUCTURED);
- session.save();
- return slcResParNode;
- }
- } catch (RepositoryException re) {
- throw new SlcException(
- "Unexpected error while creating slcResult root parent node.",
- re);
- }
- }
-
- /**
- * Returns the path to the current Result UI specific node, depending the
- * current user
- */
- public static String getMyResultsBasePath(Session session) {
- try {
- Node userHome = NodeUtils.getUserHome(session);
- if (userHome == null)
- throw new SlcException("No user home available for "
- + session.getUserID());
- return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
- + SlcNames.SLC_MY_RESULTS;
- } catch (RepositoryException re) {
- throw new SlcException(
- "Unexpected error while getting Slc Results Base Path.", re);
- }
- }
-
- /**
- * Creates a new node with type SlcTypes.SLC_MY_RESULT_ROOT_FOLDER at the
- * given absolute path. If a node already exists at the given path, returns
- * that node if it has the correct type and throws an exception otherwise.
- *
- * @param session
- * @return
- */
- public static Node getMyResultParentNode(Session session) {
- try {
- String absPath = getMyResultsBasePath(session);
- if (session.nodeExists(absPath)) {
- Node currNode = session.getNode(absPath);
- if (currNode.isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER))
- return currNode;
- else
- throw new SlcException(
- "A node already exists at this path : " + absPath
- + " that has the wrong type. ");
- } else {
- Node myResParNode = JcrUtils.mkdirs(session, absPath);
- myResParNode.setPrimaryType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER);
- session.save();
- return myResParNode;
- }
- } catch (RepositoryException re) {
- throw new SlcException(
- "Unexpected error while creating user MyResult base node.",
- re);
- }
- }
-
- /**
- * Creates a new node with type SlcTypes.SLC_RESULT_FOLDER at the given
- * absolute path. If a node already exists at the given path, returns that
- * node if it has the correct type and throws an exception otherwise.
- *
- * @param session
- * @param absPath
- * @return
- */
- public static synchronized Node createResultFolderNode(Session session,
- String absPath) {
- try {
- if (session.nodeExists(absPath)) {
- // Sanity check
- Node currNode = session.getNode(absPath);
- if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER))
- return currNode;
- else
- throw new SlcException(
- "A node already exists at this path : " + absPath
- + " that has the wrong type. ");
- }
- Node rfNode = JcrUtils.mkdirs(session, absPath);
- rfNode.setPrimaryType(SlcTypes.SLC_RESULT_FOLDER);
- Node statusNode = rfNode.addNode(SlcNames.SLC_AGGREGATED_STATUS,
- SlcTypes.SLC_CHECK);
- statusNode.setProperty(SlcNames.SLC_SUCCESS, true);
- session.save();
- return rfNode;
- } catch (RepositoryException re) {
- throw new SlcException(
- "Unexpected error while creating Result Folder node.", re);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.jcr;
-
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
-
-import org.argeo.jcr.JcrUtils;
-import org.argeo.node.NodeUtils;
-import org.argeo.slc.DefaultNameVersion;
-import org.argeo.slc.NameVersion;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.SlcNames;
-import org.argeo.slc.SlcTypes;
-import org.argeo.slc.core.execution.PrimitiveAccessor;
-import org.argeo.slc.core.execution.PrimitiveUtils;
-import org.argeo.slc.deploy.ModuleDescriptor;
-import org.argeo.slc.test.TestStatus;
-
-/**
- * Utilities around the SLC JCR model. Note that it relies on fixed base paths
- * (convention over configuration) for optimization purposes.
- */
-public class SlcJcrUtils implements SlcNames {
- public final static Integer AGENT_FACTORY_DEPTH = 3;
-
- /** Extracts the path of a flow relative to its execution module */
- public static String flowRelativePath(String fullFlowPath) {
- String[] tokens = fullFlowPath.split("/");
- StringBuffer buf = new StringBuffer(fullFlowPath.length());
- for (int i = AGENT_FACTORY_DEPTH + 3; i < tokens.length; i++) {
- buf.append('/').append(tokens[i]);
- }
- return buf.toString();
- }
-
- /** Extracts the path to the related execution module */
- public static String modulePath(String fullFlowPath) {
- String[] tokens = fullFlowPath.split("/");
- StringBuffer buf = new StringBuffer(fullFlowPath.length());
- for (int i = 0; i < AGENT_FACTORY_DEPTH + 3; i++) {
- if (!tokens[i].equals(""))
- buf.append('/').append(tokens[i]);
- }
- return buf.toString();
- }
-
- /** Extracts the module name from a flow path */
- public static String moduleName(String fullFlowPath) {
- String[] tokens = fullFlowPath.split("/");
- String moduleName = tokens[AGENT_FACTORY_DEPTH + 2];
- moduleName = moduleName.substring(0, moduleName.indexOf('_'));
- return moduleName;
- }
-
- /** Extracts the module name and version from a flow path */
- public static NameVersion moduleNameVersion(String fullFlowPath) {
- String[] tokens = fullFlowPath.split("/");
- String module = tokens[AGENT_FACTORY_DEPTH + 2];
- String moduleName = module.substring(0, module.indexOf('_'));
- String moduleVersion = module.substring(module.indexOf('_') + 1);
- return new DefaultNameVersion(moduleName, moduleVersion);
- }
-
- /** Module node name based on module name and version */
- public static String getModuleNodeName(ModuleDescriptor moduleDescriptor) {
- return moduleDescriptor.getName() + "_" + moduleDescriptor.getVersion();
- }
-
- /** Extracts the agent factory of a flow */
- public static String flowAgentFactoryPath(String fullFlowPath) {
- String[] tokens = fullFlowPath.split("/");
- StringBuffer buf = new StringBuffer(fullFlowPath.length());
- // first token is always empty
- for (int i = 1; i < AGENT_FACTORY_DEPTH + 1; i++) {
- buf.append('/').append(tokens[i]);
- }
- return buf.toString();
- }
-
- /** Create a new execution process path based on the current time */
- public static String createExecutionProcessPath(Session session, String uuid) {
- Calendar now = new GregorianCalendar();
- return getSlcProcessesBasePath(session) + '/'
- + JcrUtils.dateAsPath(now, true) + uuid;
- }
-
- /** Get the base for the user processi. */
- public static String getSlcProcessesBasePath(Session session) {
- try {
- Node userHome = NodeUtils.getUserHome(session);
- if (userHome == null)
- throw new SlcException("No user home available for "
- + session.getUserID());
- return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
- + SlcNames.SLC_PROCESSES;
- } catch (RepositoryException re) {
- throw new SlcException(
- "Unexpected error while getting Slc Results Base Path.", re);
- }
- }
-
- /**
- * Create a new execution result path in the user home based on the current
- * time
- */
- public static String createResultPath(Session session, String uuid)
- throws RepositoryException {
- Calendar now = new GregorianCalendar();
- StringBuffer absPath = new StringBuffer(
- SlcJcrResultUtils.getSlcResultsBasePath(session) + '/');
- // Remove hours and add title property to the result process path on
- // request of O. Capillon
- // return getSlcProcessesBasePath(session) + '/'
- // + JcrUtils.dateAsPath(now, true) + uuid;
- String relPath = JcrUtils.dateAsPath(now, false);
- List<String> names = JcrUtils.tokenize(relPath);
- for (String name : names) {
- absPath.append(name + "/");
- Node node = JcrUtils.mkdirs(session, absPath.toString());
- try {
- node.addMixin(NodeType.MIX_TITLE);
- node.setProperty(Property.JCR_TITLE, name.substring(1));
- } catch (RepositoryException e) {
- throw new SlcException(
- "unable to create execution process path", e);
- }
- }
- return absPath.toString() + uuid;
- }
-
- /**
- * Set the value of the primitive accessor as a JCR property. Does nothing
- * if the value is null.
- */
- public static void setPrimitiveAsProperty(Node node, String propertyName,
- PrimitiveAccessor primitiveAccessor) {
- String type = primitiveAccessor.getType();
- Object value = primitiveAccessor.getValue();
- setPrimitiveAsProperty(node, propertyName, type, value);
- }
-
- /** Map a primitive value to JCR property value. */
- public static void setPrimitiveAsProperty(Node node, String propertyName,
- String type, Object value) {
- if (value == null)
- return;
- if (value instanceof CharSequence)
- value = PrimitiveUtils.convert(type,
- ((CharSequence) value).toString());
- if (value instanceof char[])
- value = new String((char[]) value);
-
- try {
- if (type.equals(PrimitiveAccessor.TYPE_STRING))
- node.setProperty(propertyName, value.toString());
- else if (type.equals(PrimitiveAccessor.TYPE_PASSWORD))
- node.setProperty(propertyName, value.toString());
- else if (type.equals(PrimitiveAccessor.TYPE_INTEGER))
- node.setProperty(propertyName, (long) ((Integer) value));
- else if (type.equals(PrimitiveAccessor.TYPE_LONG))
- node.setProperty(propertyName, ((Long) value));
- else if (type.equals(PrimitiveAccessor.TYPE_FLOAT))
- node.setProperty(propertyName, (double) ((Float) value));
- else if (type.equals(PrimitiveAccessor.TYPE_DOUBLE))
- node.setProperty(propertyName, ((Double) value));
- else if (type.equals(PrimitiveAccessor.TYPE_BOOLEAN))
- node.setProperty(propertyName, ((Boolean) value));
- else
- throw new SlcException("Unsupported type " + type);
- } catch (RepositoryException e) {
- throw new SlcException("Cannot set primitive of " + type
- + " as property " + propertyName + " on " + node, e);
- }
- }
-
- /** Aggregates the {@link TestStatus} of this sub-tree. */
- public static Integer aggregateTestStatus(Node node) {
- try {
- Integer status = TestStatus.PASSED;
- if (node.isNodeType(SlcTypes.SLC_CHECK))
- if (node.getProperty(SLC_SUCCESS).getBoolean())
- status = TestStatus.PASSED;
- else if (node.hasProperty(SLC_ERROR_MESSAGE))
- status = TestStatus.ERROR;
- else
- status = TestStatus.FAILED;
-
- NodeIterator it = node.getNodes();
- while (it.hasNext()) {
- Node curr = it.nextNode();
-
- // Manually skip aggregated status
- if (!SlcNames.SLC_AGGREGATED_STATUS.equals(curr.getName())) {
- Integer childStatus = aggregateTestStatus(curr);
- if (childStatus > status)
- status = childStatus;
- }
- }
- return status;
- } catch (Exception e) {
- throw new SlcException("Could not aggregate test status from "
- + node, e);
- }
- }
-
- /**
- * Aggregates the {@link TestStatus} of this sub-tree.
- *
- * @return the same {@link StringBuffer}, for convenience (typically calling
- * toString() on it)
- */
- public static StringBuffer aggregateTestMessages(Node node,
- StringBuffer messages) {
- try {
- if (node.isNodeType(SlcTypes.SLC_CHECK)) {
- if (node.hasProperty(SLC_MESSAGE)) {
- if (messages.length() > 0)
- messages.append('\n');
- messages.append(node.getProperty(SLC_MESSAGE).getString());
- }
- if (node.hasProperty(SLC_ERROR_MESSAGE)) {
- if (messages.length() > 0)
- messages.append('\n');
- messages.append(node.getProperty(SLC_ERROR_MESSAGE)
- .getString());
- }
- }
- NodeIterator it = node.getNodes();
- while (it.hasNext()) {
- Node child = it.nextNode();
- // Manually skip aggregated status
- if (!SlcNames.SLC_AGGREGATED_STATUS.equals(child.getName())) {
- aggregateTestMessages(child, messages);
- }
- }
- return messages;
- } catch (Exception e) {
- throw new SlcException("Could not aggregate test messages from "
- + node, e);
- }
- }
-
- /** Prevents instantiation */
- private SlcJcrUtils() {
- }
-}
\ No newline at end of file
import javax.jcr.Session;
-import org.argeo.slc.core.attachment.Attachment;
+import org.argeo.slc.attachment.Attachment;
import org.argeo.slc.core.attachment.AttachmentUploader;
import org.springframework.core.io.Resource;
import org.argeo.slc.SlcException;
import org.argeo.slc.SlcNames;
import org.argeo.slc.SlcTypes;
-import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
-import org.argeo.slc.core.execution.PrimitiveValue;
-import org.argeo.slc.core.execution.RefSpecAttribute;
-import org.argeo.slc.core.execution.RefValueChoice;
import org.argeo.slc.deploy.ModuleDescriptor;
import org.argeo.slc.execution.ExecutionFlowDescriptor;
import org.argeo.slc.execution.ExecutionModuleDescriptor;
import org.argeo.slc.execution.ExecutionModulesManager;
import org.argeo.slc.execution.ExecutionSpec;
import org.argeo.slc.execution.ExecutionSpecAttribute;
+import org.argeo.slc.execution.RefSpecAttribute;
+import org.argeo.slc.execution.RefValueChoice;
import org.argeo.slc.jcr.SlcJcrUtils;
+import org.argeo.slc.primitive.PrimitiveSpecAttribute;
+import org.argeo.slc.primitive.PrimitiveValue;
/**
* Synchronizes the local execution runtime with a JCR repository. For the time
import org.argeo.slc.SlcNames;
import org.argeo.slc.SlcTypes;
import org.argeo.slc.core.execution.DefaultExecutionSpec;
-import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
-import org.argeo.slc.core.execution.PrimitiveUtils;
-import org.argeo.slc.core.execution.RefSpecAttribute;
import org.argeo.slc.execution.ExecutionFlowDescriptor;
import org.argeo.slc.execution.ExecutionSpecAttribute;
import org.argeo.slc.execution.RealizedFlow;
+import org.argeo.slc.execution.RefSpecAttribute;
import org.argeo.slc.jcr.SlcJcrUtils;
+import org.argeo.slc.primitive.PrimitiveSpecAttribute;
+import org.argeo.slc.primitive.PrimitiveUtils;
public class JcrRealizedFlow extends RealizedFlow implements SlcNames {
private static final long serialVersionUID = -3709453850260712001L;
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.spring.unit;
+
+import org.argeo.slc.execution.ExecutionFlow;
+
+public class AbstractExecutionFlowTestcase extends AbstractSpringTestCase {
+ @SuppressWarnings(value = { "unchecked" })
+ protected <T extends ExecutionFlow> T executeFlow(String flowName) {
+ ExecutionFlow flow = getBean(flowName);
+ flow.run();
+ return (T) flow;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.spring.unit;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.osgi.boot.OsgiBoot;
+import org.argeo.slc.SlcException;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.eclipse.gemini.blueprint.util.OsgiStringUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.springframework.context.ApplicationContext;
+
+import junit.framework.TestCase;
+
+@SuppressWarnings("restriction")
+public abstract class AbstractOsgiRuntimeTestCase extends TestCase {
+ private final static Log log = LogFactory
+ .getLog(AbstractOsgiRuntimeTestCase.class);
+
+ protected OsgiBoot osgiBoot = null;
+
+ protected void installBundles() throws Exception {
+
+ }
+
+ public void setUp() throws Exception {
+ // To avoid xerces from the classpath being detected as the provider
+ System
+ .setProperty("javax.xml.parsers.DocumentBuilderFactory",
+ "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
+ System.setProperty("javax.xml.parsers.SAXParserFactory",
+ "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
+
+ BundleContext bundleContext = startRuntime();
+ osgiBoot = new OsgiBoot(bundleContext);
+ log.info("OSGi runtime started.");
+
+ installBundles();
+
+ List<String> bundlesToStart = getBundlesToStart();
+ osgiBoot.startBundles(bundlesToStart);
+ waitAllBundlesOk(bundlesToStart);
+ if (log.isTraceEnabled())
+ listInstalledBundles();
+ }
+
+ public void tearDown() throws Exception {
+ osgiBoot = null;
+ stopRuntime();
+ log.info("OSGi runtime stopped.");
+ }
+
+ protected BundleContext startRuntime() throws Exception {
+ String[] args = { "-console", "-clean" };
+ BundleContext bundleContext = EclipseStarter.startup(args, null);
+ return bundleContext;
+ }
+
+ protected void stopRuntime() throws Exception {
+ EclipseStarter.shutdown();
+ }
+
+ protected List<String> getBundlesToStart() {
+ return new ArrayList<String>();
+ }
+
+ protected void listInstalledBundles() {
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ Bundle[] bundles = bundleContext.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ System.out.println(OsgiStringUtils.nullSafeSymbolicName(bundles[i])
+ + " [" + OsgiStringUtils.bundleStateAsString(bundles[i])
+ + "] " + bundles[i].getLocation());
+ }
+
+ }
+
+ protected Map<Bundle, ApplicationContext> getOsgiApplicationContexts()
+ throws Exception {
+ Map<Bundle, ApplicationContext> map = new HashMap<Bundle, ApplicationContext>();
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ ServiceReference[] srs = bundleContext.getServiceReferences(
+ ApplicationContext.class.getName(), null);
+ for (ServiceReference sr : srs) {
+ ApplicationContext context = (ApplicationContext) bundleContext
+ .getService(sr);
+ map.put(sr.getBundle(), context);
+ }
+ return map;
+ }
+
+ /** Wait for all bundles to be either RESOLVED or ACTIVE. */
+ protected void waitAllBundlesOk(List<String> bundlesToStart) {
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ long begin = System.currentTimeMillis();
+ long duration = 0;
+ boolean allBundlesOk = true;
+ StringBuffer badBundles = null;
+ while (duration < getResolvedTimeout()) {
+ badBundles = new StringBuffer();
+ for (Bundle bundle : bundleContext.getBundles()) {
+ if (bundle.getSymbolicName() != null
+ && bundle.getSymbolicName().startsWith(
+ "org.eclipse.jdt")) {
+ // don't check Eclipse SDK bundles
+ continue;
+ }
+
+ if (bundle.getState() == Bundle.INSTALLED) {
+ allBundlesOk = false;
+ badBundles
+ .append(OsgiStringUtils
+ .nullSafeSymbolicName(bundle)
+ + " ["
+ + OsgiStringUtils
+ .bundleStateAsString(bundle) + "]");
+ }
+
+ if (bundlesToStart.contains(bundle.getSymbolicName())
+ && bundle.getState() != Bundle.ACTIVE) {
+ allBundlesOk = false;
+ badBundles.append(OsgiStringUtils
+ .nullSafeSymbolicName(bundle)
+ + " ["
+ + OsgiStringUtils.bundleStateAsString(bundle)
+ + "]\n");
+ }
+ }
+
+ if (allBundlesOk)
+ break;// while
+
+ sleep(1000);
+
+ duration = System.currentTimeMillis() - begin;
+ }
+
+ if (!allBundlesOk) {
+ listInstalledBundles();
+ throw new SlcException(
+ "Some bundles are not at the proper status:\n" + badBundles);
+ }
+ }
+
+ /**
+ * Make sure that the application context of the started bundles starting
+ * with this prefix are properly initialized
+ */
+ protected void assertStartedBundlesApplicationContext(
+ String bundleSymbolicNamesPrefix) {
+ List<String> bundlesToStart = getBundlesToStart();
+ for (String bundleSName : bundlesToStart) {
+ if (bundleSName.startsWith(bundleSymbolicNamesPrefix))
+ assertBundleApplicationContext(bundleSName);
+ }
+ }
+
+ /**
+ * Make sure that the application context of this bundle is properly
+ * initialized
+ */
+ protected void assertBundleApplicationContext(String bundleSymbolicName) {
+ String filter = "(Bundle-SymbolicName=" + bundleSymbolicName + ")";
+ // Wait for application context to be ready
+ try {
+ ServiceReference[] srs = getServiceRefSynchronous(
+ ApplicationContext.class.getName(), filter);
+ if (srs == null)
+ throw new SlcException("No application context for "
+ + bundleSymbolicName);
+ } catch (InvalidSyntaxException e) {
+ throw new SlcException(
+ "Unexpected exception when looking for application context for bundle "
+ + bundleSymbolicName, e);
+ }
+ log.info("Application context of bundle " + bundleSymbolicName
+ + " is initalized.");
+ }
+
+ protected ServiceReference[] getServiceRefSynchronous(String clss,
+ String filter) throws InvalidSyntaxException {
+ // FIXME: factorize
+ if (log.isTraceEnabled())
+ log.debug("Filter: '" + filter + "'");
+ ServiceReference[] sfs = null;
+ boolean waiting = true;
+ long begin = System.currentTimeMillis();
+ do {
+ sfs = getBundleContext().getServiceReferences(clss, filter);
+
+ if (sfs != null)
+ waiting = false;
+
+ sleep(100);
+ if (System.currentTimeMillis() - begin > getDefaultTimeout())
+ throw new SlcException("Search of services " + clss
+ + " with filter " + filter + " timed out.");
+ } while (waiting);
+
+ return sfs;
+ }
+
+ protected BundleContext getBundleContext() {
+ return osgiBoot.getBundleContext();
+ }
+
+ /** Default is 30s */
+ protected long getResolvedTimeout() {
+ return 30 * 1000l;
+ }
+
+ /** Default is 10s */
+ protected long getDefaultTimeout() {
+ return 10 * 1000l;
+ }
+
+ final protected void sleep(long duration) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // silent
+ }
+ }
+}
--- /dev/null
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.slc.spring.unit;\r
+\r
+import java.util.Map;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.SlcException;\r
+import org.springframework.beans.factory.BeanFactoryUtils;\r
+import org.springframework.beans.factory.ListableBeanFactory;\r
+import org.springframework.context.ConfigurableApplicationContext;\r
+import org.springframework.context.support.ClassPathXmlApplicationContext;\r
+\r
+import junit.framework.TestCase;\r
+\r
+/** Helper for tests using a Spring application co,text. */\r
+public abstract class AbstractSpringTestCase extends TestCase {\r
+ protected final Log log = LogFactory.getLog(getClass());\r
+ private ConfigurableApplicationContext context;\r
+\r
+ /**\r
+ * Gets (and create if necessary) the application context to use. Default\r
+ * implementation uses a class path xml application context and calls\r
+ * {@link #getApplicationContextLocation()}.\r
+ */\r
+ protected ConfigurableApplicationContext getContext() {\r
+ if (context == null) {\r
+ context = new ClassPathXmlApplicationContext(\r
+ getApplicationContextLocation());\r
+ if (getIsStartContext())\r
+ context.start();\r
+ }\r
+ return context;\r
+ }\r
+\r
+ @Override\r
+ protected void tearDown() throws Exception {\r
+ if (context != null && context.isActive())\r
+ context.close();\r
+ super.tearDown();\r
+ }\r
+\r
+ /** Whether the context should be started after being created. */\r
+ protected Boolean getIsStartContext() {\r
+ return false;\r
+ }\r
+\r
+ /** Returns a bean from the underlying context */\r
+ @SuppressWarnings(value = { "unchecked" })\r
+ protected <T> T getBean(String beanId) {\r
+ return (T) getContext().getBean(beanId);\r
+ }\r
+\r
+ protected <T> T getBean(Class<? extends T> clss) {\r
+ T bean = loadSingleFromContext(getContext(), clss);\r
+ if (bean == null) {\r
+ throw new SlcException("Cannot retrieve a unique bean of type "\r
+ + clss);\r
+ } else {\r
+ return bean;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Th location of the application to load. The default implementation\r
+ * returns <i>applicationContext.xml</i> found in the same package as the\r
+ * test.\r
+ */\r
+ protected String getApplicationContextLocation() {\r
+ return inPackage("applicationContext.xml");\r
+ }\r
+\r
+ /**\r
+ * Prefixes the package of the class after converting the '.' to '/' in\r
+ * order to have a resource path.\r
+ */\r
+ protected String inPackage(String suffix) {\r
+ String prefix = getClass().getPackage().getName().replace('.', '/');\r
+ return prefix + '/' + suffix;\r
+ }\r
+\r
+ @SuppressWarnings(value = { "unchecked" })\r
+ protected <T> T loadSingleFromContext(ListableBeanFactory context,\r
+ Class<T> clss) {\r
+ Map<String, T> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(\r
+ context, clss, false, false);\r
+ if (beans.size() == 1) {\r
+ return beans.values().iterator().next();\r
+ } else if (beans.size() > 1) {\r
+ if (log.isDebugEnabled()) {\r
+ log\r
+ .debug(("Found more that on bean for type " + clss\r
+ + ": " + beans.keySet()));\r
+ }\r
+ return null;\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.spring.unit;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.argeo.slc.core.execution.DefaultExecutionSpec;
+import org.argeo.slc.core.test.BasicTestData;
+import org.argeo.slc.execution.ExecutionFlowDescriptor;
+import org.argeo.slc.execution.ExecutionSpecAttribute;
+import org.argeo.slc.execution.RefSpecAttribute;
+import org.argeo.slc.execution.RefValue;
+import org.argeo.slc.execution.RefValueChoice;
+import org.argeo.slc.primitive.PrimitiveAccessor;
+import org.argeo.slc.primitive.PrimitiveSpecAttribute;
+import org.argeo.slc.primitive.PrimitiveValue;
+
+public class ExecutionFlowDescriptorTestUtils {
+ public static ExecutionFlowDescriptor createSimpleExecutionFlowDescriptor() {
+ ExecutionFlowDescriptor flowDescriptor = new ExecutionFlowDescriptor();
+ flowDescriptor.setName("simpleFlow");
+ flowDescriptor.setDescription("my description");
+
+ Map<String, Object> values = new HashMap<String, Object>();
+ values.put("primitiveInteger", new PrimitiveValue(
+ PrimitiveAccessor.TYPE_INTEGER, 100));
+
+ RefValue refValue = new RefValue("002");
+ values.put("ref1", refValue);
+ flowDescriptor.setValues(values);
+
+ flowDescriptor.setExecutionSpec(createRelatedSimpleSpec());
+ return flowDescriptor;
+ }
+
+ protected static DefaultExecutionSpec createRelatedSimpleSpec() {
+ DefaultExecutionSpec spec = new DefaultExecutionSpec();
+ spec.setBeanName("simpleSpec");
+ Map<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
+
+ PrimitiveSpecAttribute primitiveInteger = new PrimitiveSpecAttribute();
+ primitiveInteger.setType(PrimitiveAccessor.TYPE_INTEGER);
+ primitiveInteger.setValue(50);
+ attributes.put("primitiveInteger", primitiveInteger);
+
+ RefSpecAttribute ref1 = new RefSpecAttribute();
+ ref1.setTargetClass(BasicTestData.class);
+ ref1.setChoices(new ArrayList<RefValueChoice>());
+ ref1.getChoices().add(new RefValueChoice("001", "desc"));
+ ref1.getChoices().add(new RefValueChoice("002", null));
+ ref1.getChoices().add(new RefValueChoice("003", null));
+ attributes.put("ref1", ref1);
+
+ spec.setAttributes(attributes);
+
+ return spec;
+ }
+}
--- /dev/null
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.slc.spring.unit;\r
+\r
+import static junit.framework.Assert.assertEquals;\r
+import static junit.framework.Assert.assertNotNull;\r
+import static junit.framework.Assert.assertNull;\r
+\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+import java.util.GregorianCalendar;\r
+\r
+public abstract class UnitUtils {\r
+ public static void assertDateSec(Date expected, Date reached) {\r
+ if (expected == null) {\r
+ assertNull(reached);\r
+ return;\r
+ } else {\r
+ assertNotNull(reached);\r
+ }\r
+\r
+ Calendar expectedCal = new GregorianCalendar();\r
+ expectedCal.setTime(expected);\r
+ Calendar reachedCal = new GregorianCalendar();\r
+ reachedCal.setTime(reached);\r
+ assertEquals(expectedCal.get(Calendar.YEAR), reachedCal\r
+ .get(Calendar.YEAR));\r
+ assertEquals(expectedCal.get(Calendar.MONTH), reachedCal\r
+ .get(Calendar.MONTH));\r
+ assertEquals(expectedCal.get(Calendar.DATE), reachedCal\r
+ .get(Calendar.DATE));\r
+ assertEquals(expectedCal.get(Calendar.HOUR_OF_DAY), reachedCal\r
+ .get(Calendar.HOUR_OF_DAY));\r
+ assertEquals(expectedCal.get(Calendar.MINUTE), reachedCal\r
+ .get(Calendar.MINUTE));\r
+ assertEquals(expectedCal.get(Calendar.SECOND), reachedCal\r
+ .get(Calendar.SECOND));\r
+ }\r
+\r
+ private UnitUtils() {\r
+\r
+ }\r
+\r
+}\r
<!-- SLC Runtime -->
<dependency>
<groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.core</artifactId>
+ <artifactId>org.argeo.slc.spring</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
</dependencies>
<!-- SLC -->
<dependency>
<groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.core</artifactId>
- <version>2.1.17-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.argeo.slc</groupId>
- <artifactId>org.argeo.slc.support</artifactId>
+ <artifactId>org.argeo.slc.api</artifactId>
<version>2.1.17-SNAPSHOT</version>
</dependency>
+<!-- <dependency> -->
+<!-- <groupId>org.argeo.slc</groupId> -->
+<!-- <artifactId>org.argeo.slc.support</artifactId> -->
+<!-- <version>2.1.17-SNAPSHOT</version> -->
+<!-- </dependency> -->
</dependencies>
</project>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.equinox.unit;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.osgi.boot.OsgiBoot;
-import org.argeo.slc.SlcException;
-import org.eclipse.core.runtime.adaptor.EclipseStarter;
-import org.eclipse.gemini.blueprint.util.OsgiStringUtils;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.springframework.context.ApplicationContext;
-
-@SuppressWarnings("restriction")
-public abstract class AbstractOsgiRuntimeTestCase extends TestCase {
- private final static Log log = LogFactory
- .getLog(AbstractOsgiRuntimeTestCase.class);
-
- protected OsgiBoot osgiBoot = null;
-
- protected void installBundles() throws Exception {
-
- }
-
- public void setUp() throws Exception {
- // To avoid xerces from the classpath being detected as the provider
- System
- .setProperty("javax.xml.parsers.DocumentBuilderFactory",
- "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
- System.setProperty("javax.xml.parsers.SAXParserFactory",
- "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
-
- BundleContext bundleContext = startRuntime();
- osgiBoot = new OsgiBoot(bundleContext);
- log.info("OSGi runtime started.");
-
- installBundles();
-
- List<String> bundlesToStart = getBundlesToStart();
- osgiBoot.startBundles(bundlesToStart);
- waitAllBundlesOk(bundlesToStart);
- if (log.isTraceEnabled())
- listInstalledBundles();
- }
-
- public void tearDown() throws Exception {
- osgiBoot = null;
- stopRuntime();
- log.info("OSGi runtime stopped.");
- }
-
- protected BundleContext startRuntime() throws Exception {
- String[] args = { "-console", "-clean" };
- BundleContext bundleContext = EclipseStarter.startup(args, null);
- return bundleContext;
- }
-
- protected void stopRuntime() throws Exception {
- EclipseStarter.shutdown();
- }
-
- protected List<String> getBundlesToStart() {
- return new ArrayList<String>();
- }
-
- protected void listInstalledBundles() {
- BundleContext bundleContext = osgiBoot.getBundleContext();
- Bundle[] bundles = bundleContext.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- System.out.println(OsgiStringUtils.nullSafeSymbolicName(bundles[i])
- + " [" + OsgiStringUtils.bundleStateAsString(bundles[i])
- + "] " + bundles[i].getLocation());
- }
-
- }
-
- protected Map<Bundle, ApplicationContext> getOsgiApplicationContexts()
- throws Exception {
- Map<Bundle, ApplicationContext> map = new HashMap<Bundle, ApplicationContext>();
- BundleContext bundleContext = osgiBoot.getBundleContext();
- ServiceReference[] srs = bundleContext.getServiceReferences(
- ApplicationContext.class.getName(), null);
- for (ServiceReference sr : srs) {
- ApplicationContext context = (ApplicationContext) bundleContext
- .getService(sr);
- map.put(sr.getBundle(), context);
- }
- return map;
- }
-
- /** Wait for all bundles to be either RESOLVED or ACTIVE. */
- protected void waitAllBundlesOk(List<String> bundlesToStart) {
- BundleContext bundleContext = osgiBoot.getBundleContext();
- long begin = System.currentTimeMillis();
- long duration = 0;
- boolean allBundlesOk = true;
- StringBuffer badBundles = null;
- while (duration < getResolvedTimeout()) {
- badBundles = new StringBuffer();
- for (Bundle bundle : bundleContext.getBundles()) {
- if (bundle.getSymbolicName() != null
- && bundle.getSymbolicName().startsWith(
- "org.eclipse.jdt")) {
- // don't check Eclipse SDK bundles
- continue;
- }
-
- if (bundle.getState() == Bundle.INSTALLED) {
- allBundlesOk = false;
- badBundles
- .append(OsgiStringUtils
- .nullSafeSymbolicName(bundle)
- + " ["
- + OsgiStringUtils
- .bundleStateAsString(bundle) + "]");
- }
-
- if (bundlesToStart.contains(bundle.getSymbolicName())
- && bundle.getState() != Bundle.ACTIVE) {
- allBundlesOk = false;
- badBundles.append(OsgiStringUtils
- .nullSafeSymbolicName(bundle)
- + " ["
- + OsgiStringUtils.bundleStateAsString(bundle)
- + "]\n");
- }
- }
-
- if (allBundlesOk)
- break;// while
-
- sleep(1000);
-
- duration = System.currentTimeMillis() - begin;
- }
-
- if (!allBundlesOk) {
- listInstalledBundles();
- throw new SlcException(
- "Some bundles are not at the proper status:\n" + badBundles);
- }
- }
-
- /**
- * Make sure that the application context of the started bundles starting
- * with this prefix are properly initialized
- */
- protected void assertStartedBundlesApplicationContext(
- String bundleSymbolicNamesPrefix) {
- List<String> bundlesToStart = getBundlesToStart();
- for (String bundleSName : bundlesToStart) {
- if (bundleSName.startsWith(bundleSymbolicNamesPrefix))
- assertBundleApplicationContext(bundleSName);
- }
- }
-
- /**
- * Make sure that the application context of this bundle is properly
- * initialized
- */
- protected void assertBundleApplicationContext(String bundleSymbolicName) {
- String filter = "(Bundle-SymbolicName=" + bundleSymbolicName + ")";
- // Wait for application context to be ready
- try {
- ServiceReference[] srs = getServiceRefSynchronous(
- ApplicationContext.class.getName(), filter);
- if (srs == null)
- throw new SlcException("No application context for "
- + bundleSymbolicName);
- } catch (InvalidSyntaxException e) {
- throw new SlcException(
- "Unexpected exception when looking for application context for bundle "
- + bundleSymbolicName, e);
- }
- log.info("Application context of bundle " + bundleSymbolicName
- + " is initalized.");
- }
-
- protected ServiceReference[] getServiceRefSynchronous(String clss,
- String filter) throws InvalidSyntaxException {
- // FIXME: factorize
- if (log.isTraceEnabled())
- log.debug("Filter: '" + filter + "'");
- ServiceReference[] sfs = null;
- boolean waiting = true;
- long begin = System.currentTimeMillis();
- do {
- sfs = getBundleContext().getServiceReferences(clss, filter);
-
- if (sfs != null)
- waiting = false;
-
- sleep(100);
- if (System.currentTimeMillis() - begin > getDefaultTimeout())
- throw new SlcException("Search of services " + clss
- + " with filter " + filter + " timed out.");
- } while (waiting);
-
- return sfs;
- }
-
- protected BundleContext getBundleContext() {
- return osgiBoot.getBundleContext();
- }
-
- /** Default is 30s */
- protected long getResolvedTimeout() {
- return 30 * 1000l;
- }
-
- /** Default is 10s */
- protected long getDefaultTimeout() {
- return 10 * 1000l;
- }
-
- final protected void sleep(long duration) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // silent
- }
- }
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit;\r
-\r
-import java.util.Map;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.SlcException;\r
-import org.springframework.beans.factory.BeanFactoryUtils;\r
-import org.springframework.beans.factory.ListableBeanFactory;\r
-import org.springframework.context.ConfigurableApplicationContext;\r
-import org.springframework.context.support.ClassPathXmlApplicationContext;\r
-\r
-/** Helper for tests using a Spring application co,text. */\r
-public abstract class AbstractSpringTestCase extends TestCase {\r
- protected final Log log = LogFactory.getLog(getClass());\r
- private ConfigurableApplicationContext context;\r
-\r
- /**\r
- * Gets (and create if necessary) the application context to use. Default\r
- * implementation uses a class path xml application context and calls\r
- * {@link #getApplicationContextLocation()}.\r
- */\r
- protected ConfigurableApplicationContext getContext() {\r
- if (context == null) {\r
- context = new ClassPathXmlApplicationContext(\r
- getApplicationContextLocation());\r
- if (getIsStartContext())\r
- context.start();\r
- }\r
- return context;\r
- }\r
-\r
- @Override\r
- protected void tearDown() throws Exception {\r
- if (context != null && context.isActive())\r
- context.close();\r
- super.tearDown();\r
- }\r
-\r
- /** Whether the context should be started after being created. */\r
- protected Boolean getIsStartContext() {\r
- return false;\r
- }\r
-\r
- /** Returns a bean from the underlying context */\r
- @SuppressWarnings(value = { "unchecked" })\r
- protected <T> T getBean(String beanId) {\r
- return (T) getContext().getBean(beanId);\r
- }\r
-\r
- protected <T> T getBean(Class<? extends T> clss) {\r
- T bean = loadSingleFromContext(getContext(), clss);\r
- if (bean == null) {\r
- throw new SlcException("Cannot retrieve a unique bean of type "\r
- + clss);\r
- } else {\r
- return bean;\r
- }\r
- }\r
-\r
- /**\r
- * Th location of the application to load. The default implementation\r
- * returns <i>applicationContext.xml</i> found in the same package as the\r
- * test.\r
- */\r
- protected String getApplicationContextLocation() {\r
- return inPackage("applicationContext.xml");\r
- }\r
-\r
- /**\r
- * Prefixes the package of the class after converting the '.' to '/' in\r
- * order to have a resource path.\r
- */\r
- protected String inPackage(String suffix) {\r
- String prefix = getClass().getPackage().getName().replace('.', '/');\r
- return prefix + '/' + suffix;\r
- }\r
-\r
- @SuppressWarnings(value = { "unchecked" })\r
- protected <T> T loadSingleFromContext(ListableBeanFactory context,\r
- Class<T> clss) {\r
- Map<String, T> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(\r
- context, clss, false, false);\r
- if (beans.size() == 1) {\r
- return beans.values().iterator().next();\r
- } else if (beans.size() > 1) {\r
- if (log.isDebugEnabled()) {\r
- log\r
- .debug(("Found more that on bean for type " + clss\r
- + ": " + beans.keySet()));\r
- }\r
- return null;\r
- } else {\r
- return null;\r
- }\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit;\r
-\r
-import static junit.framework.Assert.assertEquals;\r
-import static junit.framework.Assert.assertNotNull;\r
-import static junit.framework.Assert.assertNull;\r
-\r
-import java.util.Calendar;\r
-import java.util.Date;\r
-import java.util.GregorianCalendar;\r
-\r
-public abstract class UnitUtils {\r
- public static void assertDateSec(Date expected, Date reached) {\r
- if (expected == null) {\r
- assertNull(reached);\r
- return;\r
- } else {\r
- assertNotNull(reached);\r
- }\r
-\r
- Calendar expectedCal = new GregorianCalendar();\r
- expectedCal.setTime(expected);\r
- Calendar reachedCal = new GregorianCalendar();\r
- reachedCal.setTime(reached);\r
- assertEquals(expectedCal.get(Calendar.YEAR), reachedCal\r
- .get(Calendar.YEAR));\r
- assertEquals(expectedCal.get(Calendar.MONTH), reachedCal\r
- .get(Calendar.MONTH));\r
- assertEquals(expectedCal.get(Calendar.DATE), reachedCal\r
- .get(Calendar.DATE));\r
- assertEquals(expectedCal.get(Calendar.HOUR_OF_DAY), reachedCal\r
- .get(Calendar.HOUR_OF_DAY));\r
- assertEquals(expectedCal.get(Calendar.MINUTE), reachedCal\r
- .get(Calendar.MINUTE));\r
- assertEquals(expectedCal.get(Calendar.SECOND), reachedCal\r
- .get(Calendar.SECOND));\r
- }\r
-\r
- private UnitUtils() {\r
-\r
- }\r
-\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.unit.execution;
-
-import org.argeo.slc.execution.ExecutionFlow;
-import org.argeo.slc.unit.AbstractSpringTestCase;
-
-public class AbstractExecutionFlowTestcase extends AbstractSpringTestCase {
- @SuppressWarnings(value = { "unchecked" })
- protected <T extends ExecutionFlow> T executeFlow(String flowName) {
- ExecutionFlow flow = getBean(flowName);
- flow.run();
- return (T) flow;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.unit.execution;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.argeo.slc.core.execution.DefaultExecutionSpec;
-import org.argeo.slc.core.execution.PrimitiveAccessor;
-import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
-import org.argeo.slc.core.execution.PrimitiveValue;
-import org.argeo.slc.core.execution.RefSpecAttribute;
-import org.argeo.slc.core.execution.RefValue;
-import org.argeo.slc.core.execution.RefValueChoice;
-import org.argeo.slc.core.test.BasicTestData;
-import org.argeo.slc.execution.ExecutionFlowDescriptor;
-import org.argeo.slc.execution.ExecutionSpecAttribute;
-
-public class ExecutionFlowDescriptorTestUtils {
- public static ExecutionFlowDescriptor createSimpleExecutionFlowDescriptor() {
- ExecutionFlowDescriptor flowDescriptor = new ExecutionFlowDescriptor();
- flowDescriptor.setName("simpleFlow");
- flowDescriptor.setDescription("my description");
-
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("primitiveInteger", new PrimitiveValue(
- PrimitiveAccessor.TYPE_INTEGER, 100));
-
- RefValue refValue = new RefValue("002");
- values.put("ref1", refValue);
- flowDescriptor.setValues(values);
-
- flowDescriptor.setExecutionSpec(createRelatedSimpleSpec());
- return flowDescriptor;
- }
-
- protected static DefaultExecutionSpec createRelatedSimpleSpec() {
- DefaultExecutionSpec spec = new DefaultExecutionSpec();
- spec.setBeanName("simpleSpec");
- Map<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
-
- PrimitiveSpecAttribute primitiveInteger = new PrimitiveSpecAttribute();
- primitiveInteger.setType(PrimitiveAccessor.TYPE_INTEGER);
- primitiveInteger.setValue(50);
- attributes.put("primitiveInteger", primitiveInteger);
-
- RefSpecAttribute ref1 = new RefSpecAttribute();
- ref1.setTargetClass(BasicTestData.class);
- ref1.setChoices(new ArrayList<RefValueChoice>());
- ref1.getChoices().add(new RefValueChoice("001", "desc"));
- ref1.getChoices().add(new RefValueChoice("002", null));
- ref1.getChoices().add(new RefValueChoice("003", null));
- attributes.put("ref1", ref1);
-
- spec.setAttributes(attributes);
-
- return spec;
- }
-}
</properties>
<modules>
<module>org.argeo.slc.api</module>
+ <module>org.argeo.slc.jcr</module>
<!-- Runtime -->
<module>org.argeo.slc.spring</module>
- <module>org.argeo.slc.unit</module>
<module>org.argeo.slc.support</module>
<module>org.argeo.slc.repo</module>
<module>org.argeo.slc.factory</module>