Example usage for org.apache.commons.lang NullArgumentException NullArgumentException

List of usage examples for org.apache.commons.lang NullArgumentException NullArgumentException

Introduction

In this page you can find the example usage for org.apache.commons.lang NullArgumentException NullArgumentException.

Prototype

public NullArgumentException(String argName) 

Source Link

Document

Instantiates with the given argument name.

Usage

From source file:org.nuclos.server.customcode.CustomCodeInterface.java

/**
 * get a field value for object with intid <code>iObjectId</code>.
 * @param sEntityName entity name/*from   w w  w  .  j av  a 2s.co  m*/
 * @param iObjectId object id
 * @param sFieldName field name of field to get
 * @return field value
 * @precondition iObjectId != null
 * @precondition sFieldName != null
 */
public Object getFieldValue(String sEntityName, Integer iObjectId, String sFieldName) {
    if (iObjectId == null) {
        throw new NullArgumentException("iObjectId");
    }
    if (sFieldName == null) {
        throw new NullArgumentException("sFieldName");
    }
    if (Modules.getInstance().isModuleEntity(sEntityName)) {
        if (AttributeCache.getInstance().getAttribute(sEntityName, sFieldName).isCalculated()) {
            try {
                return getCalculatedAttributeValue(iObjectId, sFieldName, null);
            } catch (NuclosBusinessRuleException e) {
                this.error(e);
                return null;
            }
        } else {
            return this.getAttribute(iObjectId, sFieldName).getValue();
        }
    } else {
        return this.getRuleInterface().getMasterData(sEntityName, iObjectId).getField(sFieldName);
    }
}

From source file:org.nuclos.server.database.SpringDataBaseHelper.java

/**
 * @return a connection from the given datasource. Must be closed by the caller in a finally block.
 * @precondition datasource != null// w  ww  .  j  av  a 2s.c  om
 */
public Connection getConnection(DataSource datasource) {
    if (datasource == null) {
        throw new NullArgumentException("datasource");
    }
    try {
        return datasource.getConnection();
    } catch (SQLException ex) {
        throw new CommonFatalException("Connection to datasource could not be initialized.", ex);
    }
}

From source file:org.nuclos.server.database.SpringDataBaseHelper.java

/**
 * @return a connection from the given datasource. Must be closed by the caller in a finally block.
 * @precondition datasource != null//from www  .ja v  a 2 s  . com
 */
public String getCurrentConnectionInfo() {
    if (dataSource == null) {
        throw new NullArgumentException("datasource");
    }
    Connection conn = null;
    try {
        conn = dataSource.getConnection();
        return conn.toString() + " @schema=" + getDbAccess().getSchemaName();
    } catch (SQLException ex) {
        throw new CommonFatalException("Connection to datasource could not be initialized.", ex);
    } finally {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception ex) {
            LOG.error(ex.getMessage(), ex);
        }
    }
}

From source file:org.nuclos.server.dblayer.query.DbQueryBuilder.java

protected PreparedStringBuilder buildSql(Object... args) {
    for (int i = 0; i < args.length; i++) {
        if (args[i] instanceof DbCondition) {
            args[i] = getPreparedString((DbCondition) args[i]);
        } else if (args[i] instanceof DbExpression<?>) {
            args[i] = getPreparedString((DbExpression<?>) args[i]);
        } else if (args[i] instanceof String) {
            // do nothing, no convertion needed
        } else if (args[i] instanceof PreparedStringBuilder) {
            // do nothing, no convertion needed
        } else if (args[i] == null) {
            throw new NullArgumentException("No null allowed at index " + i + " in " + Arrays.asList(args));
        } else {/*from  w  w w  . j ava  2 s .  c  o  m*/
            throw new IllegalArgumentException("Don't know how to handle " + args[i] + " of "
                    + args[i].getClass().getName() + " in " + Arrays.asList(args));
        }
    }
    return PreparedStringBuilder.concat(args);
}

From source file:org.nuclos.server.dbtransfer.NuclosSQLUtils.java

/**
 * @return a connection from the given datasource. Must be closed by the caller in a finally block.
 * @precondition datasource != null//w ww  .j  a v  a2 s.c  om
 */
public static Connection getConnection(DataSource datasource) {
    if (datasource == null) {
        throw new NullArgumentException("datasource");
    }
    try {
        return datasource.getConnection();
    } catch (SQLException ex) {
        throw new CommonFatalException("Connection to datasource could not be initialized.", ex);
    }
}

From source file:org.nuclos.server.genericobject.ejb3.GeneratorFacadeBean.java

/**
 * transfers (copies) a specified set of attributes from one generic object
 * to another. Called from within rules. Attention: because this is called
 * within a rule, the source genericobject and its attributes were not saved
 * until now -> the consequence is, that the old attribute values of the
 * source genericobject were transfered to the target genericobject this is
 * very ugly -> todo// w  w  w .ja  v a2 s  .  co m
 *
 * @param iSourceGenericObjectId
 *            source generic object id to transfer data from
 * @param iTargetGenericObjectId
 *            target generic object id to transfer data to
 * @param asAttributes
 *            Array of attribute names to specify transferred data
 * @precondition asAttributes != null
 */
public void transferGenericObjectData(GenericObjectVO govoSource, Integer iTargetGenericObjectId,
        String[][] asAttributes, String customUsage) {
    if (asAttributes == null) {
        throw new NullArgumentException("asAttributes");
    }
    debug("Entering transferGenericObjectData()");
    try {
        final Collection<Integer> stSourceAttributeIds = getAttributeIdsByModuleId(govoSource.getModuleId());
        final GenericObjectVO govoTarget = getGenericObjectFacade().get(iTargetGenericObjectId);
        final Collection<Integer> stTargetAttributeIds = getAttributeIdsByModuleId(govoTarget.getModuleId());

        final Collection<Integer> stExcludedAttributeIds = this.getExcludedAttributeIds();
        final Integer[][] aiIncludedAttributeIds = getAttributeIdsFromNames(asAttributes,
                govoSource.getModuleId(), govoTarget.getModuleId());

        for (int i = 0; i < aiIncludedAttributeIds.length; i++) {
            if (stSourceAttributeIds.contains(aiIncludedAttributeIds[i][0])
                    && !stExcludedAttributeIds.contains(aiIncludedAttributeIds[i][0])) {
                if (stTargetAttributeIds.contains(aiIncludedAttributeIds[i][1])
                        && !stExcludedAttributeIds.contains(aiIncludedAttributeIds[i][1])) {
                    copyAttribute(aiIncludedAttributeIds[i][0], aiIncludedAttributeIds[i][1], govoSource,
                            govoTarget);
                }
            }
        }

        // todo: avoid using modify here as it triggers another rule!
        getGenericObjectFacade().modify(govoTarget.getModuleId(),
                new GenericObjectWithDependantsVO(govoTarget, new DependantMasterDataMapImpl()), customUsage);
    } catch (CommonBusinessException ex) {
        throw new NuclosFatalException(ex);
    }
    debug("Leaving transferGenericObjectData()");
}

From source file:org.nuclos.server.genericobject.ejb3.GeneratorFacadeBean.java

/**
 * @param asAttributeNames/*from  ww w .  j av  a2 s.  c  o m*/
 * @return
 * @precondition asAttributeNames != null
 * @postcondition result != null
 */
private static Integer[][] getAttributeIdsFromNames(String[][] asAttributeNames, Integer iSourceModuleId,
        Integer iTargetModuleId) {
    if (asAttributeNames == null) {
        throw new NullArgumentException("asAttributeNames");
    }
    final AttributeCache attrcache = AttributeCache.getInstance();
    final Integer[][] aiAttributeIds = new Integer[asAttributeNames.length][2];

    for (int i = 0; i < asAttributeNames.length; i++) {
        String sSourceAttributeName = asAttributeNames[i][0];
        String sTargetAttributeName = asAttributeNames[i][1];
        aiAttributeIds[i][0] = attrcache.getAttribute(iSourceModuleId, sSourceAttributeName).getId();
        aiAttributeIds[i][1] = attrcache.getAttribute(iTargetModuleId, sTargetAttributeName).getId();
    }

    assert aiAttributeIds != null;
    return aiAttributeIds;
}

From source file:org.nuclos.server.genericobject.ejb3.GenericObjectFacadeBean.java

/**
 * gets generic object with dependants vo for a given generic object id (historical, readonly view)
 * @param iGenericObjectId id of generic object to show historical information for
 * @param dateHistorical date to show historical information for
 * @return generic object with dependants vo at the given point in time
 * @throws CommonFinderException if the given object didn't exist at the given point in time.
 * @precondition dateHistorical != null/*from   w  ww  . ja  va  2  s. com*/
 * @postcondition result != null
 * @nucleus.permission mayRead(module)
 */
@RolesAllowed("Login")
public GenericObjectWithDependantsVO getHistorical(int iGenericObjectId, Date dateHistorical,
        String customUsage) throws CommonFinderException, CommonPermissionException {
    debug("Entering getHistorical(Integer iGenericObjectId, Date dateHistorical)");

    if (dateHistorical == null) {
        throw new NullArgumentException("dateHistorical");
    }
    final RuleObjectContainerCVO loccvo = this.getRuleObjectContainerCVO(Event.UNDEFINED, iGenericObjectId,
            customUsage);
    final GenericObjectVO govoResult = loccvo.getGenericObject();
    final DependantMasterDataMap mpDependantsResult = loccvo.getDependants();

    final Calendar calendar = new GregorianCalendar();
    calendar.setTime(dateHistorical);

    // If dateHistorical has no time components, we can assume that the user wants to see the state of the object at the end of that day.
    if (calendar.get(Calendar.HOUR_OF_DAY) + calendar.get(Calendar.MINUTE)
            + calendar.get(Calendar.SECOND) == 0) {
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 0);
    }
    dateHistorical = calendar.getTime();

    // Check if the object existed at the historical date:
    final Date dateCreatedAt = govoResult.getCreatedAt();
    if (dateHistorical.before(dateCreatedAt)) {
        throw new CommonFinderException("genericobject.facade.exception.1");//"Das Objekt existierte zum angegebenen Zeitpunkt nicht.");
    }

    debug("Historical Date we want to see  : " + dateHistorical.toString());
    debug("Date of creation of record      : " + dateCreatedAt.toString());

    govoResult.setAttributes(GenericObjectFacadeHelper
            .getHistoricalAttributes(govoResult, dateHistorical, mpDependantsResult).values());

    this.debug("Leaving getHistorical(Integer iGenericObjectId, Date dateHistorical)");

    assert govoResult != null;

    return new GenericObjectWithDependantsVO(govoResult, mpDependantsResult);
}

From source file:org.nuclos.server.genericobject.ejb3.GenericObjectFacadeBean.java

@RolesAllowed("Login")
public GenericObjectWithDependantsVO modify(Integer iModuleId, GenericObjectWithDependantsVO lowdcvo,
        String customUsage)/*from  w  w  w .j a va  2 s.c  o m*/
        throws CommonCreateException, CommonFinderException, CommonRemoveException, CommonPermissionException,
        CommonStaleVersionException, NuclosBusinessException, CommonValidationException {

    if (iModuleId == null) {
        throw new NullArgumentException("iModuleId");
    }
    if (lowdcvo.getModuleId() != iModuleId) {
        throw new IllegalArgumentException("iModuleId");
    }

    final GenericObjectVO govoUpdated = this.modify(lowdcvo, lowdcvo.getDependants(), true, customUsage);

    final GenericObjectMetaDataCache lometadataprovider = GenericObjectMetaDataCache.getInstance();
    final GenericObjectWithDependantsVO result = new GenericObjectWithDependantsVO(govoUpdated,
            new DependantMasterDataMapImpl());
    final UsageCriteria usage = govoUpdated.getUsageCriteria(getAttributeCache(), customUsage);
    final Set<String> collSubEntityNames = lometadataprovider
            .getSubFormEntityNamesByLayoutId(lometadataprovider.getBestMatchingLayoutId(usage, false));
    _fillDependants(result, usage, collSubEntityNames, customUsage);

    return result;
}

From source file:org.nuclos.server.genericobject.ejb3.GenericObjectFacadeHelper.java

/**
 * fills the dependants of <code>lowdcvo</code> with the data from the required sub entities.
 * @param lowdcvo// ww w . jav  a2s .co  m
 * @param stRequiredSubEntityNames
 * @param subEntities
 * @precondition stRequiredSubEntityNames != null
 * @deprecated This method doesn't respect the foreign key field name. Replace with fillDependants().
 */
@Deprecated
public void _fillDependants(GenericObjectWithDependantsVO lowdcvo, UsageCriteria usage,
        Set<String> stRequiredSubEntityNames, Map<EntityAndFieldName, String> subEntities, String username,
        String customUsage) throws CommonFinderException {

    if (stRequiredSubEntityNames == null) {
        throw new NullArgumentException("stRequiredSubEntityNames");
    }

    // load the system attribute nuclosProcess for this genericobject (if not already loaded);
    // this is necessary for getting the dependant subforms in the next step
    Integer iAttributeId = NuclosEOField.PROCESS.getMetaData().getId().intValue();
    if (!lowdcvo.wasAttributeIdLoaded(iAttributeId)) {
        lowdcvo.addAttribute(iAttributeId);

        Set<Integer> stAttributeId = new HashSet<Integer>();
        stAttributeId.add(iAttributeId);

        CollectableSearchExpression clctSearchExpression = new CollectableSearchExpression(
                new CollectableIdCondition(lowdcvo.getId()));
        List<GenericObjectWithDependantsVO> lsgowdvo = getGenericObjects(lowdcvo.getModuleId(),
                clctSearchExpression, Collections.<String>emptySet(), username, customUsage);
        if (lsgowdvo.size() == 1 && lsgowdvo.get(0).getAttribute(iAttributeId) != null) {
            lowdcvo.setAttribute(lsgowdvo.get(0).getAttribute(iAttributeId));
        }
    }

    final Map<EntityAndFieldName, String> collSubEntities = (subEntities != null) ? subEntities :
    // getLayoutFacade().getSubFormEntityAndParentSubFormEntityNames(Modules.getInstance().getEntityNameByModuleId(lowdcvo.getModuleId()),lowdcvo.getId(),false);
            getLayoutFacade().getSubFormEntityAndParentSubFormEntityNamesByGO(usage);

    for (EntityAndFieldName eafn : collSubEntities.keySet()) {
        String sSubEntityName = eafn.getEntityName();
        // care only about subforms which are on the highest level and in the given set of entity names
        if (collSubEntities.get(eafn) == null && stRequiredSubEntityNames != null
                && (stRequiredSubEntityNames.isEmpty() || stRequiredSubEntityNames.contains(sSubEntityName))) {
            String sForeignKeyField = eafn.getFieldName();
            if (sForeignKeyField == null) {
                sForeignKeyField = ModuleConstants.DEFAULT_FOREIGNKEYFIELDNAME;
            }
            final Collection<EntityObjectVO> collmdvo = masterDataFacadeHelper
                    .getDependantMasterData(sSubEntityName, sForeignKeyField, lowdcvo.getId(), username);
            //if (CollectionUtils.isNonEmpty(collmdvo))
            {
                lowdcvo.getDependants().addAllData(sSubEntityName, CollectionUtils.emptyIfNull(collmdvo));

                //               this is not necessary here, because the callers of this method don't work on child subform data
                //               // now read all dependant data of the child subforms
                //               for (MasterDataVO mdVO : collmdvo) {
                //                  mdfacade.readAllDependants(sSubEntityName, mdVO.getIntId(), mdVO.getDependants(), mdVO.isRemoved(), sSubEntityName, collSubEntities);
                //               }
            }
        }
    }
}