Search in sources :

Example 6 with EntityTree

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);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) EntityTree(com.qcadoo.model.api.EntityTree)

Example 7 with EntityTree

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");
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) WindowComponent(com.qcadoo.view.api.components.WindowComponent) EntityTree(com.qcadoo.model.api.EntityTree)

Example 8 with EntityTree

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");
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) WindowComponent(com.qcadoo.view.api.components.WindowComponent) EntityTree(com.qcadoo.model.api.EntityTree)

Example 9 with EntityTree

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) DailyProgressKey(com.qcadoo.mes.productionPerShift.domain.DailyProgressKey) EntityTree(com.qcadoo.model.api.EntityTree) Date(java.util.Date)

Example 10 with EntityTree

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) EntityTree(com.qcadoo.model.api.EntityTree)

Aggregations

EntityTree (com.qcadoo.model.api.EntityTree)52 Entity (com.qcadoo.model.api.Entity)44 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)10 FormComponent (com.qcadoo.view.api.components.FormComponent)10 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)7 EntityList (com.qcadoo.model.api.EntityList)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Service (org.springframework.stereotype.Service)6 EntityTreeNode (com.qcadoo.model.api.EntityTreeNode)5 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 Set (java.util.Set)4 Sets (com.google.common.collect.Sets)3 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)3 Date (java.util.Date)3 Locale (java.util.Locale)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2