List of usage examples for org.apache.commons.lang ArrayUtils isEmpty
public static boolean isEmpty(boolean[] array)
Checks if an array of primitive booleans is empty or null
.
From source file:net.ymate.platform.cache.impl.DefaultSerializer.java
public Object deserialize(byte[] bytes) throws Exception { if (ArrayUtils.isEmpty(bytes)) { return null; }//from w ww . j a v a 2 s. com ObjectInputStream _input = null; try { _input = new ObjectInputStream(new ByteArrayInputStream(bytes)); return _input.readObject(); } finally { IOUtils.closeQuietly(_input); } }
From source file:net.ymate.platform.plugin.Plugins.java
/** * @param clazz ?/*ww w. j a v a2 s.c o m*/ * @return ???? * @throws Exception ?? */ private static DefaultPluginConfig loadConfig(Class<? extends IPluginFactory> clazz) throws Exception { DefaultPluginConfig _config = null; if (clazz != null && clazz.isAnnotationPresent(PluginFactory.class)) { _config = new DefaultPluginConfig(); // PluginFactory _factoryAnno = clazz.getAnnotation(PluginFactory.class); if (StringUtils.isNotBlank(_factoryAnno.pluginHome())) { _config.setPluginHome(new File(_factoryAnno.pluginHome())); } String[] _packages = _factoryAnno.autoscanPackages(); if (ArrayUtils.isEmpty(_packages)) { _packages = new String[] { clazz.getPackage().getName() }; } _config.setAutoscanPackages(Arrays.asList(_packages)); _config.setIncludedClassPath(_factoryAnno.includedClassPath()); _config.setAutomatic(_factoryAnno.automatic()); // IPluginEventListener _listener = ClassUtils.impl(_factoryAnno.listenerClass(), IPluginEventListener.class); if (_listener != null) { _config.setPluginEventListener(_listener); } else { _config.setPluginEventListener(new DefaultPluginEventListener()); } } return _config; }
From source file:net.ymate.platform.validation.validate.RequriedValidator.java
public ValidateResult validate(ValidateContext context) { boolean _matched = false; Object _paramValue = context.getParamValue(); if (_paramValue == null) { _matched = true;//from w w w . j av a 2s . com } else { if (!_paramValue.getClass().isArray()) { if (StringUtils.isBlank(BlurObject.bind(_paramValue).toStringValue())) { _matched = true; } } else { _matched = ArrayUtils.isEmpty((Object[]) _paramValue); } } if (_matched) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _pName, _pName); // String _msg = StringUtils.trimToNull(((VRequried) context.getAnnotation()).msg()); if (_msg != null) { _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, _msg, _msg, _pName); } else { String __REQURIED = "ymp.validation.requried"; _msg = I18N.formatMessage(VALIDATION_I18N_RESOURCE, __REQURIED, "{0} must be requried.", _pName); } return new ValidateResult(context.getParamName(), _msg); } return null; }
From source file:nl.knaw.huygens.timbuctoo.index.solr.SolrInputDocGenerator.java
/** * Evil reflection stuff to deal with getting strings/stuff out of arrays of objects. * It will execute the result of applying the array of methods on each of the objects. *//*www .j av a 2 s . c o m*/ private void indexArray(SolrInputDocument doc, String fieldName, Object[] array, boolean canBeEmpty, String... methods) { try { if (!ArrayUtils.isEmpty(array)) { for (Object o : array) { indexObject(doc, fieldName, o, canBeEmpty, methods); } } else if (!canBeEmpty && !StringUtils.isEmpty(fieldName)) { doc.addField(fieldName, "(empty)"); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:nl.strohalm.cyclos.controls.groups.customizedFiles.StopCustomizingGroupFileAction.java
@Override protected ActionForward executeAction(final ActionContext context) throws Exception { final StopCustomizingGroupFileForm form = context.getForm(); final long id = form.getFileId(); final long groupId = form.getGroupId(); if (id <= 0L || groupId <= 0L) { throw new ValidationException(); }//from www . ja va 2 s . c o m final CustomizedFile file = customizedFileService.load(id, CustomizedFile.Relationships.GROUP); if (file.getGroup() == null || !file.getGroup().getId().equals(groupId)) { throw new ValidationException(); } if (file.getGroup() instanceof MemberGroup) { // and BrokerGroup customizedFileService.stopCustomizingForMemberGroup(file); } else if (file.getGroup() instanceof OperatorGroup) { customizedFileService.stopCustomizingForOperatorGroup(file); } else if (file.getGroup() instanceof AdminGroup) { customizedFileService.stopCustomizingForAdminGroup(file); } else { throw new ValidationException(); } context.sendMessage("group.customizedFiles.removed"); // Remove the physical file final File physicalFile = CustomizationHelper.customizedFileOf(getServlet().getServletContext(), file); physicalFile.delete(); // Remove the directory if empty final File dir = physicalFile.getParentFile(); if (ArrayUtils.isEmpty(dir.list())) { dir.delete(); } return ActionHelper.redirectWithParam(context.getRequest(), context.getSuccessForward(), "groupId", groupId); }
From source file:nl.strohalm.cyclos.controls.groups.groupFilters.customizedFiles.StopCustomizingGroupFilterFileAction.java
@Override protected ActionForward executeAction(final ActionContext context) throws Exception { final StopCustomizingGroupFilterFileForm form = context.getForm(); final long id = form.getFileId(); final long groupFilterId = form.getGroupFilterId(); if (id <= 0L || groupFilterId <= 0L) { throw new ValidationException(); }//from ww w . j a va2s. com final CustomizedFile file = customizedFileService.load(id); if (file.getGroupFilter() == null || !file.getGroupFilter().getId().equals(groupFilterId)) { throw new ValidationException(); } customizedFileService.stopCustomizingForGroupFilter(file); context.sendMessage("groupFilter.customizedFiles.removed"); // Remove the physical file final File physicalFile = CustomizationHelper.customizedFileOf(getServlet().getServletContext(), file); physicalFile.delete(); // Remove the directory if empty final File dir = physicalFile.getParentFile(); if (ArrayUtils.isEmpty(dir.list())) { dir.delete(); } return ActionHelper.redirectWithParam(context.getRequest(), context.getSuccessForward(), "groupFilterId", groupFilterId); }
From source file:nl.strohalm.cyclos.controls.groups.groupFilters.RemoveGroupFilterAction.java
@Override protected ActionForward executeAction(final ActionContext context) throws Exception { final RemoveGroupFilterForm form = context.getForm(); // Remove the group filter final long id = form.getGroupFilterId(); final GroupFilter groupFilter = groupFilterService.load(id, GroupFilter.Relationships.CUSTOMIZED_FILES); final Collection<CustomizedFile> customizedFiles = groupFilter.getCustomizedFiles(); groupFilterService.remove(id);/*from www. j a va 2 s. c o m*/ // Remove the physical customized files for the group for (final CustomizedFile customizedFile : customizedFiles) { final File physicalFile = CustomizationHelper.customizedFileOf(getServlet().getServletContext(), customizedFile); physicalFile.delete(); // Remove the directory if empty final File dir = physicalFile.getParentFile(); if (ArrayUtils.isEmpty(dir.list())) { dir.delete(); } } context.sendMessage("groupFilter.removed"); return context.getSuccessForward(); }
From source file:nl.strohalm.cyclos.controls.groups.RemoveGroupAction.java
@Override protected ActionForward executeAction(final ActionContext context) throws Exception { final RemoveGroupForm form = context.getForm(); final long id = form.getGroupId(); if (id <= 0) { throw new ValidationException(); }/*ww w. j a v a 2 s .c om*/ try { final Group group = groupService.load(id, Group.Relationships.CUSTOMIZED_FILES); final Collection<CustomizedFile> customizedFiles = group.getCustomizedFiles(); if (group instanceof AdminGroup) { groupService.removeAdmin(id); } else if (group instanceof BrokerGroup) { groupService.removeBroker(id); } else if (group instanceof MemberGroup) { groupService.removeMember(id); } else { groupService.removeOperator(id); } // Remove the physical customized files for the group for (final CustomizedFile customizedFile : customizedFiles) { final File physicalFile = CustomizationHelper.customizedFileOf(getServlet().getServletContext(), customizedFile); physicalFile.delete(); // Remove the directory if empty final File dir = physicalFile.getParentFile(); if (ArrayUtils.isEmpty(dir.list())) { dir.delete(); } } context.sendMessage("group.removed"); } catch (final Exception e) { context.sendMessage("group.error.removing"); } return context.getSuccessForward(); }
From source file:nl.strohalm.cyclos.dao.accounts.cards.CardDAOImpl.java
@Override public Card loadByNumber(final BigInteger number, final Relationship... fetch) { Card card = uniqueResult("from Card c where c.cardNumber = :number", Collections.singletonMap("number", number)); if (card == null) { throw new EntityNotFoundException(Card.class); }//from w w w . j a v a 2s. c o m if (!ArrayUtils.isEmpty(fetch)) { card = getFetchDao().fetch(card, fetch); } return card; }
From source file:nl.strohalm.cyclos.dao.accounts.fee.account.MemberAccountFeeLogDAOImpl.java
@Override public int prepareCharge(final AccountFeeLog log) { final Long[] groupIds = EntityHelper.toIds(log.getAccountFee().getGroups()); if (ArrayUtils.isEmpty(groupIds)) { // No groups to charge return 0; }/* w w w .j a va 2s . com*/ final MutableInt result = new MutableInt(); runNative(new JDBCCallback() { @Override public void execute(final JDBCWrapper jdbc) throws SQLException { String[] placeHolders = new String[groupIds.length]; Arrays.fill(placeHolders, "?"); StringBuilder sql = new StringBuilder(); sql.append(" insert into members_pending_charge"); sql.append(" (account_fee_log_id, member_id)"); sql.append(" select ?, id"); sql.append(" from members m"); sql.append(" where m.subclass = ?"); sql.append(" and m.group_id in (").append(StringUtils.join(placeHolders, ",")).append(')'); List<Object> args = new ArrayList<Object>(groupIds.length + 2); args.add(log.getId()); args.add("M"); CollectionUtils.addAll(args, groupIds); int totalMembers = jdbc.execute(sql.toString(), args.toArray()); result.setValue(totalMembers); } }); return result.intValue(); }