Search in sources :

Example 1 with RunForStateTransitions

use of com.qcadoo.mes.states.annotation.RunForStateTransitions in project mes by qcadoo.

the class TechnologyProductStructureDeletingAspect method postHookOnDraft.

@RunInPhase(TechnologyStateChangePhase.LAST)
@RunForStateTransitions({ @RunForStateTransition(targetState = TechnologyStateStringValues.DRAFT) })
@After(PHASE_EXECUTION_POINTCUT)
public void postHookOnDraft(final StateChangeContext stateChangeContext, final int phase) {
    Entity technology = stateChangeContext.getOwner();
    Entity technologyFromDB = technology.getDataDefinition().get(technology.getId());
    EntityTree tree = technologyFromDB.getTreeField(TechnologyFields.PRODUCT_STRUCTURE_TREE);
    if (tree.getRoot() != null) {
        List<Entity> treeEntities = tree.find().list().getEntities();
        for (Entity entity : treeEntities) {
            entity.getDataDefinition().delete(entity.getId());
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) After(org.aspectj.lang.annotation.After) RunInPhase(com.qcadoo.mes.states.annotation.RunInPhase) RunForStateTransitions(com.qcadoo.mes.states.annotation.RunForStateTransitions)

Example 2 with RunForStateTransitions

use of com.qcadoo.mes.states.annotation.RunForStateTransitions in project mes by qcadoo.

the class DeliveryStateValidationAspectTest method shouldPreValidationOnReceivedMethodBeCorrectlyAnnotated.

@Test
public final void shouldPreValidationOnReceivedMethodBeCorrectlyAnnotated() throws SecurityException, NoSuchMethodException {
    Method preValidationOnReceive = clazz.getMethod("preValidationOnReceived", StateChangeContext.class, int.class);
    assertNotNull(preValidationOnReceive);
    RunForStateTransitions transitions = preValidationOnReceive.getAnnotation(RunForStateTransitions.class);
    assertNotNull(transitions);
    assertEquals(2, transitions.value().length);
    RunForStateTransition firstTransition = transitions.value()[0];
    assertEquals(firstTransition.sourceState(), DeliveryStateStringValues.APPROVED);
    assertEquals(firstTransition.targetState(), DeliveryStateStringValues.RECEIVED);
    RunForStateTransition secondTransition = transitions.value()[1];
    assertEquals(secondTransition.sourceState(), DeliveryStateStringValues.APPROVED);
    assertEquals(secondTransition.targetState(), DeliveryStateStringValues.RECEIVE_CONFIRM_WAITING);
    RunInPhase runInPhase = preValidationOnReceive.getAnnotation(RunInPhase.class);
    assertNotNull(runInPhase);
    assertEquals(DeliveryStateChangePhase.PRE_VALIDATION, runInPhase.value()[0]);
    Before before = preValidationOnReceive.getAnnotation(Before.class);
    assertNotNull(before);
}
Also used : Before(org.aspectj.lang.annotation.Before) RunForStateTransition(com.qcadoo.mes.states.annotation.RunForStateTransition) RunInPhase(com.qcadoo.mes.states.annotation.RunInPhase) Method(java.lang.reflect.Method) RunForStateTransitions(com.qcadoo.mes.states.annotation.RunForStateTransitions) Test(org.junit.Test)

Example 3 with RunForStateTransitions

use of com.qcadoo.mes.states.annotation.RunForStateTransitions in project mes by qcadoo.

the class TechnologyValidationAspect method preValidationOnAcceptingOrChecking.

@RunInPhase(TechnologyStateChangePhase.PRE_VALIDATION)
@RunForStateTransitions({ @RunForStateTransition(targetState = TechnologyStateStringValues.ACCEPTED), @RunForStateTransition(targetState = TechnologyStateStringValues.CHECKED) })
@Before(PHASE_EXECUTION_POINTCUT)
public void preValidationOnAcceptingOrChecking(final StateChangeContext stateChangeContext, final int phase) {
    if (!technologyValidationService.checkIfTechnologyTreeIsSet(stateChangeContext)) {
        return;
    }
    if (!technologyValidationService.checkIfEveryInComponentsHasQuantities(stateChangeContext)) {
        return;
    }
    if (!technologyValidationService.checkIfWasteProductsIsRightMarked(stateChangeContext)) {
        return;
    }
    Entity technology = stateChangeContext.getOwner();
    String targetState = stateChangeContext.getStateChangeEntity().getStringField(TechnologyStateChangeFields.TARGET_STATE);
    Entity parameter = parameterService.getParameter();
    if (parameter.getBooleanField(ParameterFieldsT.MOVE_PRODUCTS_TO_SUBSEQUENT_OPERATIONS)) {
        technologyDetailsListeners.fillProducts(technology);
    }
    if (TechnologyStateStringValues.ACCEPTED.equals(targetState) || (TechnologyStateStringValues.CHECKED.equals(targetState) && !parameter.getBooleanField(ParameterFieldsT.ALLOW_CHECKED_TECHNOLOGY_WITHOUT_IN_PRODUCTS))) {
        technologyValidationService.checkIfEveryOperationHasInComponents(stateChangeContext);
    }
    technologyValidationService.checkConsumingManyProductsFromOneSubOp(stateChangeContext);
    technologyTreeValidators.checkConsumingTheSameProductFromManySubOperations(technology.getDataDefinition(), technology, true);
    technologyValidationService.checkIfTechnologyHasAtLeastOneComponent(stateChangeContext);
    technologyValidationService.checkTopComponentsProducesProductForTechnology(stateChangeContext);
    technologyValidationService.checkIfOperationsUsesSubOperationsProds(stateChangeContext);
    technologyValidationService.checkTechnologyCycles(stateChangeContext);
    if (TechnologyStateStringValues.ACCEPTED.equals(targetState)) {
        technologyValidationService.checkDifferentProductsInDifferentSizes(stateChangeContext);
    }
    if (PluginUtils.isEnabled("timeNormsForOperations")) {
        technologyValidationService.checkIfTreeOperationIsValid(stateChangeContext);
    }
    if (parameter.getBooleanField(ParameterFieldsT.CHECK_FOR_THE_EXISTENCE_OF_INPUT_PRODUCT_PRICES)) {
        technologyValidationService.checkIfInputProductPricesSet(stateChangeContext);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) Before(org.aspectj.lang.annotation.Before) RunInPhase(com.qcadoo.mes.states.annotation.RunInPhase) RunForStateTransitions(com.qcadoo.mes.states.annotation.RunForStateTransitions)

Aggregations

RunForStateTransitions (com.qcadoo.mes.states.annotation.RunForStateTransitions)3 RunInPhase (com.qcadoo.mes.states.annotation.RunInPhase)3 Entity (com.qcadoo.model.api.Entity)2 Before (org.aspectj.lang.annotation.Before)2 RunForStateTransition (com.qcadoo.mes.states.annotation.RunForStateTransition)1 EntityTree (com.qcadoo.model.api.EntityTree)1 Method (java.lang.reflect.Method)1 After (org.aspectj.lang.annotation.After)1 Test (org.junit.Test)1