Search in sources :

Example 56 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class UsedBatchModelValidators method checkIfUsedBatchIsNotAlreadyUsed.

public final boolean checkIfUsedBatchIsNotAlreadyUsed(final DataDefinition usedBatchDD, final Entity usedBatch) {
    Entity batch = usedBatch.getBelongsToField(L_BATCH);
    Entity trackingRecord = usedBatch.getBelongsToField(L_TRACKING_RECORD);
    EntityList usedBatches = trackingRecord.getHasManyField(L_USED_BATCHES_SIMPLE);
    if (usedBatch.getId() == null) {
        if (batch == null) {
            return true;
        } else {
            if (usedBatches == null) {
                return true;
            } else {
                for (Entity ub : usedBatches) {
                    Entity b = ub.getBelongsToField(L_BATCH);
                    if (b.getId().equals(batch.getId())) {
                        usedBatch.addError(usedBatchDD.getField(L_BATCH), "advancedGenealogy.usedBatchSimple.message.usedBatchIsAlreadyUsed");
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList)

Example 57 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class AdvancedGenealogyTreeService method generateProducedFromTree.

private void generateProducedFromTree(final Entity producedBatch, final List<Entity> tree, final boolean includeDrafts, final boolean makeIdsUnique) {
    EntityList trackingRecords = producedBatch.getHasManyField(BatchFields.TRACKING_RECORDS);
    for (Entity trackingRecord : trackingRecords) {
        String type = trackingRecord.getStringField(TrackingRecordFields.ENTITY_TYPE);
        if (type == null) {
            continue;
        }
        String state = trackingRecord.getStringField(STATE);
        if (!TrackingRecordState.ACCEPTED.getStringValue().equals(state)) {
            boolean isDraftAndWeIncludeDrafts = TrackingRecordState.DRAFT.getStringValue().equals(state) && includeDrafts;
            if (!isDraftAndWeIncludeDrafts) {
                continue;
            }
        }
        if (TrackingRecordType.SIMPLE.equals(type)) {
            EntityList usedBatches = trackingRecord.getHasManyField(USED_BATCHES_SIMPLE);
            for (Entity usedBatch : usedBatches) {
                Entity batch = usedBatch.getBelongsToField(UsedBatchSimpleFields.BATCH);
                boolean addedChild = addChild(tree, batch, producedBatch, makeIdsUnique);
                if (addedChild) {
                    generateProducedFromTree(batch, tree, includeDrafts, makeIdsUnique);
                }
            }
        } else if (TrackingRecordType.FOR_ORDER.equals(type) && isEnabled(L_ADVANCED_GENEALOGY_FOR_ORDERS)) {
            EntityList genealogyProductInComponents = trackingRecord.getHasManyField("genealogyProductInComponents");
            for (Entity genealogyProductInComponent : genealogyProductInComponents) {
                EntityList productInBatches = genealogyProductInComponent.getHasManyField("productInBatches");
                for (Entity producedInBatch : productInBatches) {
                    Entity batch = producedInBatch.getBelongsToField(L_BATCH);
                    if (batch == null) {
                        continue;
                    }
                    boolean addedChild = addChild(tree, batch, producedBatch, makeIdsUnique);
                    if (addedChild) {
                        generateProducedFromTree(batch, tree, includeDrafts, makeIdsUnique);
                    }
                }
            }
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList)

Example 58 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class AdvancedGenealogyTreeServiceTest method mockEntityList.

private EntityList mockEntityList(List<Entity> list) {
    EntityList entityList = mock(EntityList.class);
    when(entityList.iterator()).thenReturn(list.iterator());
    return entityList;
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 59 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class AdvancedGenealogyTreeServiceTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    treeService = new AdvancedGenealogyTreeService();
    ReflectionTestUtils.setField(treeService, "dataDefinitionService", dataDefinitionService);
    ReflectionTestUtils.setField(treeService, "pluginAccessor", pluginAccessor);
    when(pluginAccessor.getPlugin("advancedGenealogyForOrders")).thenReturn(null);
    when(dataDefinitionService.get(AdvancedGenealogyConstants.PLUGIN_IDENTIFIER, AdvancedGenealogyConstants.MODEL_BATCH)).thenReturn(dataDefinition);
    when(batch1.getId()).thenReturn(1L);
    when(batch2.getId()).thenReturn(2L);
    EntityList batch1Trs = mockEntityList(asList(batch1Tr));
    when(batch1.getHasManyField("trackingRecords")).thenReturn(batch1Trs);
    when(batch1Tr.getStringField("entityType")).thenReturn(TrackingRecordType.SIMPLE);
    when(batch1Tr.getStringField("state")).thenReturn(TrackingRecordState.DRAFT.getStringValue());
    Entity batch1TrUsedBatch1 = mock(Entity.class);
    when(batch1TrUsedBatch1.getBelongsToField("batch")).thenReturn(batch2);
    EntityList batch1TrUsedBatches = mockEntityList(asList(batch1TrUsedBatch1));
    when(batch1Tr.getHasManyField("usedBatchesSimple")).thenReturn(batch1TrUsedBatches);
    EntityList batch2Trs = mockEntityList(new LinkedList<Entity>());
    when(batch2.getHasManyField("trackingRecords")).thenReturn(batch2Trs);
    SearchCriteriaBuilder searchCriteriaBuilder = Mockito.mock(SearchCriteriaBuilder.class);
    when(dataDefinition.find()).thenReturn(searchCriteriaBuilder);
    when(searchCriteriaBuilder.list()).thenReturn(searchResult);
    when(searchResult.getEntities()).thenReturn(asList(batch1));
    String number1 = "QWD33";
    String number2 = "POS22";
    String productName2 = "productName2";
    String productNumber2 = "productNumber2";
    when(batch1.getField("parent")).thenReturn(parent1);
    when(batch2.getField("parent")).thenReturn(parent2);
    when(batch1.getBelongsToField("product")).thenReturn(product1);
    when(batch2.getBelongsToField("product")).thenReturn(product2);
    when(product1.getStringField("name")).thenReturn(productName1);
    when(product1.getStringField("number")).thenReturn(productNumber1);
    when(product2.getStringField("name")).thenReturn(productName2);
    when(product2.getStringField("number")).thenReturn(productNumber2);
    when(batch1.getField("number")).thenReturn(number1);
    when(batch2.getField("number")).thenReturn(number2);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) EntityList(com.qcadoo.model.api.EntityList) Before(org.junit.Before)

Example 60 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class AdvancedGenealogyTreeService method generateUsedToProduceTree.

private void generateUsedToProduceTree(final Entity parent, final List<Entity> tree, final boolean includeDrafts, final boolean makeIdsUnique, final long realParentId) {
    List<Entity> batches = getDD().find().list().getEntities();
    for (Entity producedBatch : batches) {
        EntityList trackingRecords = producedBatch.getHasManyField(TRACKING_RECORDS);
        for (Entity trackingRecord : trackingRecords) {
            String entityType = trackingRecord.getStringField(ENTITY_TYPE);
            if (entityType == null) {
                continue;
            }
            String state = trackingRecord.getStringField(STATE);
            if (!TrackingRecordState.ACCEPTED.getStringValue().equals(state)) {
                boolean isDraftAndWeIncludeDrafts = TrackingRecordState.DRAFT.getStringValue().equals(state) && includeDrafts;
                if (!isDraftAndWeIncludeDrafts) {
                    continue;
                }
            }
            if (TrackingRecordType.SIMPLE.equals(entityType)) {
                EntityList usedBatches = trackingRecord.getHasManyField(USED_BATCHES_SIMPLE);
                for (Entity usedBatch : usedBatches) {
                    Entity batch = usedBatch.getBelongsToField(UsedBatchSimpleFields.BATCH);
                    if (batch.getId().equals(realParentId)) {
                        long realId = producedBatch.getId();
                        boolean addedChild = addChild(tree, producedBatch, parent, makeIdsUnique);
                        if (addedChild) {
                            generateUsedToProduceTree(producedBatch, tree, includeDrafts, makeIdsUnique, realId);
                        }
                    }
                }
            } else if (TrackingRecordType.FOR_ORDER.equals(entityType) && isEnabled(L_ADVANCED_GENEALOGY_FOR_ORDERS)) {
                EntityList genealogyProductInComponents = trackingRecord.getHasManyField("genealogyProductInComponents");
                for (Entity genealogyProductInComponent : genealogyProductInComponents) {
                    EntityList productInBatches = genealogyProductInComponent.getHasManyField("productInBatches");
                    for (Entity producedInBatch : productInBatches) {
                        Entity batch = producedInBatch.getBelongsToField(L_BATCH);
                        if (batch == null) {
                            continue;
                        }
                        if (batch.getId().equals(realParentId)) {
                            long realId = producedBatch.getId();
                            boolean addedChild = addChild(tree, producedBatch, parent, makeIdsUnique);
                            if (addedChild) {
                                generateUsedToProduceTree(producedBatch, tree, includeDrafts, makeIdsUnique, realId);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList)

Aggregations

EntityList (com.qcadoo.model.api.EntityList)103 Entity (com.qcadoo.model.api.Entity)52 Test (org.junit.Test)27 DataDefinition (com.qcadoo.model.api.DataDefinition)16 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 Before (org.junit.Before)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 Objects (java.util.Objects)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Service (org.springframework.stereotype.Service)10 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)9 BigDecimal (java.math.BigDecimal)9 StateChangeTest (com.qcadoo.mes.states.StateChangeTest)5