List of usage examples for org.springframework.util CollectionUtils isEmpty
public static boolean isEmpty(@Nullable Map<?, ?> map)
From source file:com.vip.saturn.job.console.service.impl.ServerDimensionServiceImpl.java
@Override public Map<String, Object> getAllServersBriefInfo() { CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient(); HashMap<String, Object> model = new HashMap<String, Object>(); Map<String, ServerBriefInfo> sbfMap = new LinkedHashMap<String, ServerBriefInfo>(); List<String> jobs = new ArrayList<>(); try {//from w ww . ja v a 2s .c o m jobs = jobDimensionService.getAllUnSystemJobs(curatorFrameworkOp); } catch (SaturnJobConsoleException e) { logger.error(e.getMessage(), e); } Map<String, Map<String, Integer>> jobNameExecutorNameTotalLevel = new HashMap<>(); String executorNodePath = ExecutorNodePath.getExecutorNodePath(); if (curatorFrameworkOp.checkExists(executorNodePath)) { List<String> executors = curatorFrameworkOp.getChildren(executorNodePath); if (!CollectionUtils.isEmpty(executors)) { for (String executor : executors) { ServerBriefInfo sbf = new ServerBriefInfo(executor); String ip = curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(executor, "ip")); sbf.setServerIp(ip); String lastBeginTime = curatorFrameworkOp .getData(ExecutorNodePath.getExecutorNodePath(sbf.getExecutorName(), "lastBeginTime")); sbf.setLastBeginTime(null == lastBeginTime ? null : dateFormat.format(new Date(Long.parseLong(lastBeginTime)))); if (!Strings.isNullOrEmpty(ip)) { sbf.setStatus(ServerStatus.ONLINE); } else { sbf.setStatus(ServerStatus.OFFLINE); } sbf.setVersion( curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(executor, "version"))); if (!CollectionUtils.isEmpty(jobs)) { for (String jobName : jobs) { String serverNodePath = JobNodePath.getServerNodePath(jobName); if (!curatorFrameworkOp.checkExists(serverNodePath)) { continue; } if (Strings.isNullOrEmpty(sbf.getServerIp())) { String serverIp = curatorFrameworkOp .getData(JobNodePath.getServerNodePath(jobName, executor, "ip")); sbf.setServerIp(serverIp); } Map<String, Integer> executorNameWithTotalLevel = null; if (jobNameExecutorNameTotalLevel.containsKey(jobName)) { executorNameWithTotalLevel = jobNameExecutorNameTotalLevel.get(jobName); } else { executorNameWithTotalLevel = new LinkedHashMap<>(); jobNameExecutorNameTotalLevel.put(jobName, executorNameWithTotalLevel); } if (ServerStatus.ONLINE.equals(sbf.getStatus())) {// ??onlineExecutor executorNameWithTotalLevel.put(executor, 0); } String sharding = curatorFrameworkOp .getData(JobNodePath.getServerNodePath(jobName, executor, "sharding")); if (!Strings.isNullOrEmpty(sharding)) { sbf.setHasSharding(true);// ???? if (JobStatus.STOPPED.equals(jobDimensionService.getJobStatus(jobName))) { continue;// ?STOPPED?? } if (ServerStatus.OFFLINE.equals(sbf.getStatus())) {// offlineexecutor?? continue; } // concat executorSharding String executorSharding = jobName + ":" + sharding; if (Strings.isNullOrEmpty(sbf.getSharding())) {// ???? sbf.setSharding(executorSharding); } else { sbf.setSharding(sbf.getSharding() + "<br/>" + executorSharding); } // calculate totalLoadLevel String loadLevelNode = curatorFrameworkOp .getData(JobNodePath.getConfigNodePath(jobName, "loadLevel")); Integer loadLevel = 1; if (!Strings.isNullOrEmpty(loadLevelNode)) { loadLevel = Integer.parseInt(loadLevelNode); } Integer totalLoadLevel = sbf.getTotalLoadLevel(); int thisJobsLoad = (sharding.split(",").length * loadLevel); sbf.setTotalLoadLevel( (sbf.getTotalLoadLevel() == null ? 0 : totalLoadLevel) + thisJobsLoad); executorNameWithTotalLevel.put(executor, thisJobsLoad); } } } sbfMap.put(executor, sbf); } } model.put("serverInfos", sbfMap.values()); model.put("jobShardLoadLevels", jobNameExecutorNameTotalLevel); } return model; }
From source file:org.arrow.service.DefaultRepositoryService.java
/** * {@inheritDoc}/*from w w w .j ava 2s. c o m*/ */ @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void deploy(Definitions definitions) { if (CollectionUtils.isEmpty(definitions.getProcesses())) { logger.warn("no processes found, skip deployment"); return; } // use a visitor to cache all BPMN event definitions CacheBpmnEventDefinitionEntityVisitor defVisitor = getDefVisitor(); definitions.visit(defVisitor); for (Process process : definitions.getProcesses()) { Assert.notNull(process); prepareProcess(process, defVisitor.getCache()); // add a relationship from a process to each element which demands one process.visit(new AddProcessRelationEntityVisitor(process, template)); } // save the process meta data processMetaDataRepository.saveAll(prepareProcessMetaData(definitions)); // save the definitions template.save(definitions); }
From source file:nivance.jpa.cassandra.prepare.core.CassandraSessionFactoryBean.java
@Override public void afterPropertiesSet() { if (converter == null) { throw new IllegalArgumentException("converter is required"); }//from w w w .j a va 2 s. com super.afterPropertiesSet(); // mappingContext = converter.getMappingContext(); schemaOperations = new DefaultSchemaOperations(session, keyspace, converter); schemaCqlOperations = new DefaultSchemaCqlOperations(session, keyspace); if (StringUtils.hasText(keyspace)) { if (!CollectionUtils.isEmpty(tables)) { for (TableAttributes tableAttributes : tables) { String entityClassName = tableAttributes.getEntityClass(); Class<?> entityClass = loadClass(entityClassName); String useTableName = tableAttributes.getTableName() != null ? tableAttributes.getTableName() : this.getTableName(entityClass); if (keyspaceCreated) { createNewTable(useTableName, entityClass); } else if (keyspaceAttributes.isUpdate()) { TableMetadata table = schemaCqlOperations.getTableMetadata(useTableName); if (table == null) { createNewTable(useTableName, entityClass); } else { Optional<UpdateOperation> alter = schemaOperations.alterTable(useTableName, entityClass, true); if (alter.isPresent()) { alter.get().execute(); } schemaOperations.alterIndexes(useTableName, entityClass).execute(); } } else if (keyspaceAttributes.isValidate()) { TableMetadata table = schemaCqlOperations.getTableMetadata(useTableName); if (table == null) { throw new InvalidDataAccessApiUsageException( "not found table " + useTableName + " for entity " + entityClassName); } String query = schemaOperations.validateTable(useTableName, entityClass); if (query != null) { throw new InvalidDataAccessApiUsageException("invalid table " + useTableName + " for entity " + entityClassName + ". modify it by " + query); } List<String> queryList = schemaOperations.validateIndexes(useTableName, entityClass); if (!queryList.isEmpty()) { throw new InvalidDataAccessApiUsageException("invalid indexes in table " + useTableName + " for entity " + entityClassName + ". modify it by " + queryList); } } } } } }
From source file:org.openmrs.web.controller.patient.ShortPatientModel.java
/** * Constructor that creates a shortPatientModel object from a given patient object * * @param patient/* ww w. j av a 2 s. c o m*/ */ @SuppressWarnings("unchecked") public ShortPatientModel(Patient patient) { if (patient != null) { this.patient = patient; this.personName = patient.getPersonName(); this.personAddress = patient.getPersonAddress(); List<PatientIdentifier> activeIdentifiers = patient.getActiveIdentifiers(); if (activeIdentifiers.isEmpty()) { final PatientIdentifierType defaultIdentifierType = getDefaultIdentifierType(); activeIdentifiers.add(new PatientIdentifier(null, defaultIdentifierType, (LocationUtility.getUserDefaultLocation() != null) ? LocationUtility.getUserDefaultLocation() : LocationUtility.getDefaultLocation())); } identifiers = ListUtils.lazyList(new ArrayList<PatientIdentifier>(activeIdentifiers), FactoryUtils.instantiateFactory(PatientIdentifier.class)); List<PersonAttributeType> viewableAttributeTypes = Context.getPersonService() .getPersonAttributeTypes(PERSON_TYPE.PATIENT, ATTR_VIEW_TYPE.VIEWING); personAttributes = new ArrayList<PersonAttribute>(); if (!CollectionUtils.isEmpty(viewableAttributeTypes)) { for (PersonAttributeType personAttributeType : viewableAttributeTypes) { PersonAttribute persistedAttribute = patient.getAttribute(personAttributeType); //This ensures that empty attributes are added for those we want to display //in the view, but have no values PersonAttribute formAttribute = new PersonAttribute(personAttributeType, null); //send a clone to the form so that we can use the original to track changes in the values if (persistedAttribute != null) { BeanUtils.copyProperties(persistedAttribute, formAttribute); } personAttributes.add(formAttribute); } } } }
From source file:cognition.pipeline.data.DNCWorkUnitDao.java
private Object getObjectFromCoordinate(DNCWorkCoordinate coordinate) { SessionWrapper sessionWrapper = createSourceSession(); try {//from w w w. j a v a 2 s. co m Query coordinateQuery = sessionWrapper.getNamedQuery("getObjectFromCoordinate"); String queryString = coordinateQuery.getQueryString(); queryString = queryString.replace(":sourceTable", coordinate.getSourceTable()) .replace(":sourceColumn", coordinate.getSourceColumn()) .replace(":pkColumnName", coordinate.getPkColumnName()) .replace(":id", Long.toString(coordinate.getIdInSourceTable())); List result = getSQLResultFromSource(queryString); if (CollectionUtils.isEmpty(result)) { throw new WorkCoordinateNotFound("Coordinate is invalid. No data found at " + coordinate); } return result.get(0); } finally { sessionWrapper.closeSession(); } }
From source file:be.roots.taconic.pricingguide.respository.ModelRepositoryImpl.java
@Override public List<Model> findFor(List<String> modelList) throws IOException { final List<Model> models = new ArrayList<>(); if (!CollectionUtils.isEmpty(modelList)) { // make the modelList a set of unique ids final Set<String> modelIds = new HashSet<>(modelList); // check if "all" is passed; if so execute findAll for (String modelId : modelIds) { if ("all".equalsIgnoreCase(modelId)) { return findAll(); }/*w ww. ja va 2s .c om*/ } // find the models based on their ids for (String modelId : modelIds) { final Model model = findOne(modelId); if (model != null) { models.add(model); } else { LOGGER.error("Couldn't find model for " + modelId); } } } return models; }
From source file:io.spring.springoverflow.domain.Post.java
@PostLoad public void calculateVotes() { if (!CollectionUtils.isEmpty(votes)) { for (Vote vote : votes) { if (vote.getVoteType() == 2) { voteCount++;/*from w w w .j av a2s.c o m*/ } else if (vote.getVoteType() == 3) { voteCount--; } } } }
From source file:edu.wisc.wisccal.caldav2Exchange.impl.caldav.datagenerator.ICal4jTestDataGenerator.java
public void addToCalendarComputeSize(Calendar cal, Component comp) { long orgSize = ObjectSizeFetcher.getSerializedObjectSize(cal); cal.getComponents().add(comp);//from www .j a v a 2 s.c o m long serializedObjectSize = ObjectSizeFetcher.getSerializedObjectSize(cal); assertTrue(serializedObjectSize > orgSize); ComponentList components = cal.getComponents(); int compCount = 0; if (!CollectionUtils.isEmpty(components)) { compCount = components.size(); } log.info(compCount + " , " + serializedObjectSize); }
From source file:pe.gob.mef.gescon.service.impl.ConsultaServiceImpl.java
@Override public List<Consulta> getDestacadosByTipoConocimiento(HashMap filters) { List<Consulta> lista = new ArrayList<Consulta>(); try {/*from w w w . ja v a 2s . com*/ ConsultaDao consultaDao = (ConsultaDao) ServiceFinder.findBean("ConsultaDao"); List<HashMap> consulta = consultaDao.getDestacadosByTipoConocimiento(filters); if (!CollectionUtils.isEmpty(consulta)) { for (HashMap map : consulta) { Consulta c = new Consulta(); c.setIdconocimiento((BigDecimal) map.get("ID")); c.setNombre((String) map.get("NOMBRE")); String sumilla = (String) map.get("SUMILLA"); sumilla = sumilla != null ? sumilla : StringUtils.EMPTY; if (sumilla.length() > 160) { sumilla = sumilla.substring(0, 160); sumilla = sumilla.substring(0, sumilla.lastIndexOf(" ")).concat("..."); } c.setSumilla(sumilla); c.setFechaPublicacion((Date) map.get("FECHA")); c.setIdCategoria((BigDecimal) map.get("IDCATEGORIA")); c.setCategoria((String) map.get("CATEGORIA")); c.setIdTipoConocimiento((BigDecimal) map.get("IDTIPOCONOCIMIENTO")); c.setTipoConocimiento((String) map.get("TIPOCONOCIMIENTO")); c.setIdEstado((BigDecimal) map.get("IDESTADO")); c.setEstado((String) map.get("ESTADO")); lista.add(c); } } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } return lista; }
From source file:org.agatom.springatom.data.hades.model.enumeration.NEnumeration.java
public NEnumeration setEntries(final List<NEnumerationEntry> entries) { if (CollectionUtils.isEmpty(entries)) { throw new IllegalArgumentException("entries can not be null / empty"); }/*from ww w.j a v a2 s .c om*/ final NEnumeration self = this; this.entries = FluentIterable.from(entries).transform(new Function<NEnumerationEntry, NEnumerationEntry>() { @Nullable @Override public NEnumerationEntry apply(final NEnumerationEntry input) { return input.setEntry(self); } }).toSet(); return this; }