From: Mathieu Baudier Date: Sat, 15 Feb 2020 09:55:52 +0000 (+0100) Subject: Start SLC 2 refactoring. X-Git-Tag: argeo-slc-2.1.17~67 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=f8a9ca2e0faabe1e0cdcd3537da34e02a0e55f57;p=gpl%2Fargeo-slc.git Start SLC 2 refactoring. --- diff --git a/dep/org.argeo.slc.dep.backend/pom.xml b/dep/org.argeo.slc.dep.backend/pom.xml index e0210c753..4bbe5394d 100644 --- a/dep/org.argeo.slc.dep.backend/pom.xml +++ b/dep/org.argeo.slc.dep.backend/pom.xml @@ -105,15 +105,6 @@ org.argeo.tp.misc org.eclipse.jgit - - - - - org.argeo.slc - org.argeo.slc.unit - 2.1.17-SNAPSHOT - test - diff --git a/dep/org.argeo.slc.dep.e4.rap/pom.xml b/dep/org.argeo.slc.dep.e4.rap/pom.xml index 30bd59c9e..63cfd3403 100644 --- a/dep/org.argeo.slc.dep.e4.rap/pom.xml +++ b/dep/org.argeo.slc.dep.e4.rap/pom.xml @@ -32,6 +32,15 @@ 2.1.17-SNAPSHOT + + + org.argeo.commons + org.argeo.osgi.boot + 2.1.86-SNAPSHOT + test + + @@ -42,26 +51,26 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/dep/org.argeo.slc.dep.minimal/pom.xml b/dep/org.argeo.slc.dep.minimal/pom.xml index e32a59a82..e51826248 100644 --- a/dep/org.argeo.slc.dep.minimal/pom.xml +++ b/dep/org.argeo.slc.dep.minimal/pom.xml @@ -25,11 +25,6 @@ org.argeo.slc.api 2.1.17-SNAPSHOT - - org.argeo.slc - org.argeo.slc.support - 2.1.17-SNAPSHOT - diff --git a/dep/org.argeo.slc.dep.spring/pom.xml b/dep/org.argeo.slc.dep.spring/pom.xml index faada3bb6..835345eea 100644 --- a/dep/org.argeo.slc.dep.spring/pom.xml +++ b/dep/org.argeo.slc.dep.spring/pom.xml @@ -22,7 +22,12 @@ org.argeo.slc - org.argeo.slc.core + org.argeo.slc.spring + 2.1.17-SNAPSHOT + + + org.argeo.slc + org.argeo.slc.support 2.1.17-SNAPSHOT @@ -44,6 +49,20 @@ 2.1.17-SNAPSHOT + + + org.argeo.tp.apache.ant + org.apache.ant + + + org.argeo.tp.apache.ant + org.apache.ant.launch + + + org.argeo.tp.javax + javax.mail + + org.argeo.tp.spring diff --git a/legacy/argeo-commons/dep/org.argeo.dep.cms.platform/pom.xml b/legacy/argeo-commons/dep/org.argeo.dep.cms.platform/pom.xml index 047a269fb..f2edc68c3 100644 --- a/legacy/argeo-commons/dep/org.argeo.dep.cms.platform/pom.xml +++ b/legacy/argeo-commons/dep/org.argeo.dep.cms.platform/pom.xml @@ -87,22 +87,14 @@ - - org.argeo.tp.bouncycastle - bcmail - - - org.argeo.tp.bouncycastle - bcpg - - - org.argeo.tp.apache.ant - org.apache.ant - - - org.argeo.tp.apache.ant - org.apache.ant.launch - + + + + + + + + @@ -111,78 +103,75 @@ - - org.argeo.tp.javax - javax.mail - - - org.argeo.tp.spring - org.springframework.beans - - - org.argeo.tp.spring - org.springframework.core - - - org.argeo.tp.javax - javax.el - - - org.argeo.tp.gemini - org.eclipse.gemini.blueprint.core - - - org.argeo.tp.gemini - org.eclipse.gemini.blueprint.extender - - - org.argeo.tp.gemini - org.eclipse.gemini.blueprint.io - - - org.argeo.tp.misc - org.aspectj.weaver - - - org.argeo.tp.misc - org.aopalliance - - - org.argeo.tp.spring - org.springframework.aop - - - org.argeo.tp.spring - org.springframework.context - - - org.argeo.tp.spring - org.springframework.expression - - - org.argeo.tp.spring - org.springframework.instrument - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - org.argeo.tp.spring - org.springframework.aspects - - - org.argeo.tp.spring - org.springframework.context.support - - - org.argeo.tp.spring - org.springframework.jdbc - - - org.argeo.tp.spring - org.springframework.tx - + + + + + + + + + + + + + + + + + diff --git a/org.argeo.slc.api/src/org/argeo/slc/attachment/Attachment.java b/org.argeo.slc.api/src/org/argeo/slc/attachment/Attachment.java new file mode 100644 index 000000000..9ad961355 --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/attachment/Attachment.java @@ -0,0 +1,26 @@ +/* + * 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(); +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/attachment/AttachmentsEnabled.java b/org.argeo.slc.api/src/org/argeo/slc/attachment/AttachmentsEnabled.java new file mode 100644 index 000000000..53c8cdf4b --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/attachment/AttachmentsEnabled.java @@ -0,0 +1,20 @@ +/* + * 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); +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/attachment/AttachmentsStorage.java b/org.argeo.slc.api/src/org/argeo/slc/attachment/AttachmentsStorage.java new file mode 100644 index 000000000..94a845c7b --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/attachment/AttachmentsStorage.java @@ -0,0 +1,27 @@ +/* + * 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); +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/AbstractExecutionValue.java b/org.argeo.slc.api/src/org/argeo/slc/execution/AbstractExecutionValue.java new file mode 100644 index 000000000..23ab55ebe --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/execution/AbstractExecutionValue.java @@ -0,0 +1,23 @@ +/* + * 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; +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/AbstractSpecAttribute.java b/org.argeo.slc.api/src/org/argeo/slc/execution/AbstractSpecAttribute.java new file mode 100644 index 000000000..5b1438ad2 --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/execution/AbstractSpecAttribute.java @@ -0,0 +1,88 @@ +/* + * 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; + } + +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/RefSpecAttribute.java b/org.argeo.slc.api/src/org/argeo/slc/execution/RefSpecAttribute.java new file mode 100644 index 000000000..ccfebaf03 --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/execution/RefSpecAttribute.java @@ -0,0 +1,77 @@ +/* + * 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 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 getChoices() { + return choices; + } + + public void setChoices(List 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 : ""); + } + +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/RefValue.java b/org.argeo.slc.api/src/org/argeo/slc/execution/RefValue.java new file mode 100644 index 000000000..b66f2c474 --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/execution/RefValue.java @@ -0,0 +1,53 @@ +/* + * 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 + "]"; + } + +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/RefValueChoice.java b/org.argeo.slc.api/src/org/argeo/slc/execution/RefValueChoice.java new file mode 100644 index 000000000..83c880a8e --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/execution/RefValueChoice.java @@ -0,0 +1,50 @@ +/* + * 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; + } + +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveAccessor.java b/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveAccessor.java new file mode 100644 index 000000000..ce71429d7 --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveAccessor.java @@ -0,0 +1,37 @@ +/* + * 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); +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveSpecAttribute.java b/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveSpecAttribute.java new file mode 100644 index 000000000..eb9ff2ad8 --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveSpecAttribute.java @@ -0,0 +1,66 @@ +/* + * 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 : ""); + } + +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveUtils.java b/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveUtils.java new file mode 100644 index 000000000..d7284cf8d --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveUtils.java @@ -0,0 +1,110 @@ +/* + * 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; + } + } + +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveValue.java b/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveValue.java new file mode 100644 index 000000000..b3ade50d9 --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/primitive/PrimitiveValue.java @@ -0,0 +1,54 @@ +/* + * 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; + } + +} diff --git a/org.argeo.slc.client.ui/pom.xml b/org.argeo.slc.client.ui/pom.xml index c2ff564df..f4571db4c 100644 --- a/org.argeo.slc.client.ui/pom.xml +++ b/org.argeo.slc.client.ui/pom.xml @@ -15,7 +15,7 @@ org.argeo.slc - org.argeo.slc.core + org.argeo.slc.spring 2.1.17-SNAPSHOT diff --git a/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java b/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java index 758d761c6..638d3a2d2 100644 --- a/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java +++ b/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java @@ -38,8 +38,8 @@ import org.argeo.slc.SlcException; 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; diff --git a/org.argeo.slc.e4/pom.xml b/org.argeo.slc.e4/pom.xml index e638a99b5..8585843b7 100644 --- a/org.argeo.slc.e4/pom.xml +++ b/org.argeo.slc.e4/pom.xml @@ -13,7 +13,7 @@ org.argeo.slc - org.argeo.slc.core + org.argeo.slc.jcr 2.1.17-SNAPSHOT diff --git a/org.argeo.slc.jcr/.classpath b/org.argeo.slc.jcr/.classpath new file mode 100644 index 000000000..e801ebfb4 --- /dev/null +++ b/org.argeo.slc.jcr/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.argeo.slc.jcr/.gitignore b/org.argeo.slc.jcr/.gitignore new file mode 100644 index 000000000..09e3bc9b2 --- /dev/null +++ b/org.argeo.slc.jcr/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/org.argeo.slc.jcr/.project b/org.argeo.slc.jcr/.project new file mode 100644 index 000000000..a4cd8740b --- /dev/null +++ b/org.argeo.slc.jcr/.project @@ -0,0 +1,28 @@ + + + org.argeo.slc.jcr + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.argeo.slc.jcr/META-INF/.gitignore b/org.argeo.slc.jcr/META-INF/.gitignore new file mode 100644 index 000000000..4854a41b9 --- /dev/null +++ b/org.argeo.slc.jcr/META-INF/.gitignore @@ -0,0 +1 @@ +/MANIFEST.MF diff --git a/org.argeo.slc.jcr/bnd.bnd b/org.argeo.slc.jcr/bnd.bnd new file mode 100644 index 000000000..b632c5a46 --- /dev/null +++ b/org.argeo.slc.jcr/bnd.bnd @@ -0,0 +1,2 @@ +Import-Package: javax.jcr.nodetype,\ +* \ No newline at end of file diff --git a/org.argeo.slc.jcr/build.properties b/org.argeo.slc.jcr/build.properties new file mode 100644 index 000000000..34d2e4d2d --- /dev/null +++ b/org.argeo.slc.jcr/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/org.argeo.slc.jcr/pom.xml b/org.argeo.slc.jcr/pom.xml new file mode 100644 index 000000000..8f34b615b --- /dev/null +++ b/org.argeo.slc.jcr/pom.xml @@ -0,0 +1,59 @@ + + 4.0.0 + + org.argeo.slc + argeo-slc + 2.1.17-SNAPSHOT + .. + + org.argeo.slc.jcr + SLC JCR implementations + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + + + + org.argeo.commons + org.argeo.enterprise + ${version.argeo-commons} + + + org.argeo.commons + org.argeo.node.api + ${version.argeo-commons} + + + org.argeo.commons + org.argeo.cms + ${version.argeo-commons} + + + org.argeo.commons + org.argeo.jcr + ${version.argeo-commons} + + + org.argeo.commons + org.argeo.util + ${version.argeo-commons} + + + + + org.argeo.slc + org.argeo.slc.api + 2.1.17-SNAPSHOT + + + \ No newline at end of file diff --git a/org.argeo.slc.jcr/src/org/argeo/slc/jcr/JcrMetadataWriter.java b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/JcrMetadataWriter.java new file mode 100644 index 000000000..c4922d325 --- /dev/null +++ b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/JcrMetadataWriter.java @@ -0,0 +1,80 @@ +/* + * 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 metadata = new HashMap(); + + 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 metadata) { + this.metadata = metadata; + } + +} diff --git a/org.argeo.slc.jcr/src/org/argeo/slc/jcr/JcrTestResult.java b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/JcrTestResult.java new file mode 100644 index 000000000..3f94b8bcd --- /dev/null +++ b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/JcrTestResult.java @@ -0,0 +1,291 @@ +/* + * 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 attributes = new HashMap(); + + 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 getAttributes() { + Node node = getNode(); + try { + Map map = new HashMap(); + 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 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; + } +} diff --git a/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrConstants.java b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrConstants.java new file mode 100644 index 000000000..3190c85b9 --- /dev/null +++ b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrConstants.java @@ -0,0 +1,29 @@ +/* + * 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; +} diff --git a/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrResultUtils.java b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrResultUtils.java new file mode 100644 index 000000000..6353804df --- /dev/null +++ b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrResultUtils.java @@ -0,0 +1,168 @@ +/* + * 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 diff --git a/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrUtils.java b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrUtils.java new file mode 100644 index 000000000..fcf2e7159 --- /dev/null +++ b/org.argeo.slc.jcr/src/org/argeo/slc/jcr/SlcJcrUtils.java @@ -0,0 +1,268 @@ +/* + * 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 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 diff --git a/org.argeo.slc.repo/pom.xml b/org.argeo.slc.repo/pom.xml index ab207def9..759c61189 100644 --- a/org.argeo.slc.repo/pom.xml +++ b/org.argeo.slc.repo/pom.xml @@ -11,15 +11,15 @@ org.argeo.slc.repo SLC Repo - + org.argeo.slc - org.argeo.slc.support + org.argeo.slc.api 2.1.17-SNAPSHOT org.argeo.slc - org.argeo.slc.core + org.argeo.slc.spring 2.1.17-SNAPSHOT diff --git a/org.argeo.slc.spring/bnd.bnd b/org.argeo.slc.spring/bnd.bnd index fb76254e2..2b27e378d 100644 --- a/org.argeo.slc.spring/bnd.bnd +++ b/org.argeo.slc.spring/bnd.bnd @@ -1,5 +1,6 @@ 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,\ diff --git a/org.argeo.slc.spring/pom.xml b/org.argeo.slc.spring/pom.xml index 29ba3cf97..5462d5446 100644 --- a/org.argeo.slc.spring/pom.xml +++ b/org.argeo.slc.spring/pom.xml @@ -49,12 +49,25 @@ ${version.argeo-commons} + + + org.argeo.commons + org.argeo.osgi.boot + ${version.argeo-commons} + provided + + org.argeo.slc org.argeo.slc.api 2.1.17-SNAPSHOT + + org.argeo.slc + org.argeo.slc.jcr + 2.1.17-SNAPSHOT + @@ -87,6 +100,5 @@ org.argeo.tp.apache.ant org.apache.ant - \ No newline at end of file diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/Attachment.java b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/Attachment.java deleted file mode 100644 index ecde0b936..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/Attachment.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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(); -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentUploader.java b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentUploader.java index eb484c92c..9b91207b3 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentUploader.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentUploader.java @@ -15,6 +15,7 @@ */ package org.argeo.slc.core.attachment; +import org.argeo.slc.attachment.Attachment; import org.springframework.core.io.Resource; public interface AttachmentUploader { diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentsEnabled.java b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentsEnabled.java deleted file mode 100644 index 780a6a483..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentsEnabled.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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); -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentsStorage.java b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentsStorage.java deleted file mode 100644 index 2214afabf..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/AttachmentsStorage.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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); -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/FileAttachmentsStorage.java b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/FileAttachmentsStorage.java index 3b7e62dac..e6bd8e776 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/FileAttachmentsStorage.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/FileAttachmentsStorage.java @@ -30,6 +30,8 @@ import org.apache.commons.io.IOUtils; 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; diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/SimpleAttachment.java b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/SimpleAttachment.java index 6248dd71e..e9a44c959 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/SimpleAttachment.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/core/attachment/SimpleAttachment.java @@ -18,6 +18,8 @@ package org.argeo.slc.core.attachment; 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(); diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/AbstractExecutionValue.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/AbstractExecutionValue.java deleted file mode 100644 index 131ffec75..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/AbstractExecutionValue.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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; -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/AbstractSpecAttribute.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/AbstractSpecAttribute.java deleted file mode 100644 index 109c0335e..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/AbstractSpecAttribute.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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; - } - -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java index beac9175a..41a2f27e9 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java @@ -30,6 +30,11 @@ import org.argeo.slc.execution.ExecutionFlowDescriptorConverter; 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; diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/DefaultExecutionSpec.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/DefaultExecutionSpec.java index 2bce12577..f36a71f73 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/DefaultExecutionSpec.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/DefaultExecutionSpec.java @@ -25,6 +25,8 @@ import org.apache.commons.logging.Log; 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; diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/InstantiationManager.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/InstantiationManager.java index 60e93ec15..211fc4cf9 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/InstantiationManager.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/InstantiationManager.java @@ -22,6 +22,9 @@ import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionSpecAttribute; +import org.argeo.slc.execution.RefSpecAttribute; +import org.argeo.slc.primitive.PrimitiveSpecAttribute; +import org.argeo.slc.primitive.PrimitiveUtils; /** Manage parameters that need to be set during the instantiation of a flow */ public class InstantiationManager { diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveAccessor.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveAccessor.java deleted file mode 100644 index 18d1b9894..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveAccessor.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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); -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java deleted file mode 100644 index fe8412c81..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 : ""); - } - -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveUtils.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveUtils.java deleted file mode 100644 index 4268b8b03..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveUtils.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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; - } - } - -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveValue.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveValue.java deleted file mode 100644 index 3dedb9c22..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/PrimitiveValue.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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; - } - -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefSpecAttribute.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefSpecAttribute.java deleted file mode 100644 index 8e4f617c8..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefSpecAttribute.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 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 getChoices() { - return choices; - } - - public void setChoices(List 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 : ""); - } - -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefValue.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefValue.java deleted file mode 100644 index 0a24bc4b4..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefValue.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 + "]"; - } - -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefValueChoice.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefValueChoice.java deleted file mode 100644 index 5e1f9c2ab..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/RefValueChoice.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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; - } - -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/tasks/UploadAttachments.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/tasks/UploadAttachments.java index 13cc51918..93f27b281 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/tasks/UploadAttachments.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/tasks/UploadAttachments.java @@ -22,9 +22,9 @@ import java.util.Map; 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 { diff --git a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/xml/SpecBeanDefinitionParser.java b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/xml/SpecBeanDefinitionParser.java index 761e26dd1..bb2d24516 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/core/execution/xml/SpecBeanDefinitionParser.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/core/execution/xml/SpecBeanDefinitionParser.java @@ -20,9 +20,9 @@ import java.util.List; 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; diff --git a/org.argeo.slc.spring/src/org/argeo/slc/jcr/JcrMetadataWriter.java b/org.argeo.slc.spring/src/org/argeo/slc/jcr/JcrMetadataWriter.java deleted file mode 100644 index c4922d325..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/jcr/JcrMetadataWriter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 metadata = new HashMap(); - - 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 metadata) { - this.metadata = metadata; - } - -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/jcr/JcrTestResult.java b/org.argeo.slc.spring/src/org/argeo/slc/jcr/JcrTestResult.java deleted file mode 100644 index c9ec874ea..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/jcr/JcrTestResult.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * 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 attributes = new HashMap(); - - 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 getAttributes() { - Node node = getNode(); - try { - Map map = new HashMap(); - 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 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; - } -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrConstants.java b/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrConstants.java deleted file mode 100644 index 3190c85b9..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrConstants.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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; -} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrResultUtils.java b/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrResultUtils.java deleted file mode 100644 index 6353804df..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrResultUtils.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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 diff --git a/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrUtils.java b/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrUtils.java deleted file mode 100644 index 137e298be..000000000 --- a/org.argeo.slc.spring/src/org/argeo/slc/jcr/SlcJcrUtils.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * 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 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 diff --git a/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrAttachmentUploader.java b/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrAttachmentUploader.java index 105d549cd..52ea2801a 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrAttachmentUploader.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrAttachmentUploader.java @@ -17,7 +17,7 @@ package org.argeo.slc.jcr.execution; 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; diff --git a/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java b/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java index 1a2576e06..022dd8721 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java @@ -33,10 +33,6 @@ 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.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; @@ -44,7 +40,11 @@ import org.argeo.slc.execution.ExecutionModulesListener; 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 diff --git a/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrRealizedFlow.java b/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrRealizedFlow.java index c371b1114..5c8738b3f 100644 --- a/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrRealizedFlow.java +++ b/org.argeo.slc.spring/src/org/argeo/slc/jcr/execution/JcrRealizedFlow.java @@ -12,13 +12,13 @@ import org.argeo.slc.SlcException; 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; diff --git a/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractExecutionFlowTestcase.java b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractExecutionFlowTestcase.java new file mode 100644 index 000000000..301846333 --- /dev/null +++ b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractExecutionFlowTestcase.java @@ -0,0 +1,27 @@ +/* + * 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 executeFlow(String flowName) { + ExecutionFlow flow = getBean(flowName); + flow.run(); + return (T) flow; + } +} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractOsgiRuntimeTestCase.java b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractOsgiRuntimeTestCase.java new file mode 100644 index 000000000..7cd14736e --- /dev/null +++ b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractOsgiRuntimeTestCase.java @@ -0,0 +1,246 @@ +/* + * 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 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 getBundlesToStart() { + return new ArrayList(); + } + + 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 getOsgiApplicationContexts() + throws Exception { + Map map = new HashMap(); + 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 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 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 + } + } +} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractSpringTestCase.java b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractSpringTestCase.java new file mode 100644 index 000000000..b6e48fed4 --- /dev/null +++ b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/AbstractSpringTestCase.java @@ -0,0 +1,115 @@ +/* + * 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.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.SlcException; +import org.springframework.beans.factory.BeanFactoryUtils; +import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import junit.framework.TestCase; + +/** Helper for tests using a Spring application co,text. */ +public abstract class AbstractSpringTestCase extends TestCase { + protected final Log log = LogFactory.getLog(getClass()); + private ConfigurableApplicationContext context; + + /** + * Gets (and create if necessary) the application context to use. Default + * implementation uses a class path xml application context and calls + * {@link #getApplicationContextLocation()}. + */ + protected ConfigurableApplicationContext getContext() { + if (context == null) { + context = new ClassPathXmlApplicationContext( + getApplicationContextLocation()); + if (getIsStartContext()) + context.start(); + } + return context; + } + + @Override + protected void tearDown() throws Exception { + if (context != null && context.isActive()) + context.close(); + super.tearDown(); + } + + /** Whether the context should be started after being created. */ + protected Boolean getIsStartContext() { + return false; + } + + /** Returns a bean from the underlying context */ + @SuppressWarnings(value = { "unchecked" }) + protected T getBean(String beanId) { + return (T) getContext().getBean(beanId); + } + + protected T getBean(Class clss) { + T bean = loadSingleFromContext(getContext(), clss); + if (bean == null) { + throw new SlcException("Cannot retrieve a unique bean of type " + + clss); + } else { + return bean; + } + } + + /** + * Th location of the application to load. The default implementation + * returns applicationContext.xml found in the same package as the + * test. + */ + protected String getApplicationContextLocation() { + return inPackage("applicationContext.xml"); + } + + /** + * Prefixes the package of the class after converting the '.' to '/' in + * order to have a resource path. + */ + protected String inPackage(String suffix) { + String prefix = getClass().getPackage().getName().replace('.', '/'); + return prefix + '/' + suffix; + } + + @SuppressWarnings(value = { "unchecked" }) + protected T loadSingleFromContext(ListableBeanFactory context, + Class clss) { + Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( + context, clss, false, false); + if (beans.size() == 1) { + return beans.values().iterator().next(); + } else if (beans.size() > 1) { + if (log.isDebugEnabled()) { + log + .debug(("Found more that on bean for type " + clss + + ": " + beans.keySet())); + } + return null; + } else { + return null; + } + } + +} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/ExecutionFlowDescriptorTestUtils.java b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/ExecutionFlowDescriptorTestUtils.java new file mode 100644 index 000000000..a78662f97 --- /dev/null +++ b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/ExecutionFlowDescriptorTestUtils.java @@ -0,0 +1,73 @@ +/* + * 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 values = new HashMap(); + 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 attributes = new HashMap(); + + 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()); + 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; + } +} diff --git a/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/UnitUtils.java b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/UnitUtils.java new file mode 100644 index 000000000..1eeca0561 --- /dev/null +++ b/org.argeo.slc.spring/src/org/argeo/slc/spring/unit/UnitUtils.java @@ -0,0 +1,57 @@ +/* + * 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 static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertNull; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +public abstract class UnitUtils { + public static void assertDateSec(Date expected, Date reached) { + if (expected == null) { + assertNull(reached); + return; + } else { + assertNotNull(reached); + } + + Calendar expectedCal = new GregorianCalendar(); + expectedCal.setTime(expected); + Calendar reachedCal = new GregorianCalendar(); + reachedCal.setTime(reached); + assertEquals(expectedCal.get(Calendar.YEAR), reachedCal + .get(Calendar.YEAR)); + assertEquals(expectedCal.get(Calendar.MONTH), reachedCal + .get(Calendar.MONTH)); + assertEquals(expectedCal.get(Calendar.DATE), reachedCal + .get(Calendar.DATE)); + assertEquals(expectedCal.get(Calendar.HOUR_OF_DAY), reachedCal + .get(Calendar.HOUR_OF_DAY)); + assertEquals(expectedCal.get(Calendar.MINUTE), reachedCal + .get(Calendar.MINUTE)); + assertEquals(expectedCal.get(Calendar.SECOND), reachedCal + .get(Calendar.SECOND)); + } + + private UnitUtils() { + + } + +} diff --git a/org.argeo.slc.support/pom.xml b/org.argeo.slc.support/pom.xml index b4d091d3f..d9082295d 100644 --- a/org.argeo.slc.support/pom.xml +++ b/org.argeo.slc.support/pom.xml @@ -12,7 +12,7 @@ org.argeo.slc - org.argeo.slc.core + org.argeo.slc.spring 2.1.17-SNAPSHOT diff --git a/org.argeo.slc.unit/pom.xml b/org.argeo.slc.unit/pom.xml index ef9c0e4bc..76563e3d1 100644 --- a/org.argeo.slc.unit/pom.xml +++ b/org.argeo.slc.unit/pom.xml @@ -19,13 +19,13 @@ org.argeo.slc - org.argeo.slc.core - 2.1.17-SNAPSHOT - - - org.argeo.slc - org.argeo.slc.support + org.argeo.slc.api 2.1.17-SNAPSHOT + + + + + \ No newline at end of file diff --git a/org.argeo.slc.unit/src/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java b/org.argeo.slc.unit/src/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java deleted file mode 100644 index 2bcf96029..000000000 --- a/org.argeo.slc.unit/src/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * 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 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 getBundlesToStart() { - return new ArrayList(); - } - - 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 getOsgiApplicationContexts() - throws Exception { - Map map = new HashMap(); - 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 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 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 - } - } -} diff --git a/org.argeo.slc.unit/src/org/argeo/slc/unit/AbstractSpringTestCase.java b/org.argeo.slc.unit/src/org/argeo/slc/unit/AbstractSpringTestCase.java deleted file mode 100644 index 76b7fb660..000000000 --- a/org.argeo.slc.unit/src/org/argeo/slc/unit/AbstractSpringTestCase.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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; - -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.SlcException; -import org.springframework.beans.factory.BeanFactoryUtils; -import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** Helper for tests using a Spring application co,text. */ -public abstract class AbstractSpringTestCase extends TestCase { - protected final Log log = LogFactory.getLog(getClass()); - private ConfigurableApplicationContext context; - - /** - * Gets (and create if necessary) the application context to use. Default - * implementation uses a class path xml application context and calls - * {@link #getApplicationContextLocation()}. - */ - protected ConfigurableApplicationContext getContext() { - if (context == null) { - context = new ClassPathXmlApplicationContext( - getApplicationContextLocation()); - if (getIsStartContext()) - context.start(); - } - return context; - } - - @Override - protected void tearDown() throws Exception { - if (context != null && context.isActive()) - context.close(); - super.tearDown(); - } - - /** Whether the context should be started after being created. */ - protected Boolean getIsStartContext() { - return false; - } - - /** Returns a bean from the underlying context */ - @SuppressWarnings(value = { "unchecked" }) - protected T getBean(String beanId) { - return (T) getContext().getBean(beanId); - } - - protected T getBean(Class clss) { - T bean = loadSingleFromContext(getContext(), clss); - if (bean == null) { - throw new SlcException("Cannot retrieve a unique bean of type " - + clss); - } else { - return bean; - } - } - - /** - * Th location of the application to load. The default implementation - * returns applicationContext.xml found in the same package as the - * test. - */ - protected String getApplicationContextLocation() { - return inPackage("applicationContext.xml"); - } - - /** - * Prefixes the package of the class after converting the '.' to '/' in - * order to have a resource path. - */ - protected String inPackage(String suffix) { - String prefix = getClass().getPackage().getName().replace('.', '/'); - return prefix + '/' + suffix; - } - - @SuppressWarnings(value = { "unchecked" }) - protected T loadSingleFromContext(ListableBeanFactory context, - Class clss) { - Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( - context, clss, false, false); - if (beans.size() == 1) { - return beans.values().iterator().next(); - } else if (beans.size() > 1) { - if (log.isDebugEnabled()) { - log - .debug(("Found more that on bean for type " + clss - + ": " + beans.keySet())); - } - return null; - } else { - return null; - } - } - -} diff --git a/org.argeo.slc.unit/src/org/argeo/slc/unit/UnitUtils.java b/org.argeo.slc.unit/src/org/argeo/slc/unit/UnitUtils.java deleted file mode 100644 index 75cc578e5..000000000 --- a/org.argeo.slc.unit/src/org/argeo/slc/unit/UnitUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -public abstract class UnitUtils { - public static void assertDateSec(Date expected, Date reached) { - if (expected == null) { - assertNull(reached); - return; - } else { - assertNotNull(reached); - } - - Calendar expectedCal = new GregorianCalendar(); - expectedCal.setTime(expected); - Calendar reachedCal = new GregorianCalendar(); - reachedCal.setTime(reached); - assertEquals(expectedCal.get(Calendar.YEAR), reachedCal - .get(Calendar.YEAR)); - assertEquals(expectedCal.get(Calendar.MONTH), reachedCal - .get(Calendar.MONTH)); - assertEquals(expectedCal.get(Calendar.DATE), reachedCal - .get(Calendar.DATE)); - assertEquals(expectedCal.get(Calendar.HOUR_OF_DAY), reachedCal - .get(Calendar.HOUR_OF_DAY)); - assertEquals(expectedCal.get(Calendar.MINUTE), reachedCal - .get(Calendar.MINUTE)); - assertEquals(expectedCal.get(Calendar.SECOND), reachedCal - .get(Calendar.SECOND)); - } - - private UnitUtils() { - - } - -} diff --git a/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java b/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java deleted file mode 100644 index 774ce257d..000000000 --- a/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 executeFlow(String flowName) { - ExecutionFlow flow = getBean(flowName); - flow.run(); - return (T) flow; - } -} diff --git a/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java b/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java deleted file mode 100644 index b8619f4c9..000000000 --- a/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 values = new HashMap(); - 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 attributes = new HashMap(); - - 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()); - 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; - } -} diff --git a/pom.xml b/pom.xml index 6cee4d3e1..98a5e915e 100644 --- a/pom.xml +++ b/pom.xml @@ -23,10 +23,10 @@ org.argeo.slc.api + org.argeo.slc.jcr org.argeo.slc.spring - org.argeo.slc.unit org.argeo.slc.support org.argeo.slc.repo org.argeo.slc.factory