Search in sources :

Example 76 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class MailManagerImpl method getMailByParams.

/**
 * Retrieve mail definition from db by params.
 * Mail contains all texts.
 * If mail not exists, or no texts exists null is returned.
 *
 * @param formId relation to VO form
 * @param appType application type
 * @param mailType mail type
 * @return mail if definition exists or null
 */
private ApplicationMail getMailByParams(Integer formId, AppType appType, MailType mailType) {
    ApplicationMail mail;
    // We want to use the initial notifications for the embedded applications
    if (appType == AppType.EMBEDDED) {
        appType = AppType.INITIAL;
    }
    // get mail def
    try {
        List<ApplicationMail> mails = jdbc.query(MAILS_SELECT_BY_PARAMS, (resultSet, arg1) -> new ApplicationMail(resultSet.getInt("id"), AppType.valueOf(resultSet.getString("app_type")), resultSet.getInt("form_id"), MailType.valueOf(resultSet.getString("mail_type")), resultSet.getBoolean("send")), formId, appType.toString(), mailType.toString());
        // set
        if (mails.size() != 1) {
            log.error("[MAIL MANAGER] Wrong number of mail definitions returned by unique params, expected 1 but was: {}", mails.size());
            return null;
        }
        mail = mails.get(0);
    } catch (EmptyResultDataAccessException ex) {
        return null;
    }
    List<MailText> texts;
    try {
        texts = jdbc.query(MAIL_TEXTS_SELECT_BY_MAIL_ID, (resultSet, arg1) -> new MailText(new Locale(resultSet.getString("locale")), resultSet.getString("subject"), resultSet.getString("text")), mail.getId());
    } catch (EmptyResultDataAccessException ex) {
        // if no texts it's error"HmacSHA256"
        log.error("[MAIL MANAGER] Mail do not contains any text message.", ex);
        return null;
    }
    texts.forEach(mt -> mail.getMessage().put(mt.getLocale(), mt));
    return mail;
}
Also used : Message(javax.mail.Message) JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) ApplicationMailNotExistsException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailNotExistsException) RegistrarManagerImpl(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl) LoggerFactory(org.slf4j.LoggerFactory) SecretKeySpec(javax.crypto.spec.SecretKeySpec) MessagingException(javax.mail.MessagingException) Autowired(org.springframework.beans.factory.annotation.Autowired) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) cz.metacentrum.perun.core.api(cz.metacentrum.perun.core.api) ApplicationMailExistsException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailExistsException) MailManager(cz.metacentrum.perun.registrar.MailManager) MembersManagerBl(cz.metacentrum.perun.core.bl.MembersManagerBl) ApplicationMailAlreadyRemovedException(cz.metacentrum.perun.registrar.exceptions.ApplicationMailAlreadyRemovedException) Matcher(java.util.regex.Matcher) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail) cz.metacentrum.perun.core.api.exceptions(cz.metacentrum.perun.core.api.exceptions) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) BigInteger(java.math.BigInteger) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) RegistrarException(cz.metacentrum.perun.registrar.exceptions.RegistrarException) MailForVoIdUpdated(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdUpdated) MailSending(cz.metacentrum.perun.audit.events.MailManagerEvents.MailSending) URN_GROUP_FROM_EMAIL(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl.URN_GROUP_FROM_EMAIL) Mac(javax.crypto.Mac) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) StandardCharsets(java.nio.charset.StandardCharsets) Application(cz.metacentrum.perun.registrar.model.Application) Pattern(java.util.regex.Pattern) MailException(org.springframework.mail.MailException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) java.util(java.util) MailForGroupIdRemoved(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdRemoved) MailForVoIdAdded(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdAdded) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) MailType(cz.metacentrum.perun.registrar.model.ApplicationMail.MailType) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) InternetAddress(javax.mail.internet.InternetAddress) MailSentForApplication(cz.metacentrum.perun.audit.events.MailManagerEvents.MailSentForApplication) DataSource(javax.sql.DataSource) AuthzResolverBlImpl(cz.metacentrum.perun.core.blImpl.AuthzResolverBlImpl) URN_VO_FROM_EMAIL(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl.URN_VO_FROM_EMAIL) FormNotExistsException(cz.metacentrum.perun.registrar.exceptions.FormNotExistsException) MailForGroupIdAdded(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdAdded) Logger(org.slf4j.Logger) AppType(cz.metacentrum.perun.registrar.model.Application.AppType) ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) RegistrarManager(cz.metacentrum.perun.registrar.RegistrarManager) MimeMessage(javax.mail.internet.MimeMessage) URLEncoder(java.net.URLEncoder) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) java.io(java.io) Utils(cz.metacentrum.perun.core.impl.Utils) MailForVoIdRemoved(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdRemoved) MailForGroupIdUpdated(cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdUpdated) URN_GROUP_FROM_NAME_EMAIL(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl.URN_GROUP_FROM_NAME_EMAIL) InvitationSentEvent(cz.metacentrum.perun.audit.events.MailManagerEvents.InvitationSentEvent) Transactional(org.springframework.transaction.annotation.Transactional) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail)

Example 77 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project SSM by Intel-bigdata.

the class TestBackUpInfoDao method testDelete.

@Test
public void testDelete() {
    backUpInfoDao.delete(1L);
    BackUpInfo[] backUpInfos = new BackUpInfo[2];
    backUpInfos[0] = new BackUpInfo(1, "test", "test", 1);
    backUpInfos[1] = new BackUpInfo(2, "test", "test", 1);
    backUpInfoDao.insert(backUpInfos);
    backUpInfoDao.delete(1L);
    Assert.assertTrue(backUpInfoDao.getByRid(2).equals(backUpInfos[1]));
    try {
        backUpInfoDao.getByRid(1);
    } catch (EmptyResultDataAccessException e) {
    }
}
Also used : BackUpInfo(org.smartdata.model.BackUpInfo) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Test(org.junit.Test)

Example 78 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project SSM by Intel-bigdata.

the class MetaStore method getHotFiles.

public List<FileAccessInfo> getHotFiles(List<AccessCountTable> tables, int topNum) throws MetaStoreException {
    Iterator<AccessCountTable> tableIterator = tables.iterator();
    if (tableIterator.hasNext()) {
        try {
            Map<Long, Integer> accessCounts = accessCountDao.getHotFiles(tables, topNum);
            if (accessCounts.size() == 0) {
                return new ArrayList<>();
            }
            Map<Long, String> idToPath = getFilePaths(accessCounts.keySet());
            List<FileAccessInfo> result = new ArrayList<>();
            for (Map.Entry<Long, Integer> entry : accessCounts.entrySet()) {
                Long fid = entry.getKey();
                if (idToPath.containsKey(fid) && entry.getValue() > 0) {
                    result.add(new FileAccessInfo(fid, idToPath.get(fid), entry.getValue()));
                }
            }
            return result;
        } catch (EmptyResultDataAccessException e) {
            return new ArrayList<>();
        } catch (Exception e) {
            throw new MetaStoreException(e);
        } finally {
            for (AccessCountTable accessCountTable : tables) {
                if (accessCountTable.isEphemeral()) {
                    this.dropTable(accessCountTable.getTableName());
                }
            }
        }
    } else {
        return new ArrayList<>();
    }
}
Also used : FileAccessInfo(org.smartdata.model.FileAccessInfo) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SQLException(java.sql.SQLException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) AccessCountTable(org.smartdata.metastore.dao.AccessCountTable) Map(java.util.Map) HashMap(java.util.HashMap)

Example 79 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project SSM by Intel-bigdata.

the class MetaStore method getFileState.

/**
 * Get FileState of the given path.
 *
 * @param path
 * @return
 * @throws MetaStoreException
 */
public FileState getFileState(String path) throws MetaStoreException {
    FileState fileState;
    try {
        fileState = fileStateDao.getByPath(path);
        // Fetch info from corresponding table to regenerate a specific file state
        switch(fileState.getFileType()) {
            case NORMAL:
                fileState = new NormalFileState(path);
                break;
            case COMPACT:
                fileState = smallFileDao.getFileStateByPath(path);
                break;
            case COMPRESSION:
                CompressionFileState compressionFileState = getCompressionInfo(path);
                if (compressionFileState != null) {
                    compressionFileState.setFileStage(fileState.getFileStage());
                    fileState = compressionFileState;
                }
                break;
            case S3:
                fileState = new S3FileState(path);
                break;
            default:
        }
    } catch (EmptyResultDataAccessException e1) {
        fileState = new NormalFileState(path);
    } catch (Exception e2) {
        throw new MetaStoreException(e2);
    }
    return fileState;
}
Also used : S3FileState(org.smartdata.model.S3FileState) NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) NormalFileState(org.smartdata.model.NormalFileState) CompressionFileState(org.smartdata.model.CompressionFileState) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) S3FileState(org.smartdata.model.S3FileState) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SQLException(java.sql.SQLException)

Example 80 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class AttributesManagerImpl method getAttributes.

@Override
public List<Attribute> getAttributes(PerunSession sess, Host host, List<String> attrNames) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("hId", host.getId());
    parameters.addValue("nSC", AttributesManager.NS_HOST_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_HOST_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_HOST_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_HOST_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("host_attr_values") + " from attr_names " + "left join host_attr_values on id=attr_id and host_id=:hId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new SingleBeanAttributeRowMapper<>(sess, this, host));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)99 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)46 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)31 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)9 Transactional (org.springframework.transaction.annotation.Transactional)9 Group (cz.metacentrum.perun.core.api.Group)8 User (cz.metacentrum.perun.core.api.User)8 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)7 SQLException (java.sql.SQLException)7 Test (org.junit.Test)6 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (cz.metacentrum.perun.core.api.Service)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3