use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class EventListeners method addEvent.
public void addEvent(final ViewDefinitionState viewDefinitionState, final ComponentState triggerState, final String[] args) {
String eventType = args[0];
factoryStructureId = Long.parseLong(args[1]);
EntityTree tree = factoryStructureForEventHooks.getGeneratedTree();
Optional<Entity> maybeElement = tree.stream().filter(element -> element.getId() == factoryStructureId).findFirst();
if (!maybeElement.isPresent()) {
viewDefinitionState.addMessage("cmmsMachineParts.error.elementNotSelected", ComponentState.MessageType.FAILURE);
return;
}
Entity selectedElement = maybeElement.get();
FactoryStructureElementType elementType = FactoryStructureElementType.of(selectedElement);
if (elementType.compareTo(FactoryStructureElementType.COMPANY) == 0) {
viewDefinitionState.addMessage("cmmsMachineParts.error.companySelected", ComponentState.MessageType.INFO);
return;
}
if (elementType.compareTo(FactoryStructureElementType.FACTORY) == 0) {
viewDefinitionState.addMessage("cmmsMachineParts.error.factorySelected", ComponentState.MessageType.INFO);
return;
}
DataDefinition dataDefinition = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT);
Entity maintenanceEvent = dataDefinition.create();
if (elementType.compareTo(FactoryStructureElementType.DIVISION) == 0 || elementType.compareTo(FactoryStructureElementType.PRODUCTION_LINE) == 0 || MaintenanceEventType.parseString(eventType).compareTo(MaintenanceEventType.PROPOSAL) == 0) {
maintenanceEvent.setField(MaintenanceEventFields.FAULT_TYPE, faultTypesService.getDefaultFaultType());
}
fillEventFieldsFromSelectedElement(maintenanceEvent, selectedElement);
maintenanceEvent.setField(MaintenanceEventFields.TYPE, eventType);
maintenanceEvent = dataDefinition.save(maintenanceEvent);
Map<String, Object> parameters = Maps.newHashMap();
parameters.put("form.id", maintenanceEvent.getId());
viewDefinitionState.redirectTo("../page/" + CmmsMachinePartsConstants.PLUGIN_IDENTIFIER + "/maintenanceEventDetails.html", false, true, parameters);
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class MatchingChangeoverNormsDetailsHooks method setFieldsVisible.
public void setFieldsVisible(final ViewDefinitionState view) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
ComponentState matchingNorm = view.getComponentByReference("matchingNorm");
ComponentState matchingNormNotFound = view.getComponentByReference("matchingNormNotFound");
if (form.getEntityId() == null) {
matchingNorm.setVisible(false);
matchingNormNotFound.setVisible(true);
} else {
matchingNorm.setVisible(true);
matchingNormNotFound.setVisible(false);
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class DivisionDetailsListenersPL method onRemoveSelectedProductionLines.
public void onRemoveSelectedProductionLines(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent productionLinesGrid = (GridComponent) view.getComponentByReference("productionLines");
List<Entity> productionLinesToDelete = productionLinesGrid.getSelectedEntities();
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Long divisionId = form.getEntityId();
for (Entity productionLine : productionLinesToDelete) {
List<Entity> workstations = productionLine.getHasManyField(ProductionLineFields.WORKSTATIONS);
workstations.stream().filter(workstation -> workstation.getBelongsToField(WorkstationFields.DIVISION).getId().equals(divisionId)).forEach(workstation -> {
workstation.setField(WorkstationFieldsPL.PRODUCTION_LINE, null);
workstation.setField(WorkstationFields.DIVISION, null);
workstation.getDataDefinition().save(workstation);
});
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class ProductionLineDetailsListeners method onRemoveSelectedDivisions.
public void onRemoveSelectedDivisions(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent divisionsGrid = (GridComponent) view.getComponentByReference("divisions");
List<Entity> divisionsToDelete = divisionsGrid.getSelectedEntities();
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Long productionLineId = form.getEntityId();
for (Entity division : divisionsToDelete) {
List<Entity> workstations = division.getHasManyField(DivisionFields.WORKSTATIONS);
workstations.stream().filter(workstation -> workstation.getBelongsToField(WorkstationFieldsPL.PRODUCTION_LINE).getId().equals(productionLineId)).forEach(workstation -> {
workstation.setField(WorkstationFieldsPL.PRODUCTION_LINE, null);
workstation.setField(WorkstationFields.DIVISION, null);
workstation.getDataDefinition().save(workstation);
});
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class ScheduleDetailsListenersPS method assignOperationsToWorkstations.
@Transactional
public void assignOperationsToWorkstations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
Entity schedule = ((FormComponent) state).getEntity();
Map<Long, Date> workstationsFinishDates = Maps.newHashMap();
Set<Long> ordersToAvoid = Sets.newHashSet();
List<Long> positionsIds = sortPositionsForWorkstations(schedule.getId());
Date scheduleStartTime = schedule.getDateField(ScheduleFields.START_TIME);
for (Long positionId : positionsIds) {
Entity position = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_SCHEDULE_POSITION).get(positionId);
if (ordersToAvoid.contains(position.getBelongsToField(SchedulePositionFields.ORDER).getId())) {
continue;
}
List<Entity> workstations = getWorkstationsFromTOC(position);
if (workstations.isEmpty()) {
ordersToAvoid.add(position.getBelongsToField(SchedulePositionFields.ORDER).getId());
continue;
}
Map<Long, PositionNewData> operationWorkstationsPositionNewData = Maps.newHashMap();
boolean allMachineWorkTimesEqualsZero = getWorkstationsNewFinishDate(workstationsFinishDates, scheduleStartTime, position, workstations, operationWorkstationsPositionNewData);
if (allMachineWorkTimesEqualsZero) {
ordersToAvoid.add(position.getBelongsToField(SchedulePositionFields.ORDER).getId());
continue;
}
if (ScheduleWorkstationAssignCriterion.SHORTEST_TIME.getStringValue().equals(schedule.getStringField(ScheduleFields.WORKSTATION_ASSIGN_CRITERION))) {
operationWorkstationsPositionNewData.entrySet().stream().min(Comparator.comparing(e -> e.getValue().getFinishDate())).ifPresent(entry -> updatePositionWorkstationAndDates(entry, workstationsFinishDates, position));
} else {
Map.Entry<Long, PositionNewData> firstEntry;
if (workstationsFinishDates.isEmpty()) {
firstEntry = operationWorkstationsPositionNewData.entrySet().iterator().next();
} else {
firstEntry = operationWorkstationsPositionNewData.entrySet().stream().filter(entry -> workstationsFinishDates.containsKey(entry.getKey())).findFirst().orElse(operationWorkstationsPositionNewData.entrySet().iterator().next());
}
updatePositionWorkstationAndDates(firstEntry, workstationsFinishDates, position);
}
}
}
Aggregations