WorkflowStepDTO.java
/*
* Copyright 2024 Global Crop Diversity Trust
*
* 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.gringlobal.api.model;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.genesys.blocks.util.JsonClassNameWriter;
import org.gringlobal.custom.json.CustomTypeIdResolver;
import org.gringlobal.custom.validation.javax.PeriodExpressionValidation;
import javax.validation.constraints.Size;
import java.util.HashMap;
import java.util.Map;
@Data
@EqualsAndHashCode(callSuper = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "_class")
@JsonTypeIdResolver(WorkflowStepDTO.WorkflowStepDTOTypeIdResolver.class)
/* @formatter:off */
@JsonAppend(props = {
@JsonAppend.Prop(name = "_class", value = JsonClassNameWriter.class, type = String.class),
})
/* @formatter:on */
@Schema(name = "WorkflowStep")
public abstract class WorkflowStepDTO extends CooperatorOwnedDTO {
private WorkflowInfo workflow;
@Data
@EqualsAndHashCode(callSuper = true)
public static class WorkflowStartStepDTO extends WorkflowStepDTO {
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class WorkflowEndStepDTO extends WorkflowStepDTO {
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class WorkflowActionStepDTO extends WorkflowStepDTO {
private String actionNameCode;
private AclSidInfo actionAssignee;
@Size(max = 20)
@PeriodExpressionValidation
private String delay;
}
public static class WorkflowStepDTOTypeIdResolver extends CustomTypeIdResolver {
@Override
protected Map<String, Class<?>> initClassesMap() {
Map<String, Class<?>> classes = new HashMap<>();
classes.put(WorkflowStartStepDTO.class.getSimpleName(), WorkflowStartStepDTO.class);
classes.put(WorkflowActionStepDTO.class.getSimpleName(), WorkflowActionStepDTO.class);
classes.put(WorkflowEndStepDTO.class.getSimpleName(), WorkflowEndStepDTO.class);
return classes;
}
}
}