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;
}
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);
}
}
}
}
}
}
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;
}
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);
}
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);
}
}
}
}
}
}
}
}
Aggregations