Search in sources :

Example 51 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiI18nLabelInterface method getLabel.

public JAXBI18nLabel getLabel(Properties properties) throws ApiException, ApsSystemException {
    JAXBI18nLabel jaxbI18nLabel = null;
    try {
        String key = properties.getProperty("key");
        ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
        if (null == labelGroups) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' does not exist", Response.Status.CONFLICT);
        }
        jaxbI18nLabel = new JAXBI18nLabel(key, labelGroups);
    } catch (ApiException ae) {
        throw ae;
    } catch (ApsSystemException t) {
        _logger.error("error loading labels", t);
        throw new ApsSystemException("Error loading labels", t);
    }
    return jaxbI18nLabel;
}
Also used : JAXBI18nLabel(org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 52 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiI18nLabelInterface method updateInlineLabel.

public void updateInlineLabel(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
    try {
        this.checkLabels(jaxbI18nLabel);
        String key = jaxbI18nLabel.getKey();
        ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
        _logger.info("KEY ->  {} ", key);
        boolean isEdit = (null != labelGroups);
        if (!isEdit) {
            labelGroups = new ApsProperties();
        } else {
        // 
        }
        ApsProperties labels = jaxbI18nLabel.extractLabels();
        Iterator<Object> iterator = labels.keySet().iterator();
        while (iterator.hasNext()) {
            Object langKey = iterator.next();
            labelGroups.put(langKey, labels.get(langKey));
        }
        if (isEdit) {
            this.getI18nManager().updateLabelGroup(key, labelGroups);
            _logger.info("*** EDIT DONE *** -> {}", labelGroups);
        } else {
            this.getI18nManager().addLabelGroup(key, labelGroups);
            _logger.info("*** ADD DONE *** -> {}", labelGroups);
        }
    } catch (ApiException | ApsSystemException t) {
        _logger.error("Error updating label {} ", t);
        throw new ApiException("Error updating labels", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 53 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class LabelService method addLabelGroup.

@Override
public LabelDto addLabelGroup(LabelDto labelRequest) {
    try {
        BeanPropertyBindingResult validationResult = this.validateAddLabelGroup(labelRequest);
        if (validationResult.hasErrors()) {
            throw new ValidationGenericException(validationResult);
        }
        String code = labelRequest.getKey();
        ApsProperties languages = new ApsProperties();
        languages.putAll(labelRequest.getTitles());
        this.getI18nManager().addLabelGroup(code, languages);
        return labelRequest;
    } catch (ApsSystemException t) {
        logger.error("error in add label group with code {}", labelRequest.getKey(), t);
        throw new RestServerError("error in add label group", t);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 54 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class LabelService method updateLabelGroup.

@Override
public LabelDto updateLabelGroup(LabelDto labelRequest) {
    try {
        String code = labelRequest.getKey();
        ApsProperties labelGroup = this.getI18nManager().getLabelGroup(code);
        if (null == labelGroup) {
            logger.warn("no label found with key {}", code);
            throw new RestRourceNotFoundException(LabelValidator.ERRCODE_LABELGROUP_NOT_FOUND, "label", code);
        }
        BeanPropertyBindingResult validationResult = this.validateUpdateLabelGroup(labelRequest);
        if (validationResult.hasErrors()) {
            throw new ValidationGenericException(validationResult);
        }
        ApsProperties languages = new ApsProperties();
        languages.putAll(labelRequest.getTitles());
        this.getI18nManager().updateLabelGroup(code, languages);
        return labelRequest;
    } catch (ApsSystemException t) {
        logger.error("error in update label group with code {}", labelRequest.getKey(), t);
        throw new RestServerError("error in update label group", t);
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 55 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class OAuth2TokenDAO method addAccessToken.

public synchronized void addAccessToken(final OAuth2Token accessToken, boolean isLocalUser) throws ApsSystemException {
    Connection conn = null;
    PreparedStatement stat = null;
    try {
        conn = this.getConnection();
        conn.setAutoCommit(false);
        stat = isLocalUser ? conn.prepareStatement(INSERT_TOKEN_LOCAL_USER) : conn.prepareStatement(INSERT_TOKEN);
        stat.setString(1, accessToken.getAccessToken());
        stat.setString(2, accessToken.getClientId());
        stat.setTimestamp(3, new Timestamp(accessToken.getExpiresIn().getTime()));
        stat.setString(4, accessToken.getRefreshToken());
        stat.setString(5, accessToken.getGrantType());
        if (isLocalUser) {
            stat.setString(6, accessToken.getLocalUser());
        }
        stat.executeUpdate();
        conn.commit();
    } catch (ApsSystemException | SQLException t) {
        this.executeRollback(conn);
        logger.error("Error while adding an access token", t);
        throw new ApsSystemException("Error while adding an access token", t);
    } finally {
        closeDaoResources(null, stat, conn);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)452 ArrayList (java.util.ArrayList)53 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)48 RestServerError (org.entando.entando.aps.system.exception.RestServerError)39 ApsProperties (com.agiletec.aps.util.ApsProperties)26 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)23 HashMap (java.util.HashMap)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)21 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)21 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)20 Date (java.util.Date)20 StringReader (java.io.StringReader)18 IPage (com.agiletec.aps.system.services.page.IPage)17 List (java.util.List)17 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)16 File (java.io.File)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 Widget (com.agiletec.aps.system.services.page.Widget)15 IOException (java.io.IOException)15 Cache (org.springframework.cache.Cache)15