Example usage for org.springframework.util Assert isNull

List of usage examples for org.springframework.util Assert isNull

Introduction

In this page you can find the example usage for org.springframework.util Assert isNull.

Prototype

public static void isNull(@Nullable Object object, Supplier<String> messageSupplier) 

Source Link

Document

Assert that an object is null .

Usage

From source file:com.appleframework.monitor.service.ProjectService.java

public void create(Project project) throws IllegalArgumentException {
    Assert.isNull(findProject(project.getName()), "project  [" + project.getName() + "] has exist");
    MongoTemplate template = project.fetchMongoTemplate();
    Assert.notNull(template, "mongo uri is not access");
    Assert.notNull(template.getDb(), "mongo uri is not access");

    saveProject(project);//from w w w  . jav a 2 s  .  c  o m
}

From source file:fr.mby.opa.picsimpl.dao.DbProposalDao.java

@Override
public ProposalBag createBag(final ProposalBag bag, final long branchId) {
    Assert.notNull(bag, "No ProposalBag supplied !");
    Assert.isNull(bag.getId(), "Id should not be set for creation !");

    new TxCallback(this.getEmf()) {

        @Override/*from   w  ww.  java 2  s  .co  m*/
        // @SuppressWarnings("unchecked")
        protected void executeInTransaction(final EntityManager em) {
            // Retrieve branch
            final ProposalBranch branch = em.find(ProposalBranch.class, branchId,
                    LockModeType.PESSIMISTIC_WRITE);
            if (branch == null) {
                throw new ProposalBranchNotFoundException();
            }

            // Retrieve base bag (parent bag) and lock the row
            // final Query findParentQuery = em.createNamedQuery(ProposalBag.FIND_LAST_BRANCH_BAG);
            // findParentQuery.setParameter("branchId", branchId);
            // findParentQuery.setLockMode(LockModeType.PESSIMISTIC_WRITE);

            // Persist bag with its parent
            // final ProposalBag parentBag = Iterables.getFirst(findParentQuery.getResultList(), null);
            // bag.setBaseProposal(parentBag);
            // em.persist(bag);

            // Persist bag with its parent
            bag.setBaseProposal(branch.getHead());
            em.persist(bag);

            // Update branch head pointer
            branch.setHead(bag);
            em.merge(branch);
        }
    };

    return bag;
}

From source file:es.sas.lopd.infraestructura.seguridad.impl.DaoAuthenticationProvider.java

/**
 * Sets the PasswordEncoder instance to be used to encode and validate passwords.
 * If not set, the password will be compared as plain text.
 * <p>// w w  w.  j  a va2s .  c  o  m
 * For systems which are already using salted password which are encoded with a previous release, the encoder
 * should be of type {@code org.springframework.security.authentication.encoding.PasswordEncoder}. Otherwise,
 * the recommended approach is to use {@code org.springframework.security.crypto.password.PasswordEncoder}.
 *
 * @param passwordEncoder must be an instance of one of the {@code PasswordEncoder} types.
 */
public void setPasswordEncoder(Object passwordEncoder) {
    Assert.notNull(passwordEncoder, "passwordEncoder cannot be null");

    if (passwordEncoder instanceof PasswordEncoder) {
        this.passwordEncoder = (PasswordEncoder) passwordEncoder;
        return;
    }

    if (passwordEncoder instanceof org.springframework.security.crypto.password.PasswordEncoder) {
        final org.springframework.security.crypto.password.PasswordEncoder delegate = (org.springframework.security.crypto.password.PasswordEncoder) passwordEncoder;
        this.passwordEncoder = new PasswordEncoder() {
            public String encodePassword(String rawPass, Object salt) {
                checkSalt(salt);
                return delegate.encode(rawPass);
            }

            public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
                checkSalt(salt);
                return delegate.matches(rawPass, encPass);
            }

            private void checkSalt(Object salt) {
                Assert.isNull(salt, "Salt value must be null when used with crypto module PasswordEncoder");
            }
        };

        return;
    }

    throw new IllegalArgumentException("passwordEncoder must be a PasswordEncoder instance");
}

From source file:com.kurento.kmf.spring.KurentoApplicationContextUtils.java

public static AnnotationConfigApplicationContext createKurentoHandlerServletApplicationContext(
        Class<?> servletClass, String servletName, ServletContext sc, String handlerClassName) {
    Assert.notNull(sc, "Cannot create Kurento ServletApplicationContext from null ServletContext");
    Assert.notNull(servletClass, "Cannot create KurentoServletApplicationContext from a null Servlet class");
    Assert.notNull(servletClass, "Cannot create KurentoServletApplicationContext from a null Hanlder class");

    if (childContexts == null) {
        childContexts = new ConcurrentHashMap<String, AnnotationConfigApplicationContext>();
    }//  w ww  .  j a v  a  2  s.  co m

    AnnotationConfigApplicationContext childContext = childContexts
            .get(servletClass.getName() + ":" + servletName);
    Assert.isNull(childContext, "Pre-existing context found associated to servlet class "
            + servletClass.getName() + " and servlet name " + servletName);

    childContext = new AnnotationConfigApplicationContext();
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClassName(handlerClassName);
    childContext.registerBeanDefinition(handlerClassName, beanDefinition);
    if (!kurentoApplicationContextExists()) {
        createKurentoApplicationContext(sc);
    }
    childContext.setParent(getKurentoApplicationContext());
    childContext.refresh();
    childContexts.put(servletClass.getName(), childContext);

    return childContext;
}

From source file:am.ik.categolj2.domain.service.entry.EntryServiceImpl.java

@Override
@Transactional/*ww w.  ja  v  a2s. c o  m*/
@CacheEvict(value = { "recentPost", "entry" }, allEntries = true)
public Entry create(Entry entry, List<Category> category) {
    Assert.notNull(entry, "entry must not be null");
    Assert.isNull(entry.getCategory(), "entry.category must be null");
    Assert.notNull(category, "category must not be null or empty");
    Assert.notNull(entry.getTags(), "category must not be null");
    // create new tags
    tagRepository.save(entry.getTags().stream().filter(tag -> !tagRepository.exists(tag.getTagName()))
            .collect(Collectors.toList()));
    DateTime now = dateFactory.newDateTime();
    entry.setCreatedDate(now);
    entry.setLastModifiedDate(now);
    // createdBy,lastModifiedBy are set by AuditingEntityListener
    entryRepository.saveAndFlush(entry);
    Integer entryId = entry.getEntryId();
    for (Category c : category) {
        c.getCategoryPK().setEntryId(entryId);
    }
    entry.setCategory(category);
    return entry;
}

From source file:fr.mby.opa.picsimpl.dao.DbProposalDao.java

public AbstractUnitProposal createProposal(final AbstractUnitProposal proposal) {
    Assert.notNull(proposal, "No Proposal supplied !");
    Assert.isNull(proposal.getId(), "Id should not be set for creation !");

    new TxCallback(this.getEmf()) {

        @Override/*from   www.  j  a v a2s  .c  o m*/
        protected void executeInTransaction(final EntityManager em) {
            em.persist(proposal);
        }
    };

    return proposal;
}

From source file:oz.hadoop.yarn.api.net.ApplicationContainerServerImpl.java

/**
 * Performs message exchange session (request/reply) with the client identified by the {@link SelectionKey}.
 * Message data is contained in 'buffer' parameter. 
 * //from   w w w  .  j a v  a 2  s.  c o  m
 * The actual exchange happens asynchronously, so the return type is {@link Future} and returns immediately.
 * 
 * @param selectionKey
 * @param buffer
 * @return
 */
void process(SelectionKey selectionKey, ByteBuffer buffer, ReplyPostProcessor replyPostProcessor) {
    Assert.isNull(this.replyCallbackMap.putIfAbsent(selectionKey, replyPostProcessor),
            "Unprocessed callback remains attached to the SelectionKey. This must be a bug. Please report!");
    this.doWrite(selectionKey, buffer);
}

From source file:ph.fingra.statisticsweb.security.FingraphAnthenticationProvider.java

@Autowired
public void setPasswordEncoder(Object passwordEncoder) {

    Assert.notNull(passwordEncoder, "passwordEncoder cannot be null");

    if (passwordEncoder instanceof PasswordEncoder) {
        setPasswordEncoder((PasswordEncoder) passwordEncoder);
        return;/*from w  w  w . ja  v  a2 s. c  o  m*/
    }

    if (passwordEncoder instanceof org.springframework.security.crypto.password.PasswordEncoder) {
        final org.springframework.security.crypto.password.PasswordEncoder delegate = (org.springframework.security.crypto.password.PasswordEncoder) passwordEncoder;

        // password encoder for admin.properties
        adminPasswordEncoder = delegate;

        setPasswordEncoder(new PasswordEncoder() {
            public String encodePassword(String rawPass, Object salt) {
                checkSalt(salt);
                return delegate.encode(rawPass);
            }

            public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
                checkSalt(salt);
                return delegate.matches(rawPass, encPass);
            }

            private void checkSalt(Object salt) {
                Assert.isNull(salt, "Salt value must be null when used with crypto module PasswordEncoder");
            }
        });

        return;
    }

    throw new IllegalArgumentException("passwordEncoder must be a PasswordEncoder instance");
}

From source file:at.porscheinformatik.common.spring.web.extended.template.cache.AbstractTemplateCache.java

protected void addTemplate(String name, String location, Resource resource, ResourceType type,
        boolean optimizedResource, boolean skipProcessing) throws IOException {
    String templateName = cacheName + ":" + name;

    Template template = null;//  ww  w  . ja v a  2 s. c om

    // If the template should not be processed by an template engine we use
    // the StringTemplate
    if (skipProcessing) {
        template = new StringTemplate(type, templateName, optimizedResource, resource, location);
    } else {
        template = templateFactory.createTemplate(resource, templateName, location, type, optimizedResource);
    }

    if (optimizedResource) {
        Assert.isNull(optimizedTemplates.put(name, template),
                "Template " + name + " was added twice to the cache for optimized Templates");
    } else {
        Assert.isNull(templates.put(name, template), "Template " + name + " was added twice to the cache");
    }
}