Search in sources :

Example 1 with SORuntimeException

use of com.storedobject.common.SORuntimeException in project SODevelopment by syampillai.

the class AbstractQuantityField method convertX.

private T convertX(T value) {
    value = v(value);
    if (allowedUnits != null && !allowedUnits.contains(value.getUnit())) {
        MeasurementUnit unit = value.getUnit();
        MeasurementUnit mu = allowedUnits.stream().filter(u -> u.getType() == unit.getType()).findFirst().orElse(null);
        if (mu == null) {
            if (value.isZero()) {
                mu = allowedUnits.stream().findFirst().orElseThrow();
            } else {
                throw new SORuntimeException();
            }
        }
        // noinspection unchecked
        value = (T) value.convert(mu);
    }
    return value;
}
Also used : MeasurementUnit(com.storedobject.core.MeasurementUnit) SORuntimeException(com.storedobject.common.SORuntimeException)

Example 2 with SORuntimeException

use of com.storedobject.common.SORuntimeException in project SODevelopment by syampillai.

the class ParameterParser method itemTypeClass.

static Class<? extends InventoryItemType> itemTypeClass(int skip, String parameters, Class<? extends InventoryItemType> defaultClass) {
    if (parameters == null) {
        return defaultClass;
    }
    String[] ps = parameters.split("\\|");
    for (String p : ps) {
        p = p.trim();
        if (StringUtility.getCharCount(p, '.') == 1) {
            p = ApplicationServer.getPackageName() + "." + p;
        }
        if (!isClass(p)) {
            continue;
        }
        try {
            Class<?> c;
            if ("*".equals(p)) {
                c = InventoryItemType.class;
            } else {
                c = JavaClassLoader.getLogic(p);
            }
            if (!InventoryItemType.class.isAssignableFrom(c)) {
                continue;
            }
            if (skip <= 0) {
                // noinspection unchecked
                return (Class<? extends InventoryItemType>) c;
            }
            --skip;
        } catch (Throwable e) {
            throw new SORuntimeException("Unable to determine item type from '" + parameters + "'");
        }
    }
    return defaultClass;
}
Also used : SORuntimeException(com.storedobject.common.SORuntimeException)

Example 3 with SORuntimeException

use of com.storedobject.common.SORuntimeException in project SODevelopment by syampillai.

the class ObjectListEditor method save.

/**
 * Save the currently accumulated changes to the database. (Please note that this method will not
 * use any "saver" set by the {@link #setSaver(Function)} method. In fact, a "saver" may call this method
 * to carry out the real "save action" if required.)
 *
 * @param transaction Transaction.
 * @throws Exception Will be thrown if the save is not successful.
 */
public void save(Transaction transaction) throws Exception {
    if (isReadOnly()) {
        return;
    }
    if (stillEditing()) {
        return;
    }
    saveEdited();
    aboutToSave(transaction);
    if (saver == null) {
        transaction.addCommitListener(t -> savedAll());
    }
    try {
        streamAll().forEach(o -> {
            try {
                boolean added;
                if ((added = isAdded(o)) || isEdited(o)) {
                    if (!skipSave(transaction, o)) {
                        if (added) {
                            if (o.isVirtual()) {
                                o.makeNew();
                            }
                        }
                        o.save(transaction);
                        saved(transaction, o);
                    }
                } else if (isDeleted(o)) {
                    if (!skipDelete(transaction, o)) {
                        o.delete(transaction);
                        deleted(transaction, o);
                    }
                }
            } catch (Exception e) {
                throw new SORuntimeException(e);
            }
        });
        reload.setVisible(false);
        reloadAll.setVisible(false);
    } catch (SORuntimeException re) {
        throw (Exception) re.getCause();
    }
}
Also used : SORuntimeException(com.storedobject.common.SORuntimeException) SORuntimeException(com.storedobject.common.SORuntimeException)

Example 4 with SORuntimeException

use of com.storedobject.common.SORuntimeException in project SODevelopment by syampillai.

the class MeasurementField method createQField.

private static <Q extends Quantity> AbstractQuantityField<Q> createQField(Class<Q> quantityClass, int width, int decimals, MeasurementUnit unit) {
    if (unit == null) {
        try {
            unit = quantityClass.getDeclaredConstructor().newInstance().getUnit();
        } catch (Throwable ignored) {
        }
    }
    String name = quantityClass.getName();
    name = "com.storedobject.ui." + name.substring(name.lastIndexOf('.') + 1) + "Field";
    try {
        // noinspection unchecked
        return (AbstractQuantityField<Q>) Class.forName(name).getDeclaredConstructor(int.class, int.class, MeasurementUnit.class).newInstance(width, decimals, unit);
    } catch (Throwable e) {
        throw new SORuntimeException(e);
    }
}
Also used : AbstractQuantityField(com.storedobject.ui.util.AbstractQuantityField) SORuntimeException(com.storedobject.common.SORuntimeException)

Example 5 with SORuntimeException

use of com.storedobject.common.SORuntimeException in project SODevelopment by syampillai.

the class ParameterParser method itemClass.

static Class<? extends InventoryItem> itemClass(int skip, String parameters, Class<? extends InventoryItem> defaultClass) {
    if (parameters == null) {
        return defaultClass;
    }
    String[] ps = parameters.split("\\|");
    for (String p : ps) {
        p = p.trim();
        if (StringUtility.getCharCount(p, '.') == 1) {
            p = ApplicationServer.getPackageName() + "." + p;
        }
        if (!isClass(p)) {
            continue;
        }
        try {
            Class<?> c;
            if ("*".equals(p)) {
                c = InventoryItem.class;
            } else {
                c = JavaClassLoader.getLogic(p);
            }
            if (!InventoryItem.class.isAssignableFrom(c)) {
                continue;
            }
            if (skip <= 0) {
                // noinspection unchecked
                return (Class<? extends InventoryItem>) c;
            }
            --skip;
        } catch (Throwable e) {
            throw new SORuntimeException("Unable to determine item class from '" + parameters + "'");
        }
    }
    return defaultClass;
}
Also used : SORuntimeException(com.storedobject.common.SORuntimeException)

Aggregations

SORuntimeException (com.storedobject.common.SORuntimeException)5 MeasurementUnit (com.storedobject.core.MeasurementUnit)1 AbstractQuantityField (com.storedobject.ui.util.AbstractQuantityField)1