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());
}
}
}
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);
}
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);
}
}
Aggregations