Search in sources :

Example 6 with PropertyServiceUnexpectedException

use of org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class StringIdAliasServiceEagerImpl method registerAlias.

/**
 * Will register alias (or retrieve already stored, only - useful for multi
 * server installation - environment - AKA webfarm)
 */
protected final synchronized long registerAlias(String str) {
    // WARNING: This method must be called only after getALiasFor invoked at
    // least once, otherwise NullPointerException might happen
    Long ret = aliases.get(str);
    // sanity check if someone has already stored it
    if (ret != null) {
        return ret.longValue();
    }
    long alias;
    try {
        try {
            alias = doCreateAlias(str);
        } catch (DuplicateKeyException dke) {
            log.debug("Looks like alias already exist in database, will load it");
            ret = stringIdAliasDao.findAliasFor(str);
            if (ret == null) {
                throw new PropertyServiceUnexpectedException("Failed to create alias because of duplicate, but later was unable to find that duplicate.");
            }
            alias = ret.longValue();
        }
    } catch (Throwable t) {
        throw new PropertyServiceUnexpectedException("Failed to store alias", t);
    }
    // store it locally
    aliases.put(str, alias);
    // ret
    return alias;
}
Also used : PropertyServiceUnexpectedException(org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException)

Example 7 with PropertyServiceUnexpectedException

use of org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class PropertyServiceImpl method findSubjectProperty.

@Override
public String findSubjectProperty(String appName, String domainName, String subjectId, String name) {
    checkArgumentsHaveText(appName, domainName, subjectId, name);
    try {
        long appId = appNameAlias.getAliasFor(appName);
        long domainId = domainNameAlias.getAliasFor(domainName);
        long propertyNameId = propertyNameAlias.getAliasFor(name);
        return propertyDao.findSubjectProperty(appId, domainId, subjectId, propertyNameId);
    } catch (Throwable t) {
        throw new PropertyServiceUnexpectedException("Failed to find subject property", t);
    }
}
Also used : PropertyServiceUnexpectedException(org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException)

Example 8 with PropertyServiceUnexpectedException

use of org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class PropertyServiceImpl method putSubjectsProperty.

@Transactional(rollbackFor = Throwable.class)
@Override
public void putSubjectsProperty(String appName, String domainName, List<String> subjectsIds, String name, String value) {
    if (CollectionUtils.isEmpty(subjectsIds)) {
        return;
    }
    checkArgumentsHaveText(appName, domainName, name);
    try {
        long appId = appNameAlias.getAliasFor(appName);
        long domainId = domainNameAlias.getAliasFor(domainName);
        long propertyNameId = propertyNameAlias.getAliasFor(name);
        for (String subjectId : subjectsIds) {
            propertyDao.putProperty(appId, domainId, subjectId, propertyNameId, value);
        }
    } catch (Throwable t) {
        propagatePropertyNameIfTruncationError(t, name);
        throw new PropertyServiceUnexpectedException("Failed to put subjects property", t);
    }
}
Also used : PropertyServiceUnexpectedException(org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with PropertyServiceUnexpectedException

use of org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class PropertyServiceImpl method deleteSubjectsProperties.

@Override
@Transactional(rollbackFor = Throwable.class)
public void deleteSubjectsProperties(String appName, String domainName, List<String> subjectsIds) {
    if (CollectionUtils.isEmpty(subjectsIds)) {
        return;
    }
    checkArgumentsHaveText(appName, domainName);
    try {
        long appId = appNameAlias.getAliasFor(appName);
        long domainId = domainNameAlias.getAliasFor(domainName);
        for (String subjectId : subjectsIds) {
            propertyDao.deleteSubjectProperties(appId, domainId, subjectId);
        }
    } catch (Throwable t) {
        throw new PropertyServiceUnexpectedException("Failed to delete subject properties", t);
    }
}
Also used : PropertyServiceUnexpectedException(org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with PropertyServiceUnexpectedException

use of org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class PropertyServiceImpl method findSubjectsProperty.

@Override
public Map<String, String> findSubjectsProperty(String appName, String domainName, List<String> subjectsIds, String name) {
    if (CollectionUtils.isEmpty(subjectsIds)) {
        return new HashMap<String, String>();
    }
    checkArgumentsHaveText(appName, domainName, name);
    try {
        long appId = appNameAlias.getAliasFor(appName);
        long domainId = domainNameAlias.getAliasFor(domainName);
        long propertyNameId = propertyNameAlias.getAliasFor(name);
        Map<String, String> ret = new HashMap<String, String>();
        for (String subjectId : subjectsIds) {
            String value = propertyDao.findSubjectProperty(appId, domainId, subjectId, propertyNameId);
            if (value != null) {
                ret.put(subjectId, value);
            }
        }
        return ret;
    } catch (Throwable t) {
        throw new PropertyServiceUnexpectedException("Failed to find subject property", t);
    }
}
Also used : HashMap(java.util.HashMap) PropertyServiceUnexpectedException(org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException)

Aggregations

PropertyServiceUnexpectedException (org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException)11 Transactional (org.springframework.transaction.annotation.Transactional)5 HashMap (java.util.HashMap)2 Map (java.util.Map)1 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 PagerParams (org.summerb.easycrud.api.dto.PagerParams)1 NamedProperty (org.summerb.properties.api.dto.NamedProperty)1 AliasEntry (org.summerb.properties.impl.dao.AliasEntry)1