Search in sources :

Example 1 with GanttChartItem

use of com.qcadoo.view.api.components.ganttChart.GanttChartItem in project qcadoo by qcadoo.

the class GanttChartComponentState method renderContent.

@Override
protected JSONObject renderContent() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("zoomLevel", scale.getZoomLevel().toString());
    json.put("dateFromErrorMessage", dateFromErrorMessage);
    json.put("dateToErrorMessage", dateToErrorMessage);
    if (dateFromErrorMessage == null) {
        json.put("dateFrom", DATETYPE.toString(scale.getDateFrom(), getLocale()));
    }
    if (dateToErrorMessage == null) {
        json.put("dateTo", DATETYPE.toString(scale.getDateTo(), getLocale()));
    }
    json.put("globalErrorMessage", globalErrorMessage);
    if (globalErrorMessage == null) {
        json.put("scale", scale.getAsJson());
        JSONArray rowsArray = new JSONArray();
        JSONArray itemsArray = new JSONArray();
        for (Map.Entry<String, List<GanttChartItem>> entry : items.entrySet()) {
            rowsArray.put(entry.getKey());
            for (GanttChartItem item : entry.getValue()) {
                if (item != null) {
                    itemsArray.put(item.getAsJson());
                }
            }
        }
        json.put("stripsOrientation", getStripsOrientation().getStringValue());
        json.put("itemsBorderColor", itemsBorderColor);
        json.put("itemsBorderWidth", itemsBorderWidth);
        json.put("rows", rowsArray);
        json.put("items", itemsArray);
        JSONArray collisionItemsArray = new JSONArray();
        for (Map.Entry<String, List<GanttChartItem>> entry : collisionItems.entrySet()) {
            for (GanttChartItem item : entry.getValue()) {
                if (item != null) {
                    collisionItemsArray.put(item.getAsJson());
                }
            }
        }
        json.put("collisions", collisionItemsArray);
        json.put("selectedEntityId", selectedEntityId);
    }
    return json;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) GanttChartItem(com.qcadoo.view.api.components.ganttChart.GanttChartItem)

Example 2 with GanttChartItem

use of com.qcadoo.view.api.components.ganttChart.GanttChartItem in project qcadoo by qcadoo.

the class GanttChartConflictItem method getAsJson.

@Override
public JSONObject getAsJson() throws JSONException {
    JSONObject json = super.getAsJson();
    JSONArray itemsArray = new JSONArray();
    for (GanttChartItem item : items) {
        itemsArray.put(item.getAsJson());
    }
    json.put("items", itemsArray);
    return json;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) GanttChartItem(com.qcadoo.view.api.components.ganttChart.GanttChartItem)

Example 3 with GanttChartItem

use of com.qcadoo.view.api.components.ganttChart.GanttChartItem in project mes by qcadoo.

the class OperationsGanttChartItemResolverImpl method resolve.

@Override
public Map<String, List<GanttChartItem>> resolve(final GanttChartScale scale, final JSONObject context, final Locale locale) {
    try {
        Long orderId = Long.valueOf(context.getString("orderId"));
        Entity order = dataDefinitionService.get(ORDERS_MODEL, ORDER_FIELD).get(orderId);
        if (order == null) {
            LOG.warn("Cannot find order for " + orderId);
            return Collections.emptyMap();
        }
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
        List<Entity> operations = dataDefinitionService.get(com.qcadoo.mes.technologies.constants.TechnologiesConstants.PLUGIN_IDENTIFIER, com.qcadoo.mes.technologies.constants.TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).find().add(SearchRestrictions.belongsTo(TechnologyOperationComponentFields.TECHNOLOGY, technology)).list().getEntities();
        if (operations.isEmpty()) {
            LOG.warn("Cannot find operations for " + order);
            return Collections.emptyMap();
        }
        if (scale.getIsDatesSet() != null && scale.getIsDatesSet()) {
            Entity orderTimeCalculation = dataDefinitionService.get(TimeNormsConstants.PLUGIN_PRODUCTION_SCHEDULING_IDENTIFIER, TimeNormsConstants.MODEL_ORDER_TIME_CALCULATION).find().add(SearchRestrictions.belongsTo("order", order)).setMaxResults(1).uniqueResult();
            if (Objects.nonNull(orderTimeCalculation)) {
                scale.setDateFrom(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_FROM));
                scale.setDateTo(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO));
            }
        }
        Map<String, List<GanttChartItem>> items = new LinkedHashMap<String, List<GanttChartItem>>();
        Map<String, Integer> counters = new HashMap<String, Integer>();
        List<Entity> sortedOperationFromTree = entityTreeUtilsService.getSortedEntities(order.getBelongsToField(OrderFields.TECHNOLOGY).getTreeField(TechnologyFields.OPERATION_COMPONENTS));
        for (Entity operationFromTree : sortedOperationFromTree) {
            Entity operation = operations.get(operations.indexOf(operationFromTree));
            Entity timeCalculation = operationWorkTimeService.createOrGetOperCompTimeCalculation(order, operation);
            Date dateFrom = timeCalculation.getDateField(EFFECTIVE_DATE_FROM_FIELD);
            Date dateTo = timeCalculation.getDateField(EFFECTIVE_DATE_TO_FIELD);
            if (dateFrom == null || dateTo == null || dateTo.before(scale.getDateFrom())) {
                continue;
            }
            StringBuffer operationName = new StringBuffer(getDescriptionForOperation(operation));
            int counter = 0;
            if (counters.containsKey(operationName.toString())) {
                counter = counters.get(operationName.toString()) + 1;
                operationName.append(" (");
                operationName.append(counter);
                operationName.append(") ");
            }
            GanttChartItem item = scale.createGanttChartItem(operationName.toString(), operationName.toString(), operation.getId(), dateFrom, dateTo);
            if (item != null) {
                items.put(operationName.toString(), Collections.singletonList(item));
                counters.put(operationName.toString(), counter);
            }
        }
        return items;
    } catch (NumberFormatException e) {
        throw new IllegalStateException(e.getMessage(), e);
    } catch (JSONException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONException(org.json.JSONException) GanttChartItem(com.qcadoo.view.api.components.ganttChart.GanttChartItem) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List)

Example 4 with GanttChartItem

use of com.qcadoo.view.api.components.ganttChart.GanttChartItem in project mes by qcadoo.

the class ShiftsGanttChartItemResolverImpl method getItemsForShift.

private List<GanttChartItem> getItemsForShift(final Shift shift, final GanttChartScale scale) {
    String shiftName = shift.getEntity().getStringField(ShiftFields.NAME);
    List<DateTimeRange> timeRanges = shiftsService.getDateTimeRanges(Collections.singletonList(shift), scale.getDateFrom(), scale.getDateTo());
    List<GanttChartItem> items = new ArrayList<>();
    for (DateTimeRange timeRange : timeRanges) {
        items.add(scale.createGanttChartItem(shiftName, shiftName, null, timeRange.getFrom().toDate(), timeRange.getTo().toDate()));
    }
    return items;
}
Also used : DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) GanttChartItem(com.qcadoo.view.api.components.ganttChart.GanttChartItem)

Aggregations

GanttChartItem (com.qcadoo.view.api.components.ganttChart.GanttChartItem)4 HashMap (java.util.HashMap)2 List (java.util.List)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)1 Entity (com.qcadoo.model.api.Entity)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 JSONException (org.json.JSONException)1