List of usage examples for org.springframework.util CollectionUtils isEmpty
public static boolean isEmpty(@Nullable Map<?, ?> map)
From source file:org.agatom.springatom.data.model.person.NPerson.java
public boolean addContact(final Collection<NPersonContact> contacts) { if (!CollectionUtils.isEmpty(contacts)) { for (NPersonContact contact : contacts) { contact.setAssignee(this); this._getContacts().add(contact); }//from w ww . j a va2 s . com return true; } return false; }
From source file:com.azaptree.services.spring.application.SpringApplicationService.java
private static void setSystemProperties(final Properties props) { if (CollectionUtils.isEmpty(props)) { return;//from w ww . j ava2s.c om } System.getProperties().putAll(props); }
From source file:com.devicehive.base.AbstractResourceTest.java
@SuppressWarnings("unchecked") protected final <T> T performRequest(String path, String method, Map<String, Object> params, Map<String, String> headers, Object body, Response.Status expectedStatus, Class<T> responseClass) { WebTarget wt = target;// ww w.j a v a 2 s . c o m if (StringUtils.isNoneBlank(path)) { wt = wt.path(path); } if (!CollectionUtils.isEmpty(params)) { for (Map.Entry<String, Object> entry : params.entrySet()) { wt = wt.queryParam(entry.getKey(), entry.getValue()); } } Invocation.Builder builder = wt.request(MediaType.APPLICATION_JSON_TYPE); if (!CollectionUtils.isEmpty(headers)) { for (Map.Entry<String, String> entry : headers.entrySet()) { builder = builder.header(entry.getKey(), entry.getValue()); } } if (StringUtils.isBlank(method)) { method = "GET"; } final Response response; switch (method.toUpperCase()) { case "GET": response = builder.get(); break; case "POST": Entity<String> entity = createJsonEntity(body); response = builder.post(entity); break; case "PUT": response = builder.put(createJsonEntity(body)); break; case "DELETE": response = builder.delete(); break; default: throw new IllegalArgumentException(String.format("Unknown http method '%s'", method)); } if (expectedStatus != null) { assertThat(response.getStatus(), is(expectedStatus.getStatusCode())); } if (responseClass == null || Response.class.isAssignableFrom(responseClass)) { return (T) response; } return response.readEntity(responseClass); }
From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java
@Test public void restSchemaDoesNotExistsTest() throws IOException { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON_UTF8); headers.add("graphql-schema", "no-such-schema"); GraphQLServerRequest qlQuery = new GraphQLServerRequest("{viewer{ id }}"); HttpEntity<GraphQLServerRequest> httpEntity = new HttpEntity<>(qlQuery, headers); ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange( "http://localhost:" + port + "/graphql", HttpMethod.POST, httpEntity, GraphQLServerResult.class); GraphQLServerResult result = responseEntity.getBody(); Assert.assertFalse(CollectionUtils.isEmpty(result.getErrors())); LOGGER.info(objectMapper.writeValueAsString(result)); }
From source file:org.pgptool.gui.ui.encrypttext.EncryptTextPm.java
private void notifyUserOfMissingKeysIfAny(Set<String> missedKeys) { if (CollectionUtils.isEmpty(missedKeys)) { return;//from w ww . j ava2s . c o m } UiUtils.messageBox(findRegisteredWindowIfAny(), text("error.notAllRecipientsAvailable", Arrays.asList(missedKeys)), text("term.attention"), JOptionPane.WARNING_MESSAGE); }
From source file:com.alibaba.otter.shared.arbitrate.impl.setl.rpc.monitor.AbstractProcessListener.java
/** * ???processIds?reply queue?processIds/*from w w w . ja v a 2 s . com*/ */ protected synchronized void compareReply(List<Long> processIds) { Object[] replyIds = replyProcessIds.toArray(); for (Object replyId : replyIds) { if (processIds.contains((Long) replyId) == false) { // reply id??processId // ?Listener???processprocessIdreply // ?processIds??process?? if (CollectionUtils.isEmpty(processIds) == false) { Long processId = processIds.get(0); if (processId > (Long) replyId) { // ??processIdreplyId, processId logger.info("## {} remove reply id [{}]", ClassUtils.getShortClassName(this.getClass()), (Long) replyId); replyProcessIds.remove((Long) replyId); } } } } }
From source file:com.sinet.gage.provision.service.impl.DomainFacadeImpl.java
/** * Creates the district domain//ww w.j a v a 2s .c o m * * @param token * DLAP API authentication token * @param request * CreateDistrictRequest pojo contians domain details */ @Override public boolean createDistrictDomain(String token, DistrictDomainRequest request) throws DomainDuplicateException, DomainNameDuplicateException { log.debug("Starts createDistrictDomain "); boolean success = Boolean.TRUE; List<Domain> domainList = mapToObject.mapToDomainList(request); String name = request.getName(); List<Integer> domainIds = null; try { // step 1 create domain with null data log.debug("Creating new domain " + name); // create EdivateLearn object with form Data EdivateLearn edivateLearn = createEdivateLearnObject(request, "district", request.isFullSubscription(), request.getSubscriptionStartDate(), request.getSubscriptionEndDate()); domainIds = domainService.createDomain(token, domainList, edivateLearn, request.getCourseCatalogs(), DomainType.DISTRICT); if (CollectionUtils.isEmpty(domainIds)) { log.debug("Failed to create new domain " + name); success = Boolean.FALSE; return success; } String domainId = domainIds.get(0).toString(); log.debug("Created new domain " + name + " with domain id " + domainId); // step 2 create admin user for newly created District log.debug("Creating administrator user for domain " + name + " with domain id " + domainId); success &= persistDistrict(token, request, domainId); log.debug("Created new administrator user for domain " + name + " with domain id " + domainId); // step 3 copy resources from district template to newly created // domain log.debug("Copy resources to new domain " + name + " with domain id " + domainId); success &= resourceService.copyResources(token, properties.getTemplateDistrictDomainId(), domainId); log.debug("Copied resource to new domain " + name + " with domain id " + domainId); // step 4 copy courses from one domain to another log.debug("Copy courses to new domain " + name); success &= courseService.copyCourses(token, request, domainId); log.debug("Copied courses to new domain " + name + " with domain id " + domainId); // Step 5: subscribes to courses or provider domains log.debug("Creating subscriptions to new domain " + name); success &= subscriptionService.createDistrictDomainSubscription(token, request, domainId); log.debug("Creating subscriptions to new domain " + name + " with domain id " + domainId); if (!success) { throw new Exception("Unable to create domain " + name + " with domain id " + domainId + " one or more steps failed rolling back"); } log.debug("Completed createDistrictDomain "); } catch (DomainDuplicateException | DomainNameDuplicateException e) { log.error("Error creating District domain with duplicate login prefix or name " + request.getLoginPrefix(), e); throw e; } catch (UserDuplicateException | Exception e) { log.error("Error creating District domain with user " + request.getName(), e); rollbackDistrictDomain(token, domainIds.get(0).toString()); success = Boolean.FALSE; } return success; }
From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java
/** * @return true if {@link Facet#fields()} is not empty *///from ww w .j a v a 2 s .co m public boolean hasFacetFields() { if (hasFacetAnnotation()) { return !CollectionUtils.isEmpty(getFacetFields()); } return false; }
From source file:org.wallride.repository.PostRepositoryImpl.java
@Override public Page<Post> search(PostSearchRequest request, Pageable pageable) { FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Post.class).get(); @SuppressWarnings("rawtypes") BooleanJunction<BooleanJunction> junction = qb.bool(); junction.must(qb.all().createQuery()); junction.must(qb.keyword().onField("drafted").ignoreAnalyzer().matching("_null_").createQuery()); if (StringUtils.hasText(request.getKeyword())) { Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer("synonyms"); String[] fields = new String[] { "title", "body", "tags.name", }; MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer); parser.setDefaultOperator(QueryParser.Operator.AND); Query query = null;/* ww w . j av a 2s.c om*/ try { query = parser.parse(request.getKeyword()); } catch (ParseException e1) { try { query = parser.parse(QueryParser.escape(request.getKeyword())); } catch (ParseException e2) { throw new RuntimeException(e2); } } junction.must(query); } if (request.getStatus() != null) { junction.must(qb.keyword().onField("status").matching(request.getStatus()).createQuery()); } if (StringUtils.hasText(request.getLanguage())) { junction.must(qb.keyword().onField("language").matching(request.getLanguage()).createQuery()); } if (request.getDateFrom() != null) { junction.must(qb.range().onField("date").above(request.getDateFrom()).createQuery()); } if (request.getDateTo() != null) { junction.must(qb.range().onField("date").below(request.getDateTo()).createQuery()); } if (!CollectionUtils.isEmpty(request.getTagNames())) { BooleanJunction<BooleanJunction> subJunction = qb.bool(); for (String tagName : request.getTagNames()) { subJunction.should(qb.phrase().onField("tags.name").sentence(tagName).createQuery()); } junction.must(subJunction.createQuery()); } if (!CollectionUtils.isEmpty(request.getPostIds())) { BooleanJunction<BooleanJunction> bool = qb.bool(); for (long postId : request.getPostIds()) { bool.should(qb.keyword().onField("id").matching(postId).createQuery()); } junction.must(bool.createQuery()); } Query searchQuery = junction.createQuery(); Session session = (Session) entityManager.getDelegate(); Criteria criteria = session.createCriteria(Post.class).setFetchMode("cover", FetchMode.JOIN) .setFetchMode("tags", FetchMode.JOIN).setFetchMode("categories", FetchMode.JOIN) .setFetchMode("customFieldValues", FetchMode.JOIN) .setFetchMode("customFieldValues.customField", FetchMode.JOIN) .setFetchMode("author", FetchMode.JOIN); Sort sort = new Sort(new SortField("sortDate", SortField.Type.STRING, true), new SortField("sortId", SortField.Type.LONG, true)); FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(searchQuery, Post.class) .setCriteriaQuery(criteria).setSort(sort); persistenceQuery.setFirstResult(pageable.getOffset()); persistenceQuery.setMaxResults(pageable.getPageSize()); int resultSize = persistenceQuery.getResultSize(); @SuppressWarnings("unchecked") List<Post> results = persistenceQuery.getResultList(); return new PageImpl<>(results, pageable, resultSize); }
From source file:com._4dconcept.springframework.data.marklogic.repository.support.SimpleMarklogicRepository.java
@Override public <S extends T> Optional<S> findOne(Example<S> example) { final List<S> results = findAll(example); if (CollectionUtils.isEmpty(results)) { return Optional.empty(); }//w ww . j a v a2 s . com if (results.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return Optional.of(results.get(0)); }