Example usage for java.text ParsePosition ParsePosition

List of usage examples for java.text ParsePosition ParsePosition

Introduction

In this page you can find the example usage for java.text ParsePosition ParsePosition.

Prototype

public ParsePosition(int index) 

Source Link

Document

Create a new ParsePosition with the given initial index.

Usage

From source file:org.zuinnote.hadoop.office.format.common.converter.ExcelConverterSimpleSpreadSheetCellDAO.java

/***
 * This provides another sample to infer schema in form of simple datatypes
 * (e.g. boolean, byte etc.). You might add as many sample as necessary to get a
 * precise schema./*from   w w w .j  a v  a2s. c  o  m*/
 * 
 * @param dataRow
 */
public void updateSpreadSheetCellRowToInferSchemaInformation(SpreadSheetCellDAO[] dataRow) {
    // check size of cell based on address
    // if necessary add more to schemaRow

    for (SpreadSheetCellDAO currentSpreadSheetCellDAO : dataRow) {
        boolean dataTypeFound = false;
        if (currentSpreadSheetCellDAO != null) {
            // add potential column to list
            int j = new CellAddress(currentSpreadSheetCellDAO.getAddress()).getColumn();
            if (j >= this.schemaRow.size()) {
                // fill up
                for (int x = this.schemaRow.size(); x <= j; x++) {
                    this.schemaRow.add(null);
                }
            }
            // check if boolean data type
            if ((currentSpreadSheetCellDAO.getFormattedValue() != null)
                    && (!"".equals(currentSpreadSheetCellDAO.getFormattedValue()))) { // skip null value
                String currentCellValue = currentSpreadSheetCellDAO.getFormattedValue();
                // check if boolean
                if (("TRUE".equals(currentCellValue)) || ("FALSE".equals(currentCellValue))) {
                    dataTypeFound = true;
                    if (this.schemaRow.get(j) != null) { // check if previous assumption was boolean

                        if (!(this.schemaRow.get(j) instanceof GenericBooleanDataType)) {
                            // if not then the type needs to be set to string
                            this.schemaRow.set(j, new GenericStringDataType());
                        }
                        // if yes then nothing todo (already boolean)
                    } else { // we face this the first time
                        this.schemaRow.set(j, new GenericBooleanDataType());
                    }
                }
                // check if timestamp using provided format
                if (!dataTypeFound) {
                    if (this.dateTimeFormat != null) { // only if a format is specified
                        Date theDate = this.dateTimeFormat.parse(currentCellValue, new ParsePosition(0));
                        if (theDate != null) { // we found indeed a date time

                            dataTypeFound = true;
                            if (this.schemaRow.get(j) != null) { // check if previous assumption was date

                                if (!(this.schemaRow.get(j) instanceof GenericTimestampDataType)) {
                                    // if not then the type needs to be set to string
                                    this.schemaRow.set(j, new GenericStringDataType());
                                }
                            } else { // we face this the first time
                                this.schemaRow.set(j, new GenericTimestampDataType());

                            }

                        }
                    }
                }
                // check for timestamp using java.sql.Timestamp
                if (!dataTypeFound) {

                    try {
                        java.sql.Timestamp ts = java.sql.Timestamp.valueOf(currentCellValue);
                        dataTypeFound = true;
                        this.schemaRow.set(j, new GenericTimestampDataType());
                    } catch (IllegalArgumentException e) {
                        LOG.warn(
                                "Could not identify timestamp using TimeStamp.valueOf. Trying last resort Date parsing....");
                    }
                }
                // check if date data type
                if (!dataTypeFound) {

                    Date theDate = this.dateFormat.parse(currentCellValue, new ParsePosition(0));
                    if (theDate != null) { // we have indeed a date

                        dataTypeFound = true;
                        if (this.schemaRow.get(j) != null) { // check if previous assumption was date

                            if (!(this.schemaRow.get(j) instanceof GenericDateDataType)) {
                                // if not then the type needs to be set to string
                                this.schemaRow.set(j, new GenericStringDataType());
                            }

                        } else { // we face this the first time
                            this.schemaRow.set(j, new GenericDateDataType());
                            // check if it has a time component

                        }
                    }
                }
                // check if BigDecimal

                BigDecimal bd = (BigDecimal) this.decimalFormat.parse(currentCellValue, new ParsePosition(0));
                if ((!dataTypeFound) && (bd != null)) {
                    BigDecimal bdv = bd.stripTrailingZeros();

                    dataTypeFound = true;

                    if (this.schemaRow.get(j) != null) { // check if previous assumption was a number

                        // check if we need to upgrade to decimal
                        if ((bdv.scale() > 0) && (this.schemaRow.get(j) instanceof GenericNumericDataType)) {
                            // upgrade to decimal, if necessary
                            if (!(this.schemaRow.get(j) instanceof GenericBigDecimalDataType)) {
                                this.schemaRow.set(j,
                                        new GenericBigDecimalDataType(bdv.precision(), bdv.scale()));
                            } else {
                                if ((bdv.scale() > ((GenericBigDecimalDataType) this.schemaRow.get(j))
                                        .getScale())
                                        && (bdv.precision() > ((GenericBigDecimalDataType) this.schemaRow
                                                .get(j)).getPrecision())) {
                                    this.schemaRow.set(j,
                                            new GenericBigDecimalDataType(bdv.precision(), bdv.scale()));
                                } else if (bdv.scale() > ((GenericBigDecimalDataType) this.schemaRow.get(j))
                                        .getScale()) {
                                    // upgrade scale
                                    GenericBigDecimalDataType gbd = ((GenericBigDecimalDataType) this.schemaRow
                                            .get(j));
                                    gbd.setScale(bdv.scale());
                                    this.schemaRow.set(j, gbd);
                                } else if (bdv.precision() > ((GenericBigDecimalDataType) this.schemaRow.get(j))
                                        .getPrecision()) {
                                    // upgrade precision
                                    // new precision is needed to extend to max scale
                                    GenericBigDecimalDataType gbd = ((GenericBigDecimalDataType) this.schemaRow
                                            .get(j));
                                    int newpre = bdv.precision() + (gbd.getScale() - bdv.scale());
                                    gbd.setPrecision(newpre);
                                    this.schemaRow.set(j, gbd);
                                }
                            }
                        } else { // check if we need to upgrade one of the integer types
                            // if current is byte
                            boolean isByte = false;
                            boolean isShort = false;
                            boolean isInt = false;
                            boolean isLong = true;
                            try {
                                bdv.longValueExact();
                                isLong = true;
                                bdv.intValueExact();
                                isInt = true;
                                bdv.shortValueExact();
                                isShort = true;
                                bdv.byteValueExact();
                                isByte = true;
                            } catch (Exception e) {
                                LOG.debug("Possible data types: Long: " + isLong + " Int: " + isInt + " Short: "
                                        + isShort + " Byte: " + isByte);
                            }
                            // if it was Numeric before we can ignore testing the byte case, here just for
                            // completeness
                            if ((isByte) && ((this.schemaRow.get(j) instanceof GenericByteDataType)
                                    || (this.schemaRow.get(j) instanceof GenericShortDataType)
                                    || (this.schemaRow.get(j) instanceof GenericIntegerDataType)
                                    || (this.schemaRow.get(j) instanceof GenericLongDataType))) {
                                // if it was Byte before we can ignore testing the byte case, here just for
                                // completeness
                            } else if ((isShort) && ((this.schemaRow.get(j) instanceof GenericByteDataType))) {
                                // upgrade to short
                                this.schemaRow.set(j, new GenericShortDataType());
                            } else if ((isInt) && ((this.schemaRow.get(j) instanceof GenericShortDataType)
                                    || (this.schemaRow.get(j) instanceof GenericByteDataType))) {
                                // upgrade to integer
                                this.schemaRow.set(j, new GenericIntegerDataType());
                            } else if ((!isByte) && (!isShort) && (!isInt)
                                    && !((this.schemaRow.get(j) instanceof GenericLongDataType))) {
                                // upgrade to long
                                this.schemaRow.set(j, new GenericLongDataType());
                            }

                        }

                    } else {
                        // we face it for the first time
                        // determine value type
                        if (bdv.scale() > 0) {
                            this.schemaRow.set(j, new GenericBigDecimalDataType(bdv.precision(), bdv.scale()));
                        } else {
                            boolean isByte = false;
                            boolean isShort = false;
                            boolean isInt = false;
                            boolean isLong = true;
                            try {
                                bdv.longValueExact();
                                isLong = true;
                                bdv.intValueExact();
                                isInt = true;
                                bdv.shortValueExact();
                                isShort = true;
                                bdv.byteValueExact();
                                isByte = true;
                            } catch (Exception e) {
                                LOG.debug("Possible data types: Long: " + isLong + " Int: " + isInt + " Short: "
                                        + isShort + " Byte: " + isByte);
                            }
                            if (isByte) {
                                this.schemaRow.set(j, new GenericByteDataType());
                            } else if (isShort) {
                                this.schemaRow.set(j, new GenericShortDataType());
                            } else if (isInt) {
                                this.schemaRow.set(j, new GenericIntegerDataType());
                            } else if (isLong) {
                                this.schemaRow.set(j, new GenericLongDataType());
                            }
                        }
                    }
                }
                if (!dataTypeFound) {
                    // otherwise string
                    if (!(this.schemaRow.get(j) instanceof GenericStringDataType)) {
                        this.schemaRow.set(j, new GenericStringDataType());
                    }

                }

            } else {
                // ignore null values
            }
        }
    }
}

From source file:org.apache.roller.weblogger.ui.core.tags.calendar.WeblogCalendarModel.java

/**
 * Parse data as either 6-char or 8-char format.
 *//*from   w  ww  . j a  v  a  2  s .  c  o m*/
public static Date parseWeblogURLDateString(String dateString, TimeZone tz, Locale locale) {

    Date ret = new Date();
    Calendar cal = Calendar.getInstance(tz, locale);

    if (dateString != null && dateString.length() == 8 && StringUtils.isNumeric(dateString)) {
        SimpleDateFormat char8DateFormat = DateUtil.get8charDateFormat();
        char8DateFormat.setCalendar(cal);
        ParsePosition pos = new ParsePosition(0);
        ret = char8DateFormat.parse(dateString, pos);

        // make sure the requested date is not in the future
        //            Date today = null;
        //            Calendar todayCal = Calendar.getInstance();
        //            todayCal = Calendar.getInstance(tz, locale);
        //            todayCal.setTime(new Date());
        //            today = todayCal.getTime();
        // Date is always ms offset from epoch in UTC, by no means of timezone.
        Date today = new Date();
        if (ret.after(today)) {
            ret = today;
        }

    } else if (dateString != null && dateString.length() == 6 && StringUtils.isNumeric(dateString)) {
        SimpleDateFormat char6DateFormat = DateUtil.get6charDateFormat();
        char6DateFormat.setCalendar(cal);
        ParsePosition pos = new ParsePosition(0);
        ret = char6DateFormat.parse(dateString, pos);

        // make sure the requested date is not in the future
        //            Calendar todayCal = Calendar.getInstance();
        //            todayCal = Calendar.getInstance(tz, locale);
        //            todayCal.setTime(new Date());
        //            Date today = todayCal.getTime();
        Date today = new Date();
        if (ret.after(today)) {
            ret = today;
        }
    }

    return ret;
}

From source file:org.wings.SDimension.java

/**
 * Extract number from string./*from ww w  .  jav a 2 s . co m*/
 *
 * @return extracted integer. f.e.: "120px" becomes 120
 */
protected int getIntValue(String sizeString) {
    if (sizeString == null) {
        return AUTO_INT;
    }
    if (sizeString.trim().equalsIgnoreCase(AUTO)) {
        return AUTO_INT;
    }
    if (sizeString.trim().equalsIgnoreCase(INHERIT)) {
        return INHERIT_INT;
    }
    try {
        return new DecimalFormat().parse(sizeString, new ParsePosition(0)).intValue();
    } catch (Exception e) {
        log.warn("Can not parse [" + sizeString + "]", e);
    }
    return AUTO_INT;
}

From source file:org.noorganization.instalistsynch.controller.synch.impl.ListSynch.java

@Override
public void indexLocal(int _groupId, Date _lastIndexTime) {
    String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000");
    boolean isLocal = false;
    GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup();
    if (groupAuth != null) {
        isLocal = groupAuth.getGroupId() == _groupId;
    }//  w  ww .  ja v a  2s .  com
    Cursor logCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType);
    if (logCursor.getCount() == 0) {
        logCursor.close();
        return;
    }

    try {
        while (logCursor.moveToNext()) {
            // fetch the action type
            int actionId = logCursor.getInt(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION));
            eActionType actionType = eActionType.getTypeById(actionId);

            List<ModelMapping> modelMappingList = mListModelMappingController.get(
                    ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID
                            + " LIKE ?",
                    new String[] { String.valueOf(_groupId),
                            logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) });
            ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0);

            switch (actionType) {
            case INSERT:
                // skip insertion because this should be decided by the user if the non local groups should have access to the category
                // and also skip if a mapping for this case already exists!
                if (!isLocal || modelMapping != null) {
                    continue;
                }

                String clientUuid = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID));
                Date clientDate = ISO8601Utils.parse(
                        logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)),
                        new ParsePosition(0));
                modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid,
                        new Date(Constants.INITIAL_DATE), clientDate, false);
                mListModelMappingController.insert(modelMapping);
                break;
            case UPDATE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                String timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mListModelMappingController.update(modelMapping);
                break;
            case DELETE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                modelMapping.setDeleted(true);
                timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mListModelMappingController.update(modelMapping);
                break;
            default:
            }

        }
    } catch (Exception e) {
        logCursor.close();
    }
}

From source file:de.jlo.talendcomp.json.TypeUtil.java

public static BigDecimal convertToBigDecimal(String value) throws Exception {
    if (value == null || value.isEmpty()) {
        return null;
    }/*ww w. ja v a2s.  c  om*/
    try {
        DecimalFormat decfrm = getNumberFormat(DEFAULT_LOCALE);
        decfrm.setParseBigDecimal(true);
        ParsePosition pp = new ParsePosition(0);
        return (BigDecimal) decfrm.parse(value, pp);
    } catch (RuntimeException e) {
        throw new Exception("convertToBigDecimal:" + value + " failed:" + e.getMessage(), e);
    }
}

From source file:io.apiman.gateway.engine.jdbc.JdbcMetricsTest.java

/**
 * @throws ParseException // w w w.j a v  a  2 s . c o  m
 */
private RequestMetric request(String requestStart, long requestDuration, String url, String resource,
        String method, String apiOrgId, String apiId, String apiVersion, String planId, String clientOrgId,
        String clientId, String clientVersion, String contractId, String user, int responseCode,
        String responseMessage, boolean failure, int failureCode, String failureReason, boolean error,
        String errorMessage, long bytesUploaded, long bytesDownloaded) throws ParseException {
    Date start = ISO8601Utils.parse(requestStart, new ParsePosition(0));
    RequestMetric rval = new RequestMetric();
    rval.setRequestStart(start);
    rval.setRequestEnd(new Date(start.getTime() + requestDuration));
    rval.setApiStart(start);
    rval.setApiEnd(rval.getRequestEnd());
    rval.setApiDuration(requestDuration);
    rval.setUrl(url);
    rval.setResource(resource);
    rval.setMethod(method);
    rval.setApiOrgId(apiOrgId);
    rval.setApiId(apiId);
    rval.setApiVersion(apiVersion);
    rval.setPlanId(planId);
    rval.setClientOrgId(clientOrgId);
    rval.setClientId(clientId);
    rval.setClientVersion(clientVersion);
    rval.setContractId(contractId);
    rval.setUser(user);
    rval.setResponseCode(responseCode);
    rval.setResponseMessage(responseMessage);
    rval.setFailure(failure);
    rval.setFailureCode(failureCode);
    rval.setFailureReason(failureReason);
    rval.setError(error);
    rval.setErrorMessage(errorMessage);
    rval.setBytesUploaded(bytesUploaded);
    rval.setBytesDownloaded(bytesDownloaded);
    return rval;
}

From source file:com.jeeframework.util.validate.GenericTypeValidator.java

/**
 *  Checks if the value can safely be converted to a float primitive.
 *
 *@param  value   The value validation is being performed on.
 *@param  locale  The locale to use to parse the number (system default if
 *      null)/* w ww . j a  v a 2s  . c  om*/
 *@return the converted Float value.
 */
public static Float formatFloat(String value, Locale locale) {
    Float result = null;

    if (value != null) {
        NumberFormat formatter = null;
        if (locale != null) {
            formatter = NumberFormat.getInstance(locale);
        } else {
            formatter = NumberFormat.getInstance(Locale.getDefault());
        }
        ParsePosition pos = new ParsePosition(0);
        Number num = formatter.parse(value, pos);

        // If there was no error      and we used the whole string
        if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
            if (num.doubleValue() >= (Float.MAX_VALUE * -1) && num.doubleValue() <= Float.MAX_VALUE) {
                result = new Float(num.floatValue());
            }
        }
    }

    return result;
}

From source file:com.qcadoo.mes.productionScheduling.listeners.OrderTimePredictionListeners.java

@Transactional
public void changeRealizationTime(final ViewDefinitionState view, final ComponentState state,
        final String[] args) {
    FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM);

    FieldComponent technologyLookup = (FieldComponent) view.getComponentByReference(OrderFields.TECHNOLOGY);
    FieldComponent plannedQuantityField = (FieldComponent) view
            .getComponentByReference(OrderFields.PLANNED_QUANTITY);
    FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(OrderFields.DATE_FROM);
    FieldComponent dateToField = (FieldComponent) view.getComponentByReference(OrderFields.DATE_TO);
    FieldComponent productionLineLookup = (FieldComponent) view
            .getComponentByReference(OrderFields.PRODUCTION_LINE);

    boolean isGenerated = false;

    if (technologyLookup.getFieldValue() == null) {
        technologyLookup.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);

        return;/*from  ww  w .  ja v  a2s  . c  o  m*/
    }

    if (!StringUtils.hasText((String) dateFromField.getFieldValue())) {
        dateFromField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);

        return;
    }

    if (!StringUtils.hasText((String) plannedQuantityField.getFieldValue())) {
        plannedQuantityField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);

        return;
    }

    if (productionLineLookup.getFieldValue() == null) {
        productionLineLookup.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);

        return;
    }

    BigDecimal quantity = null;
    Object value = plannedQuantityField.getFieldValue();

    if (value instanceof BigDecimal) {
        quantity = (BigDecimal) value;
    } else {
        try {
            ParsePosition parsePosition = new ParsePosition(0);
            String trimedValue = value.toString().replaceAll(" ", "");
            DecimalFormat formatter = (DecimalFormat) NumberFormat.getNumberInstance(view.getLocale());
            formatter.setParseBigDecimal(true);
            quantity = new BigDecimal(String.valueOf(formatter.parseObject(trimedValue, parsePosition)));
        } catch (NumberFormatException e) {
            plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidNumericFormat",
                    MessageType.FAILURE);

            return;
        }
    }

    int scale = quantity.scale();

    if (MAX != null && scale > MAX) {
        plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidScale.max", MessageType.FAILURE,
                MAX.toString());
        return;
    }

    int presicion = quantity.precision() - scale;

    if (MAX != null && presicion > MAX) {
        plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidPrecision.max",
                MessageType.FAILURE, MAX.toString());
        return;
    }

    if (BigDecimal.ZERO.compareTo(quantity) >= 0) {
        plannedQuantityField.addMessage("qcadooView.validate.field.error.outOfRange.toSmall",
                MessageType.FAILURE);
        return;
    }

    int maxPathTime = 0;

    Entity technology = dataDefinitionService
            .get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY)
            .get((Long) technologyLookup.getFieldValue());
    Validate.notNull(technology, "technology is null");

    if (technology.getStringField(TechnologyFields.STATE).equals(TechnologyState.DRAFT.getStringValue())
            || technology.getStringField(TechnologyFields.STATE)
                    .equals(TechnologyState.OUTDATED.getStringValue())) {
        technologyLookup.addMessage("productionScheduling.technology.incorrectState", MessageType.FAILURE);

        return;
    }

    FieldComponent laborWorkTimeField = (FieldComponent) view
            .getComponentByReference(OrderFieldsPS.LABOR_WORK_TIME);
    FieldComponent machineWorkTimeField = (FieldComponent) view
            .getComponentByReference(OrderFieldsPS.MACHINE_WORK_TIME);
    FieldComponent includeTpzField = (FieldComponent) view.getComponentByReference(OrderFieldsPS.INCLUDE_TPZ);
    FieldComponent includeAdditionalTimeField = (FieldComponent) view
            .getComponentByReference(OrderFieldsPS.INCLUDE_ADDITIONAL_TIME);

    Boolean includeTpz = "1".equals(includeTpzField.getFieldValue());
    Boolean includeAdditionalTime = "1".equals(includeAdditionalTimeField.getFieldValue());

    Entity productionLine = dataDefinitionService
            .get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE)
            .get((Long) productionLineLookup.getFieldValue());

    final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();

    productQuantitiesService.getProductComponentQuantities(technology, quantity, operationRuns);

    OperationWorkTime workTime = operationWorkTimeService.estimateTotalWorkTimeForTechnology(technology,
            operationRuns, includeTpz, includeAdditionalTime, productionLine, true);

    laborWorkTimeField.setFieldValue(workTime.getLaborWorkTime());
    machineWorkTimeField.setFieldValue(workTime.getMachineWorkTime());

    maxPathTime = orderRealizationTimeService.estimateOperationTimeConsumption(
            technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(), quantity, includeTpz,
            includeAdditionalTime, productionLine);

    if (maxPathTime > OrderRealizationTimeService.MAX_REALIZATION_TIME) {
        state.addMessage("orders.validate.global.error.RealizationTimeIsToLong", MessageType.FAILURE);

        dateToField.setFieldValue(null);
    } else {
        Date startTime = DateUtils.parseDate(dateFromField.getFieldValue());

        if (startTime == null) {
            dateFromField.addMessage("orders.validate.global.error.dateFromIsNull", MessageType.FAILURE);
        } else {
            Date stopTime = shiftsService.findDateToForOrder(startTime, maxPathTime);

            if (stopTime == null) {
                orderForm.addMessage("productionScheduling.timenorms.isZero", MessageType.FAILURE, false);

                dateToField.setFieldValue(null);
            } else {
                dateToField.setFieldValue(orderRealizationTimeService.setDateToField(stopTime));

                startTime = shiftsService.findDateFromForOrder(stopTime, maxPathTime);

                scheduleOperationComponents(technology.getId(), startTime);

                isGenerated = true;
            }

            if (startTime != null) {
                orderForm.addMessage("orders.dateFrom.info.dateFromSetToFirstPossible", MessageType.INFO,
                        false);
            }
        }
    }

    laborWorkTimeField.requestComponentUpdateState();
    machineWorkTimeField.requestComponentUpdateState();
    dateFromField.requestComponentUpdateState();
    dateToField.requestComponentUpdateState();

    orderForm.setEntity(orderForm.getEntity());

    state.performEvent(view, "refresh", new String[0]);

    if (isGenerated) {
        orderForm.addMessage("productionScheduling.info.calculationGenerated", MessageType.SUCCESS);
    }
}

From source file:org.noorganization.instalistsynch.controller.synch.impl.IngredientSynch.java

@Override
public void indexLocal(int _groupId, Date _lastIndexTime) {
    String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000");
    boolean isLocal = false;
    GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup();
    if (groupAuth != null) {
        isLocal = groupAuth.getGroupId() == _groupId;
    }/*from   ww  w.j ava 2 s.c  o  m*/
    Cursor logCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType);
    if (logCursor.getCount() == 0) {
        logCursor.close();
        return;
    }

    try {
        while (logCursor.moveToNext()) {
            // fetch the action type
            int actionId = logCursor.getInt(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION));
            eActionType actionType = eActionType.getTypeById(actionId);

            List<ModelMapping> modelMappingList = mIngredientModelMapping.get(
                    ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID
                            + " LIKE ?",
                    new String[] { String.valueOf(_groupId),
                            logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) });
            ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0);

            switch (actionType) {
            case INSERT:
                // skip insertion because this should be decided by the user if the non local groups should have access to the category
                // and also skip if a mapping for this case already exists!
                if (!isLocal || modelMapping != null) {
                    continue;
                }

                String clientUuid = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID));
                Date clientDate = ISO8601Utils.parse(
                        logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)),
                        new ParsePosition(0));
                modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid,
                        new Date(Constants.INITIAL_DATE), clientDate, false);
                mIngredientModelMapping.insert(modelMapping);
                break;
            case UPDATE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                String timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mIngredientModelMapping.update(modelMapping);
                break;
            case DELETE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                modelMapping.setDeleted(true);
                timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mIngredientModelMapping.update(modelMapping);
                break;
            default:
            }

        }
    } catch (Exception e) {
        logCursor.close();
    }
}

From source file:org.noorganization.instalistsynch.controller.synch.impl.ListEntrySynch.java

@Override
public void indexLocal(int _groupId, Date _lastIndexTime) {
    String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000");
    boolean isLocal = false;
    GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup();
    if (groupAuth != null) {
        isLocal = groupAuth.getGroupId() == _groupId;
    }/* w w  w  . j  ava  2 s.co m*/
    Cursor logCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType);
    if (logCursor.getCount() == 0) {
        logCursor.close();
        return;
    }

    try {
        while (logCursor.moveToNext()) {
            // fetch the action type
            int actionId = logCursor.getInt(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION));
            eActionType actionType = eActionType.getTypeById(actionId);

            List<ModelMapping> modelMappingList = mListEntryMapping.get(
                    ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID
                            + " LIKE ?",
                    new String[] { String.valueOf(_groupId),
                            logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) });
            ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0);

            switch (actionType) {
            case INSERT:
                // skip insertion because this should be decided by the user if the non local groups should have access to the category
                // and also skip if a mapping for this case already exists!
                if (!isLocal || modelMapping != null) {
                    continue;
                }

                String clientUuid = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID));
                Date clientDate = ISO8601Utils.parse(
                        logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)),
                        new ParsePosition(0));
                modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid,
                        new Date(Constants.INITIAL_DATE), clientDate, false);
                mListEntryMapping.insert(modelMapping);
                break;
            case UPDATE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                String timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mListEntryMapping.update(modelMapping);
                break;
            case DELETE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                modelMapping.setDeleted(true);
                timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mListEntryMapping.update(modelMapping);
                break;
            default:
            }

        }
    } catch (Exception e) {
        logCursor.close();
    }
}