use of com.qcadoo.mes.states.service.client.util.ViewContextHolder in project mes by qcadoo.
the class ChangeTechnologyParametersListeners method createCustomizedTechnologies.
@Transactional
private void createCustomizedTechnologies(ViewDefinitionState view, ComponentState state, Set<Long> ids, Entity entity, Entity finalGroup, BigDecimal finalStandardPerformance) {
boolean updateOperationTimeNorms = entity.getBooleanField(L_UPDATE_OPERATION_TIME_NORMS);
ids.forEach(techId -> {
Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).get(techId);
technology.setField(TechnologyFields.MASTER, Boolean.FALSE);
technology = technology.getDataDefinition().save(technology);
if (technology.isValid()) {
Entity copyTechnology = technology.getDataDefinition().copy(technology.getId()).get(0);
Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
copyTechnology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
copyTechnology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
if (entity.getBooleanField(L_CHANGE_GROUP)) {
copyTechnology.setField(TechnologyFields.TECHNOLOGY_GROUP, finalGroup);
}
if (entity.getBooleanField(L_CHANGE_PERFORMANCE_NORM)) {
technologyService.getMasterTechnologyProductionLine(copyTechnology).ifPresent(e -> {
e.setField(TechnologyProductionLineFields.STANDARD_PERFORMANCE, finalStandardPerformance);
e.getDataDefinition().save(e);
});
}
copyTechnology = copyTechnology.getDataDefinition().save(copyTechnology);
Entity copyTechnologyDb = copyTechnology.getDataDefinition().get(copyTechnology.getId());
if (updateOperationTimeNorms) {
List<Entity> tocs = copyTechnologyDb.getHasManyField(TechnologyFields.OPERATION_COMPONENTS);
tocs.forEach(toc -> {
Entity operation = toc.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
for (String fieldName : FIELDS_OPERATION) {
toc.setField(fieldName, operation.getField(fieldName));
}
if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_TYPE) == null) {
toc.setField(NEXT_OPERATION_AFTER_PRODUCED_TYPE, "01all");
}
if (operation.getField(PRODUCTION_IN_ONE_CYCLE) == null) {
toc.setField(PRODUCTION_IN_ONE_CYCLE, "1");
}
if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY) == null) {
toc.setField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY, "0");
}
copyOperationWorkstationTimes(toc, operation);
toc.getDataDefinition().save(toc);
});
}
technologyStateChangeViewClient.changeState(new ViewContextHolder(view, state), TechnologyStateStringValues.OUTDATED, technology);
Entity savedTech = copyTechnologyDb.getDataDefinition().get(copyTechnologyDb.getId());
if (savedTech.isValid()) {
technologyStateChangeViewClient.changeState(new ViewContextHolder(view, state), TechnologyStateStringValues.ACCEPTED, savedTech);
Entity tech = savedTech.getDataDefinition().get(savedTech.getId());
tech.setField(TechnologyFields.MASTER, Boolean.TRUE);
tech.getDataDefinition().save(tech);
} else {
throw new IllegalStateException("There was a problem creating the technology");
}
} else {
throw new IllegalStateException("There was a problem creating the technology");
}
});
}
use of com.qcadoo.mes.states.service.client.util.ViewContextHolder in project mes by qcadoo.
the class ModifyTechnologyListeners method customizeTechnology.
@Transactional
private void customizeTechnology(final ViewDefinitionState view, final ComponentState state, Entity technology, List<Entity> entries, Entity mt, ModifyTechnologyResult modifyTechnologyResult) {
technology.setField(TechnologyFields.MASTER, Boolean.FALSE);
technology = technology.getDataDefinition().save(technology);
if (technology.isValid()) {
Entity copyTechnology = technology.getDataDefinition().copy(technology.getId()).get(0);
Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
copyTechnology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
copyTechnology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
copyTechnology = copyTechnology.getDataDefinition().save(copyTechnology);
for (Entity entry : entries) {
modifyOperation(mt, copyTechnology, entry);
}
copyTechnology = copyTechnology.getDataDefinition().get(copyTechnology.getId());
technologyStateChangeViewClient.changeState(new ViewContextHolder(view, state), TechnologyStateStringValues.ACCEPTED, copyTechnology);
Entity tech = copyTechnology.getDataDefinition().get(copyTechnology.getId());
tech.setField(TechnologyFields.MASTER, Boolean.TRUE);
tech.getDataDefinition().save(tech);
modifyTechnologyResult.addCreatedTechnology(tech.getStringField(TechnologyFields.NUMBER));
} else {
throw new IllegalStateException("There was a problem creating the technology");
}
}
use of com.qcadoo.mes.states.service.client.util.ViewContextHolder in project mes by qcadoo.
the class MaintenanceEventToPlannedEventListeners method continueStateChange.
public void continueStateChange(final ViewDefinitionState view, final ComponentState component, final String[] args) {
final FormComponent form = (FormComponent) component;
Entity eventStateChange = form.getPersistedEntityWithIncludedFormValues();
maintenanceEventStateChangeValidators.validate(eventStateChange.getDataDefinition(), eventStateChange);
form.setEntity(eventStateChange);
if (!eventStateChange.getErrors().isEmpty()) {
return;
}
form.performEvent(view, "save");
if (!form.isValid()) {
return;
}
final Entity stateChangeEntity = ((FormComponent) form).getEntity();
final String plannedEventType = stateChangeEntity.getStringField(MaintenanceEventStateChangeFields.PLANNED_EVENT_TYPE);
final StateChangeContext stateContext = stateChangeContextBuilder.build(maintenanceEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
if (plannedEventType.isEmpty()) {
stateContext.setStatus(StateChangeStatus.FAILURE);
stateContext.addFieldMessage("cmmsMachineParts.maintenanceEventStateChange.plannedEventType.required", StateMessageType.FAILURE, MaintenanceEventStateChangeFields.PLANNED_EVENT_TYPE);
stateContext.save();
maintenanceEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
return;
}
String plannedEventCorrect = createPlannedEvent(stateChangeEntity, plannedEventType);
if (!StringUtils.isEmpty(plannedEventCorrect)) {
stateContext.setStatus(StateChangeStatus.IN_PROGRESS);
stateContext.addMessage("cmmsMachineParts.maintenanceEventStateChange.success.plannedEventCreated", StateMessageType.INFO, plannedEventCorrect);
maintenanceEventStateChangeAspect.changeState(stateContext);
maintenanceEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
} else {
stateContext.setStatus(StateChangeStatus.FAILURE);
stateContext.addMessage("cmmsMachineParts.maintenanceEventStateChange.error.plannedEventNotCreated", StateMessageType.FAILURE);
stateContext.save();
maintenanceEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
}
}
use of com.qcadoo.mes.states.service.client.util.ViewContextHolder in project mes by qcadoo.
the class PlannedEventReasonViewListeners method cancelStateChange.
public void cancelStateChange(final ViewDefinitionState view, final ComponentState form, final String[] args) {
final Entity stateChangeEntity = ((FormComponent) form).getEntity();
stateChangeEntity.setField(PlannedEventStateChangeFields.COMMENT_REQUIRED, false);
final StateChangeContext stateContext = stateChangeContextBuilder.build(plannedEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
stateContext.setStatus(StateChangeStatus.CANCELED);
stateContext.save();
plannedEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
}
use of com.qcadoo.mes.states.service.client.util.ViewContextHolder in project mes by qcadoo.
the class PlannedEventReasonViewListeners method continueStateChange.
public void continueStateChange(final ViewDefinitionState view, final ComponentState component, final String[] args) {
final FormComponent form = (FormComponent) component;
Entity eventStateChange = form.getPersistedEntityWithIncludedFormValues();
plannedEventStateChangeValidators.validate(eventStateChange.getDataDefinition(), eventStateChange);
form.setEntity(eventStateChange);
if (!eventStateChange.getErrors().isEmpty()) {
return;
}
form.performEvent(view, "save");
if (!form.isValid()) {
return;
}
final Entity stateChangeEntity = ((FormComponent) form).getEntity();
final StateChangeContext stateContext = stateChangeContextBuilder.build(plannedEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
stateContext.setStatus(StateChangeStatus.IN_PROGRESS);
plannedEventStateChangeAspect.changeState(stateContext);
plannedEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
}
Aggregations