Vy Le
Vy Le

Reputation: 41

How do I condition which @InverseRelationShadowVariable obj assigned to my Task? Ex: Machine cut4building A.B will be assigned to Tasks building B & A

Here is my Task class. Machine was an Inverse Shadow Variable. Once it assigned, its value like Shifts will be used to automate StartTime and EndTime in automatePlanTime method.

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
@PlanningEntity
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class Task {

    @PlanningId
    private String id;

    // TODO: @CascadingUpdateShadowVariable(targetMethodName = "automateSetMachine") -> is this possible?
    @InverseRelationShadowVariable(sourceVariableName = "tasks")
    private Machine machine;

    @JsonIgnore
    @PreviousElementShadowVariable(sourceVariableName = "tasks")
    private Task previousTask;
    @JsonIgnore
    @NextElementShadowVariable(sourceVariableName = "tasks")
    private Task nextTask;

   @CascadingUpdateShadowVariable(targetMethodName = "automatePlanTime")
   @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
   @JsonDeserialize(using = LocalDateTimeDeserializer.class)
   @JsonSerialize(using = LocalDateTimeSerializer.class)
   private LocalDateTime startTime;

    @CascadingUpdateShadowVariable(targetMethodName = "automatePlanTime")
   @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
   @JsonDeserialize(using = LocalDateTimeDeserializer.class)
   @JsonSerialize(using = LocalDateTimeSerializer.class)
   private LocalDateTime endTime;

  private String building; private String factory;

   @JsonIgnore
    public void automatePlanTime() {
        if (previousTask == null && machine == null) {
            startTime = null;
            endTime = null;
            return;
        }
        // logic here
      }
}

Here is the Machine class. Machine in cut for building A,B will be assigned to tasks from building A and B (my tasks will belong to building A,B,C,D,E,F)

@PlanningEntity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Machine {

    @PlanningId
    private String id;

    private String cutForBuildings; // A,B

    private String factory;
    private String building;
    private String machineName;

    @JsonIgnore
    private List<ShiftEntity> shifts;

   @JsonIgnore
    @PlanningListVariable
    private List<Task> tasks = new ArrayList<>();


I want another @CascadingUpdateShadowVariable(targetMethodName = "assignMachine") If I use it. Will it affect method automatePlanTime? In the past, when use VariableListener for Machine, I got an error.

I'm unable to test @CascadingUpdateShadowVariable(targetMethodName = "automateSetMachine"). I will update later after test and share the error if possible.

Upvotes: 0

Views: 36

Answers (0)

Related Questions