use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.
the class TreeComponentState method getFieldValue.
@Override
public Object getFieldValue() {
if (treeStructure == null) {
return null;
}
if (treeStructure.length() == 0) {
return new ArrayList<Entity>();
}
if (treeStructure.length() > 1) {
addMessage("qcadooView.validate.field.error.multipleRoots", MessageType.FAILURE);
return null;
}
Entity entity = belongsToFieldDefinition.getDataDefinition().get(belongsToEntityId);
EntityTree tree = entity.getTreeField(belongsToFieldDefinition.getName());
nodes = new HashMap<Long, Entity>();
for (Entity node : tree) {
node.setField(CHILDREN, new ArrayList<Entity>());
node.setField("parent", null);
nodes.put(node.getId(), node);
}
try {
Entity parent = nodes.get(treeStructure.getJSONObject(0).getLong("id"));
if (treeStructure.getJSONObject(0).has(CHILDREN)) {
reorganize(parent, treeStructure.getJSONObject(0).getJSONArray(CHILDREN), Lists.newLinkedList(Lists.newArrayList(INITIAL_NODE_NUMBER_VALUE)));
}
return Collections.singletonList(parent);
} catch (JSONException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class SubassemblyDetailsListenersPL method generateFactoryStructure.
public void generateFactoryStructure(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity subassembly = form.getEntity();
EntityTree structure = factoryStructureGenerationService.generateFactoryStructureForSubassembly(subassembly);
subassembly.setField(WorkstationFieldsPL.FACTORY_STRUCTURE, structure);
form.setEntity(subassembly);
WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
window.setActiveTab("factoryStructureTab");
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class WorkstationDetailsListenersPL method generateFactoryStructure.
public void generateFactoryStructure(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity workstation = form.getEntity();
EntityTree structure = factoryStructureGenerationService.generateFactoryStructureForWorkstation(workstation);
workstation.setField(WorkstationFieldsPL.FACTORY_STRUCTURE, structure);
form.setEntity(workstation);
WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
window.setActiveTab("factoryStructureTab");
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class DailyProgressService method getDailyProgressesWithTrackingRecords.
/**
* Creates map of daily progresses with accepted production tracking records only, and fills keys with quantity produced in
* that record
*
* @param pps
* @return
*/
public Map<DailyProgressKey, Entity> getDailyProgressesWithTrackingRecords(final Entity pps) {
Map<DailyProgressKey, Entity> dailyProgresses = Maps.newHashMap();
Entity order = pps.getBelongsToField(ProductionPerShiftFields.ORDER);
Entity product = order.getBelongsToField(OrderFields.PRODUCT);
String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
Entity toc = null;
if (TypeOfProductionRecording.FOR_EACH.getStringValue().equals(typeOfProductionRecording)) {
Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
EntityTree operationsTree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
toc = operationsTree.getRoot();
}
List<Entity> mainOutProductComponents = getMainOutProductComponentsForOrderAndProduct(order, toc, product);
for (Entity outProduct : mainOutProductComponents) {
Entity trackingRecord = outProduct.getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCTION_TRACKING);
Long shiftId = trackingRecord.getBelongsToField(ProductionTrackingFields.SHIFT).getId();
Date startDate = trackingRecord.getDateField(ProductionTrackingFields.SHIFT_START_DAY);
Optional<Entity> dailyProgress = findDailyProgress(pps, shiftId, startDate);
DailyProgressKey key = new DailyProgressKey(outProduct.getDecimalField(TrackingOperationProductOutComponentFields.USED_QUANTITY), shiftId, startDate);
if (dailyProgress.isPresent()) {
Entity entity = dailyProgress.get();
entity.setField(DailyProgressFields.QUANTITY, key.getQuantity());
dailyProgresses.put(key, entity);
}
}
return dailyProgresses;
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class ProductQuantitiesServiceImpl method getProductComponentWithQuantitiesForTechnology.
@Override
public OperationProductComponentWithQuantityContainer getProductComponentWithQuantitiesForTechnology(final Entity technology, final Entity orderedProduct, final BigDecimal givenQuantity, final Map<Long, BigDecimal> operationRuns, final Set<OperationProductComponentHolder> nonComponents) {
OperationProductComponentWithQuantityContainer operationProductComponentWithQuantityContainer = new OperationProductComponentWithQuantityContainer();
operationProductComponentWithQuantityContainer.setOrderedProduct(orderedProduct);
if (Objects.nonNull(orderedProduct)) {
Entity size = orderedProduct.getBelongsToField(ProductFields.SIZE);
if (Objects.nonNull(size)) {
List<Entity> sizeGroups = size.getHasManyField(SizeFields.SIZE_GROUPS);
if (!sizeGroups.isEmpty()) {
operationProductComponentWithQuantityContainer.setSizeGroups(sizeGroups);
}
}
}
EntityTree operationComponents = getOperationComponentsFromTechnology(technology);
Entity root = operationComponents.getRoot();
if (Objects.nonNull(root)) {
preloadProductQuantitiesAndOperationRuns(operationComponents, operationProductComponentWithQuantityContainer, operationRuns);
traverseProductQuantitiesAndOperationRuns(technology, givenQuantity, root, null, operationProductComponentWithQuantityContainer, nonComponents, operationRuns);
}
return operationProductComponentWithQuantityContainer;
}
Aggregations