Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

1. Welche Status durchläuft das Entity "Contract"? Zeichnen Sie das Statusdiagramm. 

Image Added

2. Implementieren Sie das Entity mit der Statusfolge.

ACHTUNG - ungetesteter Code, nur als Anhaltspunkt zu verstehen!


package thkoeln.archilab.exercises.chargingstation;

public enum ContractStatusType {
REQUESTED,
OFFERED,
ACCEPTED,
REJECTED,
IN_PLANNING,
PLANNED,
READY_TO_BUILD
}

package thkoeln.archilab.exercises.chargingstation;

public interface CustomerActivities {
public void accept();
public void reject();
}


package thkoeln.archilab.exercises.chargingstation;

public interface SalesPersonActivities {
public void updatePricing( Double price );
public void handOverToPlanning();
public void checkPlan( Boolean priceIsStillOK );
}


package thkoeln.archilab.exercises.chargingstation;

public interface EngineerActivities {
public void providePlan( Plan plan );
}


package thkoeln.archilab.exercises.chargingstation;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.ManyToOne;

import static thkoeln.archilab.exercises.chargingstation.ContractStatusType.*;

import java.util.Date;

@Getter
@NoArgsConstructor
public class Contract implements CustomerActivities, EngineerActivities, SalesPersonActivities {

@Setter
private String details;

private Double price;
private Boolean customerHasAccepted;
private Boolean handedOverToPlanning = Boolean.FALSE;
private Boolean priceIsStillOK = Boolean.FALSE;

@Setter
@ManyToOne
private Plan plan;

private Date date = new Date();

public ContractStatusType state() {
if( priceIsStillOK ) return READY_TO_BUILD;
if( plan != null ) return PLANNED;
if( handedOverToPlanning ) return IN_PLANNING;
if( customerHasAccepted != null ) {
return customerHasAccepted ? ACCEPTED : REJECTED;
}
if( price != null ) return OFFERED;
return REQUESTED;
}

@Override
public void accept() {
// todo - throw exception(s) when called in the wrong state
customerHasAccepted = Boolean.TRUE;
}

@Override
public void reject() {
// todo - throw exception(s) when called in the wrong state
customerHasAccepted = Boolean.TRUE;
}

@Override
public void providePlan(Plan plan) {
// todo - throw exception(s) when called in the wrong state
this.plan = plan;
}

@Override
public void updatePricing(Double price) {
// todo - throw exception(s) when called in the wrong state
this.price = price;
}

@Override
public void handOverToPlanning() {
// todo - throw exception(s) when called in the wrong state
this.handedOverToPlanning = Boolean.TRUE;
}

@Override
public void checkPlan(Boolean priceIsStillOK) {
// todo - throw exception(s) when called in the wrong state
this.priceIsStillOK = priceIsStillOK;
}
}