All Downloads are FREE. Search and download functionalities are using the official Maven repository.

step.core.artefacts.AbstractArtefact Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (C) 2020, exense GmbH
 *  
 * This file is part of STEP
 *  
 * STEP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * STEP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *  
 * You should have received a copy of the GNU Affero General Public License
 * along with STEP.  If not, see .
 ******************************************************************************/
package step.core.artefacts;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
import org.bson.types.ObjectId;
import step.core.accessors.AbstractOrganizableObject;
import step.core.accessors.MapDeserializer;
import step.core.accessors.MapSerializer;
import step.core.dynamicbeans.DynamicValue;
import step.core.entities.EntityManager;
import step.core.entities.EntityReference;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@JsonTypeInfo(use=Id.CUSTOM,property= AbstractArtefact.JSON_CLASS_PROPERTY)
@JsonTypeIdResolver(ArtefactTypeIdResolver.class)
public abstract class AbstractArtefact extends AbstractOrganizableObject {

	public static final String JSON_CLASS_PROPERTY = "_class";
	protected DynamicValue dynamicName;

	protected boolean useDynamicName;

	protected String description;
		
	protected List children = new ArrayList<>();
	 
	@JsonSerialize(using = MapSerializer.class)
	@JsonDeserialize(using = MapDeserializer.class) 
	protected Map customAttributes;
	
	protected List attachments;

	private DynamicValue skipNode = new DynamicValue<>(false);
	private DynamicValue instrumentNode = new DynamicValue<>(false);
	private DynamicValue continueParentNodeExecutionOnError = new DynamicValue<>(false);
	private boolean isWorkArtefact = false;
	
	public AbstractArtefact() {
		super();
		Map defaultAttributes = new HashMap<>();
		defaultAttributes.put("name", getArtefactName(this.getClass()));
		attributes = defaultAttributes;
		dynamicName = new DynamicValue("");
		//dynamicName.setDynamic(true);
		dynamicName.setExpression("");
	}
	
	public static String getArtefactName(Class artefactClass) {
		Artefact annotation = artefactClass.getAnnotation(Artefact.class);
		return !annotation.name().isEmpty() ? annotation.name() : artefactClass.getSimpleName();
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@EntityReference(type=EntityManager.recursive)
	public List getChildren() {
		return children;
	}

	public void setChildren(List children) {
		this.children = children;
	}

	public boolean addChild(AbstractArtefact e) {
		return children.add(e);
	}

	public Map getCustomAttributes() {
		return customAttributes;
	}

	public void setCustomAttributes(Map customAttributes) {
		this.customAttributes = customAttributes;
	}

	public Object getCustomAttribute(String key) {
		if(customAttributes!=null) {
			return customAttributes.get(key);
		} else {
			return null;
		}
	}

	public synchronized void addCustomAttribute(String key, Object value) {
		if(customAttributes==null) {
			customAttributes = new HashMap<>();
		}
		customAttributes.put(key, value);
	}
	
	public void addAttachment(ObjectId attachmentId) {
		if(attachments==null) {
			attachments = new ArrayList<>();
		}
		attachments.add(attachmentId);
	}
	
	public void setAttachments(List attachments) {
		this.attachments = attachments;
	}

	public List getAttachments() {
		return attachments;
	}

	@JsonIgnore
	public boolean isCreateSkeleton() {
		return false;
	}
	
	/**
	 * Property artefacts are special artefacts that are directly attached to their
	 * parent artefact. Property artefacts are not subject to transclusion and
	 * remain attached to their parent. They are executed in 2 phases.
	 * 
  • During the first phase the method ArtafactHandler.initProperties is * called for each property artefacts before their parent artefact is * executed.
  • *
  • The second phase starts after execution of the parent artefact. During * the second phase all the property artefact are executed * (ArtafactHandler.execute_)
  • * * @return true if this artefact is a property artefact */ @JsonIgnore public boolean isPropertyArtefact() { return false; } /** * @return true if this Artefact is calling Artefacts from other plans */ @JsonIgnore public boolean isCallingArtefactsFromOtherPlans() { return false; } /** * @deprecated * This field has been deprecated and isn't used anymore. * The getter and setter have been kept in the model to avoid deserialization issues * TODO implement a migration task and remove the getter and setter * @return */ @JsonIgnore @Deprecated public boolean isPersistNode() { return true; } /** * @deprecated * This field has been deprecated and isn't used anymore. * The setter has been kept in the model to avoid deserialization issues * @param persistNode */ @Deprecated public void setPersistNode(boolean persistNode) {} public DynamicValue getSkipNode() { return skipNode; } public void setSkipNode(DynamicValue skipNode) { this.skipNode = skipNode; } public DynamicValue getDynamicName() { return dynamicName; } public void setDynamicName(DynamicValue dynamicName) { this.dynamicName = dynamicName; } public boolean isUseDynamicName() { return useDynamicName; } public void setUseDynamicName(boolean useDynamicName) { this.useDynamicName = useDynamicName; } public void deepCleanupAllCustomAttributes() { if (getCustomAttributes() != null) { getCustomAttributes().clear(); } List children = getChildren(); if (children != null) { for (AbstractArtefact child : children) { // repeat recursively for all children child.deepCleanupAllCustomAttributes(); } } } public DynamicValue getInstrumentNode() { return instrumentNode; } public void setInstrumentNode(DynamicValue instrumentNode) { this.instrumentNode = instrumentNode; } public DynamicValue getContinueParentNodeExecutionOnError() { return continueParentNodeExecutionOnError; } public void setContinueParentNodeExecutionOnError(DynamicValue continueOnError) { this.continueParentNodeExecutionOnError = continueOnError; } @JsonIgnore public boolean isWorkArtefact() { return isWorkArtefact; } public void setWorkArtefact(boolean workArtefact) { isWorkArtefact = workArtefact; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AbstractArtefact other = (AbstractArtefact) obj; if (getId() == null) { if (other.getId() != null) return false; } else if (!getId().equals(other.getId())) return false; return true; } /** * Void class to be used in annotations instead of null-values */ public static final class None extends AbstractArtefact {} }




    © 2015 - 2025 Weber Informatics LLC | Privacy Policy