Example usage for org.apache.commons.lang ArrayUtils isNotEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isNotEmpty

Introduction

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

Prototype

public static boolean isNotEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is not empty or not null.

Usage

From source file:org.apache.carbondata.processing.loading.parser.impl.StructParserImpl.java

@Override
public StructObject parse(Object data) {
    if (data != null) {
        String value = data.toString();
        if (!value.isEmpty() && !value.equals(nullFormat)) {
            String[] split = pattern.split(value, -1);
            if (ArrayUtils.isNotEmpty(split)) {
                Object[] array = new Object[children.size()];
                for (int i = 0; i < split.length && i < array.length; i++) {
                    array[i] = children.get(i).parse(split[i]);
                }/*from  w w  w.  j a  v a2s  .c  o m*/
                return new StructObject(array);
            }
        }
    }
    return null;
}

From source file:org.apache.carbondata.processing.newflow.parser.impl.ArrayParserImpl.java

@Override
public ArrayObject parse(Object data) {
    if (data != null) {
        String value = data.toString();
        if (!value.isEmpty() && !value.equals(nullFormat)) {
            String[] split = pattern.split(value, -1);
            if (ArrayUtils.isNotEmpty(split)) {
                Object[] array = new Object[split.length];
                for (int i = 0; i < split.length; i++) {
                    array[i] = child.parse(split[i]);
                }/*from   w w  w.ja va 2s.  c o m*/
                return new ArrayObject(array);
            }
        }
    }
    return null;
}

From source file:org.apache.directory.fortress.core.ant.UserAnt.java

/**
 * Set a photo on user's record/*w ww.  j ava2s. c  o m*/
 *
 * @param photo
 */
public void setPhoto(String photo) {
    this.photo = photo;
    if (StringUtils.isNotEmpty(photo)) {
        byte[] jpeg = getJpegPhoto(photo);
        if (ArrayUtils.isNotEmpty(jpeg)) {
            setJpegPhoto(jpeg);
        }
    }
}

From source file:org.apache.directory.fortress.core.cli.CommandLineInterpreter.java

/**
 * @param otherArgs//from w  w w.jav  a  2s  .  c  om
 */
private Set<String> loadCommandSet(String[] otherArgs) {
    Set<String> commands = null;
    if (ArrayUtils.isNotEmpty(otherArgs)) {
        commands = new HashSet<>();
        Collections.addAll(commands, otherArgs);
    }
    return commands;
}

From source file:org.apache.directory.fortress.core.impl.UserDAO.java

/**
 * @param entity//ww  w  . j  a v a  2s .c  o m
 * @return
 * @throws CreateException
 */
User create(User entity) throws CreateException {
    LdapConnection ld = null;

    try {
        entity.setInternalId();

        String dn = getDn(entity.getUserId(), entity.getContextId());

        Entry myEntry = new DefaultEntry(dn);

        myEntry.add(SchemaConstants.OBJECT_CLASS_AT, USER_OBJ_CLASS);
        myEntry.add(GlobalIds.FT_IID, entity.getInternalId());
        myEntry.add(SchemaConstants.UID_AT, entity.getUserId());

        // CN is required on inetOrgPerson object class, if caller did not set, use the userId:
        if (StringUtils.isEmpty(entity.getCn())) {
            entity.setCn(entity.getUserId());
        }

        myEntry.add(SchemaConstants.CN_AT, entity.getCn());

        // SN is required on inetOrgPerson object class, if caller did not set, use the userId:
        if (StringUtils.isEmpty(entity.getSn())) {
            entity.setSn(entity.getUserId());
        }

        myEntry.add(SchemaConstants.SN_AT, entity.getSn());

        // guard against npe
        myEntry.add(SchemaConstants.USER_PASSWORD_AT,
                ArrayUtils.isNotEmpty(entity.getPassword()) ? new String(entity.getPassword())
                        : new String(new char[] {}));
        myEntry.add(SchemaConstants.DISPLAY_NAME_AT, entity.getCn());

        if (StringUtils.isNotEmpty(entity.getTitle())) {
            myEntry.add(SchemaConstants.TITLE_AT, entity.getTitle());
        }

        if (StringUtils.isNotEmpty(entity.getEmployeeType())) {
            myEntry.add(EMPLOYEE_TYPE, entity.getEmployeeType());
        }

        /*
                TODO: add RFC2307BIS
                if ( StringUtils.isNotEmpty( entity.getUidNumber() ) )
                {
                    myEntry.add( UID_NUMBER, entity.getUidNumber() );
                }
                
                if ( StringUtils.isNotEmpty( entity.getGidNumber() ) )
                {
                    myEntry.add( GID_NUMBER, entity.getGidNumber() );
                }
                
                if ( StringUtils.isNotEmpty( entity.getHomeDirectory() ) )
                {
                    myEntry.add( HOME_DIRECTORY, entity.getHomeDirectory() );
                }
                
                if ( StringUtils.isNotEmpty( entity.getLoginShell() ) )
                {
                    myEntry.add( LOGIN_SHELL, entity.getLoginShell() );
                }
                
                if ( StringUtils.isNotEmpty( entity.getGecos() ) )
                {
                    myEntry.add( GECOS, entity.getGecos() );
                }
        */

        // These are multi-valued attributes, use the util function to load.
        // These items are optional.  The utility function will return quietly if item list is empty:
        loadAttrs(entity.getPhones(), myEntry, SchemaConstants.TELEPHONE_NUMBER_AT);
        loadAttrs(entity.getMobiles(), myEntry, MOBILE);
        loadAttrs(entity.getEmails(), myEntry, SchemaConstants.MAIL_AT);

        // The following attributes are optional:
        if (entity.isSystem() != null) {
            myEntry.add(SYSTEM_USER, entity.isSystem().toString().toUpperCase());
        }

        if (GlobalIds.IS_OPENLDAP && StringUtils.isNotEmpty(entity.getPwPolicy())) {
            String pwdPolicyDn = GlobalIds.POLICY_NODE_TYPE + "=" + entity.getPwPolicy() + ","
                    + getRootDn(entity.getContextId(), GlobalIds.PPOLICY_ROOT);
            myEntry.add(OPENLDAP_POLICY_SUBENTRY, pwdPolicyDn);
        }

        if (StringUtils.isNotEmpty(entity.getOu())) {
            myEntry.add(SchemaConstants.OU_AT, entity.getOu());
        }

        if (StringUtils.isNotEmpty(entity.getDescription())) {
            myEntry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
        }

        // props are optional as well:
        // Add "initial" property here.
        entity.addProperty("init", "");
        loadProperties(entity.getProperties(), myEntry, GlobalIds.PROPS);
        // map the userid to the name field in constraint:
        entity.setName(entity.getUserId());
        myEntry.add(GlobalIds.CONSTRAINT, ConstraintUtil.setConstraint(entity));
        loadAddress(entity.getAddress(), myEntry);

        if (ArrayUtils.isNotEmpty(entity.getJpegPhoto())) {
            myEntry.add(JPEGPHOTO, entity.getJpegPhoto());
        }

        ld = getAdminConnection();
        add(ld, myEntry, entity);
        entity.setDn(dn);
    } catch (LdapException e) {
        String error = "create userId [" + entity.getUserId() + "] caught LDAPException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.USER_ADD_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }

    return entity;
}

From source file:org.apache.directory.fortress.core.impl.UserDAO.java

/**
 * @param entity/*from www  .ja va  2  s . c  o m*/
 * @return
 * @throws UpdateException
 */
User update(User entity) throws UpdateException {
    LdapConnection ld = null;
    String userDn = getDn(entity.getUserId(), entity.getContextId());

    try {
        List<Modification> mods = new ArrayList<Modification>();

        if (StringUtils.isNotEmpty(entity.getCn())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.CN_AT,
                    entity.getCn()));
        }

        if (StringUtils.isNotEmpty(entity.getSn())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.SN_AT,
                    entity.getSn()));
        }

        if (StringUtils.isNotEmpty(entity.getOu())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.OU_AT,
                    entity.getOu()));
        }

        if (ArrayUtils.isNotEmpty(entity.getPassword())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE,
                    SchemaConstants.USER_PASSWORD_AT, new String(entity.getPassword())));
        }

        if (StringUtils.isNotEmpty(entity.getDescription())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE,
                    SchemaConstants.DESCRIPTION_AT, entity.getDescription()));
        }

        if (StringUtils.isNotEmpty(entity.getEmployeeType())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, EMPLOYEE_TYPE,
                    entity.getEmployeeType()));
        }

        if (StringUtils.isNotEmpty(entity.getTitle())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.TITLE_AT,
                    entity.getTitle()));
        }

        if (GlobalIds.IS_OPENLDAP && StringUtils.isNotEmpty(entity.getPwPolicy())) {
            String szDn = GlobalIds.POLICY_NODE_TYPE + "=" + entity.getPwPolicy() + ","
                    + getRootDn(entity.getContextId(), GlobalIds.PPOLICY_ROOT);
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, OPENLDAP_POLICY_SUBENTRY,
                    szDn));
        }

        if (entity.isSystem() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SYSTEM_USER,
                    entity.isSystem().toString().toUpperCase()));
        }

        if (entity.isTemporalSet()) {
            // map the userid to the name field in constraint:
            entity.setName(entity.getUserId());
            String szRawData = ConstraintUtil.setConstraint(entity);

            if (StringUtils.isNotEmpty(szRawData)) {
                mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.CONSTRAINT,
                        szRawData));
            }
        }

        if (PropUtil.isNotEmpty(entity.getProperties())) {
            loadProperties(entity.getProperties(), mods, GlobalIds.PROPS, true);
        }

        loadAddress(entity.getAddress(), mods);

        // These are multi-valued attributes, use the util function to load:
        loadAttrs(entity.getPhones(), mods, SchemaConstants.TELEPHONE_NUMBER_AT);
        loadAttrs(entity.getMobiles(), mods, MOBILE);
        loadAttrs(entity.getEmails(), mods, SchemaConstants.MAIL_AT);

        if (ArrayUtils.isNotEmpty(entity.getJpegPhoto())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, JPEGPHOTO,
                    entity.getJpegPhoto()));
        }

        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, userDn, mods, entity);
            entity.setDn(userDn);
        }

        entity.setDn(userDn);
    } catch (LdapException e) {
        String error = "update userId [" + entity.getUserId() + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.USER_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }

    return entity;
}

From source file:org.apache.directory.fortress.core.impl.UserP.java

/**
 * Method will perform various validations to ensure the integrity of the User entity targeted for insertion
 * or updating in directory.  For example the ou attribute will be "read" from the OrgUnit dataset to ensure
 * that it is valid.  Data reasonability checks will be performed on all non-null attributes.
 * This method will also copy the source constraints to target entity iff the target input entity does not have set
 * prior to calling./*from w  ww.  j a  v a2  s  .co m*/
 *
 * @param entity   User entity contains data targeted for insertion or update.  The input role constraints will be accepted.
 * @param isUpdate if true update operation is being performed which specifies a different set of targeted attributes.
 * @throws SecurityException in the event of data validation error or DAO error on Org validation.
 */
private void validate(User entity, boolean isUpdate) throws SecurityException {
    if (!isUpdate) {
        // the UserId attribute is required on User:
        VUtil.userId(entity.getUserId());

        // the cn attribute is optional as input.  entity will default to userId if cn not set by caller on add:
        if (StringUtils.isNotEmpty(entity.getCn())) {
            VUtil.safeText(entity.getCn(), GlobalIds.CN_LEN);
        }
        // the sn attribute is optional as input.  entity will default to userId if sn not set by caller on add:
        if (StringUtils.isNotEmpty(entity.getSn())) {
            VUtil.safeText(entity.getSn(), GlobalIds.SN_LEN);
        }
        // password is not required on user object but user cannot execute AccessMgr or DelAccessMgr methods w/out pw.
        if (ArrayUtils.isNotEmpty(entity.getPassword())) {
            VUtil.password(entity.getPassword());
        }
        // the OU attribute is required:
        if (StringUtils.isEmpty(entity.getOu())) {
            String error = "OU validation failed, null or empty value";
            throw new ValidationException(GlobalErrIds.ORG_NULL_USER, error);
        }
        VUtil.orgUnit(entity.getOu());
        // ensure ou exists in the OS-U pool:
        OrgUnit ou = new OrgUnit(entity.getOu(), OrgUnit.Type.USER);
        ou.setContextId(entity.getContextId());
        if (!orgUnitP.isValid(ou)) {
            String error = "validate detected invalid orgUnit name [" + entity.getOu()
                    + "] adding user with userId [" + entity.getUserId() + "]";
            throw new ValidationException(GlobalErrIds.USER_OU_INVALID, error);
        }
        // description attribute is optional:
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            VUtil.description(entity.getDescription());
        }
    } else {
        // on User update, all attributes are optional:
        if (StringUtils.isNotEmpty(entity.getCn())) {
            VUtil.safeText(entity.getCn(), GlobalIds.CN_LEN);
        }
        if (StringUtils.isNotEmpty(entity.getSn())) {
            VUtil.safeText(entity.getSn(), GlobalIds.SN_LEN);
        }
        if (ArrayUtils.isNotEmpty(entity.getPassword())) {
            VUtil.password(entity.getPassword());
        }
        if (StringUtils.isNotEmpty(entity.getOu())) {
            VUtil.orgUnit(entity.getOu());
            // ensure ou exists in the OS-U pool:
            OrgUnit ou = new OrgUnit(entity.getOu(), OrgUnit.Type.USER);
            ou.setContextId(entity.getContextId());
            if (!orgUnitP.isValid(ou)) {
                String error = "validate detected invalid orgUnit name [" + entity.getOu()
                        + "] updating user wth userId [" + entity.getUserId() + "]";
                throw new ValidationException(GlobalErrIds.USER_OU_INVALID, error);
            }
        }
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            VUtil.description(entity.getDescription());
        }
    }

    // 1 OpenLDAP password policy name must be valid if set:
    if (StringUtils.isNotEmpty(entity.getPwPolicy())) {
        PwPolicy policy = new PwPolicy(entity.getPwPolicy());
        policy.setContextId(entity.getContextId());
        if (!policyP.isValid(policy)) {
            String error = "validate detected invalid OpenLDAP policy name [" + entity.getPwPolicy()
                    + "] for userId [" + entity.getUserId()
                    + "]. Assignment is optional for User but must be valid if specified.";
            throw new ValidationException(GlobalErrIds.USER_PW_PLCY_INVALID, error);
        }
    }

    // 2 Validate constraints on User object:
    ConstraintUtil.validate(entity);

    // 3 Validate or copy constraints on RBAC roles:
    if (CollectionUtils.isNotEmpty(entity.getRoles())) {
        RoleP rp = new RoleP();
        List<UserRole> roles = entity.getRoles();
        for (UserRole ure : roles) {
            Role inRole = new Role(ure.getName());
            inRole.setContextId(entity.getContextId());
            Role role = rp.read(inRole);
            ConstraintUtil.validateOrCopy(role, ure);
        }
    }

    // 4 Validate and copy constraints on Administrative roles:
    if (CollectionUtils.isNotEmpty(entity.getAdminRoles())) {
        List<UserAdminRole> uRoles = entity.getAdminRoles();
        for (UserAdminRole uare : uRoles) {
            AdminRole inRole = new AdminRole(uare.getName());
            inRole.setContextId(entity.getContextId());
            AdminRole outRole = admRoleP.read(inRole);
            ConstraintUtil.validateOrCopy(outRole, uare);

            // copy the ARBAC AdminRole attributes to UserAdminRole:
            copyAdminAttrs(outRole, uare);
        }
    }
}

From source file:org.apache.directory.fortress.core.util.VUtil.java

/**
 * Method will throw exception with supplied error id and object.method name if string reference is null or empty.
 *
 * @param value     contains the reference to check.
 * @param errorCode contains the error id to use if null.
 * @param method contains the method name of caller.
 * @throws ValidationException in the event supplied string is null or empty.
 *//*from  ww  w.j  a va 2 s  .c  o m*/
public static void assertNotNullOrEmpty(char[] value, int errorCode, String method) throws ValidationException {
    if (!ArrayUtils.isNotEmpty(value)) {
        String error = "assertContext detected null entity for method [" + method + "], error code ["
                + errorCode + "]";
        throw new ValidationException(errorCode, error);
    }
}

From source file:org.apache.falcon.regression.core.util.InstanceUtil.java

private static Cluster createFeedCluster(Validity feedValidity, Retention feedRetention, String clusterName,
        ClusterType clusterType, String partition, String tableUri, String[] locations) {

    Cluster cluster = new Cluster();
    cluster.setName(clusterName);//from  www  .  j  a  v  a2s.  c om
    cluster.setRetention(feedRetention);
    if (clusterType != null) {
        cluster.setType(clusterType);
    }
    cluster.setValidity(feedValidity);
    if (partition != null) {
        cluster.setPartition(partition);
    }

    // if table uri is not empty or null then set it.
    if (StringUtils.isNotEmpty(tableUri)) {
        cluster.setTable(getCatalogTable(tableUri));
    }
    Locations feedLocations = new Locations();
    if (ArrayUtils.isNotEmpty(locations)) {
        for (int i = 0; i < locations.length; i++) {
            Location oneLocation = new Location();
            oneLocation.setPath(locations[i]);
            if (i == 0) {
                oneLocation.setType(LocationType.DATA);
            } else if (i == 1) {
                oneLocation.setType(LocationType.STATS);
            } else if (i == 2) {
                oneLocation.setType(LocationType.META);
            } else if (i == 3) {
                oneLocation.setType(LocationType.TMP);
            } else {
                Assert.fail("unexpected value of locations: " + Arrays.toString(locations));
            }
            feedLocations.getLocations().add(oneLocation);
        }
        cluster.setLocations(feedLocations);
    }
    return cluster;
}

From source file:org.apache.falcon.regression.Entities.ProcessMerlin.java

/**
 * Sets process pipelines tag./*w w w .ja va  2  s. c  o  m*/
 * @param pipelines set of pipelines to be set to process
 */
public void setPipelineTag(String... pipelines) {
    if (ArrayUtils.isNotEmpty(pipelines)) {
        this.pipelines = StringUtils.join(pipelines, ",");
    } else {
        this.pipelines = null;
    }
}