Example usage for org.springframework.util Assert hasLength

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

Introduction

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

Prototype

@Deprecated
public static void hasLength(@Nullable String text) 

Source Link

Document

Assert that the given String is not empty; that is, it must not be null and not the empty String.

Usage

From source file:com.dianping.cache.service.impl.CacheConfigurationServiceImpl.java

@Override
public void incVersion(String category) {
    Assert.hasLength(category);/*from  w  w w . j av a  2  s  . c  om*/

    try {
        if (cacheKeyConfigurationService.incAndRetriveVersion(category) != null) {
            logCacheVersionUpgrade(category, true);
        } else {
            logCacheVersionUpgrade(category, false);
        }
    } catch (RuntimeException e) {
        logCacheVersionUpgrade(category, false);
        throw e;
    }
}

From source file:com.dianping.cache.service.impl.CacheConfigurationServiceImpl.java

@Override
public void pushCategoryConfig(String category, String serverOrGroup) {
    Assert.hasLength(category);
    List<String> destinations = getDestinations(serverOrGroup);

    CacheKeyConfiguration config = cacheKeyConfigurationService.find(category);
    if (config != null) {
        try {/*  ww  w .j av  a 2s .c o  m*/
            final CacheKeyTypeVersionUpdateDTO message = new CacheKeyTypeVersionUpdateDTO();
            message.setAddTime(System.currentTimeMillis());
            message.setMsgValue(category);
            message.setVersion(String.valueOf(config.getVersion()));
            message.setDestinations(destinations);
            cacheMessageProducer.sendMessageToTopic(message);
            logCacheConfigPush(category, destinations, true);
        } catch (RuntimeException e) {
            logCacheConfigPush(category, destinations, false);
            throw e;
        }
    } else {
        logger.warn("Push category[" + category + "] config failed, the category not found.");
    }
}

From source file:ChartThemesApp.java

/**
 * @param fileName/*w w w . j a va2 s. c o  m*/
 *            to be found on a class path.
 * @return file found on class path.
 */
public final static File findFile(String fileName) {
    Assert.hasLength(fileName);
    URL url = ChartThemesApp.class.getResource(fileName);
    Assert.notNull(url);
    return new File(url.getFile());
}

From source file:de.blizzy.documentr.access.DocumentrPermissionEvaluator.java

@Override
public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType,
        Object permission) {/*from  w ww .ja  va 2 s.  c o  m*/

    Assert.notNull(authentication);
    Assert.notNull(targetId);
    Assert.hasLength(targetType);
    Assert.notNull(permission);

    // not used
    return false;
}

From source file:de.blizzy.documentr.access.GrantedAuthorityTarget.java

/**
 * Constructs a new target object./*from ww w  . jav  a2 s  .c  om*/
 *
 * @param targetId the ID of the target object
 * @param type the type of the target object
 */
public GrantedAuthorityTarget(String targetId, Type type) {
    Assert.hasLength(targetId);
    Assert.isTrue(!targetId.equals(ANY));
    Assert.isTrue(!targetId.endsWith("/" + ANY)); //$NON-NLS-1$
    Assert.notNull(type);

    this.targetId = targetId;
    this.type = type;
}

From source file:de.blizzy.documentr.access.OpenId.java

/**
 * Constructs a new OpenID.//from w  ww  . j a v  a  2s.c  o m
 *
 * @param delegateId the delegate ID
 * @param realId the real ID
 */
public OpenId(String delegateId, String realId) {
    Assert.hasLength(delegateId);
    Assert.hasLength(realId);

    this.delegateId = delegateId;
    this.realId = realId;
}

From source file:de.blizzy.documentr.access.RoleGrantedAuthority.java

/**
 * Constructs a new role granted authority.
 *
 * @param target the target object//from   w ww . j  a v  a2 s. c  o  m
 * @param roleName the name of the role being granted
 */
public RoleGrantedAuthority(GrantedAuthorityTarget target, String roleName) {
    Assert.notNull(target);
    Assert.hasLength(roleName);

    this.target = target;
    this.roleName = roleName;
}

From source file:de.blizzy.documentr.access.UserStore.java

/**
 * Returns the user that has the specified login name.
 *
 * @throws UserNotFoundException when the user could not be found
 */// ww w  . j a va 2  s.  c  o m
public User getUser(String loginName) throws IOException {
    Assert.hasLength(loginName);

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
        String json = BlobUtils.getHeadContent(repo.r(), loginName + USER_SUFFIX);
        if (json == null) {
            throw new UserNotFoundException(loginName);
        }

        return getUser(loginName, json);
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.access.UserStore.java

/**
 * Returns the role that has the specified name.
 *
 * @throws RoleNotFoundException when the role could not be found
 *//* w  w  w  .j  a va  2 s .c  om*/
public Role getRole(String roleName) throws IOException {
    Assert.hasLength(roleName);

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
        String json = BlobUtils.getHeadContent(repo.r(), roleName + ROLE_SUFFIX);
        if (json == null) {
            throw new RoleNotFoundException(roleName);
        }

        Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
        Map<String, Object> roleMap = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
        }.getType());
        @SuppressWarnings("unchecked")
        Collection<String> permissions = (Collection<String>) roleMap.get("permissions"); //$NON-NLS-1$
        EnumSet<Permission> rolePermissions = EnumSet.noneOf(Permission.class);
        for (String permission : permissions) {
            rolePermissions.add(Permission.valueOf(permission));
        }
        Role role = new Role(roleName, rolePermissions);
        return role;
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.access.UserStore.java

/**
 * Saves a user's authorities/*from   w ww .  j  a  v a2 s. co m*/
 *
 * @param loginName the login name of the user whose authorities are to be saved
 * @param authorities the user's authorities to be saved
 * @param currentUser the user performing the save operation
 *
 * @throws UserNotFoundException when the user does not exist
 */
public void saveUserAuthorities(String loginName, Set<RoleGrantedAuthority> authorities, User currentUser)
        throws IOException {

    Assert.hasLength(loginName);
    Assert.notNull(authorities);
    Assert.notNull(currentUser);
    if (!loginName.equals(ANONYMOUS_USER_LOGIN_NAME)) {
        // check that user exists by trying to load it
        getUser(loginName);
    }

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
        saveUserAuthorities(loginName, authorities, repo, currentUser, true);
    } catch (GitAPIException e) {
        throw new IOException(e);
    } finally {
        Closeables.closeQuietly(repo);
    }
}