Search in sources :

Example 56 with ApsSystemException

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

the class OAuth2TokenDAO method deleteAccessToken.

@Override
public void deleteAccessToken(final String accessToken) throws ApsSystemException {
    Connection conn = null;
    PreparedStatement stat = null;
    try {
        conn = this.getConnection();
        conn.setAutoCommit(false);
        stat = conn.prepareStatement(DELETE_TOKEN);
        stat.setString(1, accessToken);
        stat.executeUpdate();
        conn.commit();
    } catch (ApsSystemException | SQLException t) {
        this.executeRollback(conn);
        logger.error(ERROR_REMOVE_ACCESS_TOKEN, t);
        throw new ApsSystemException(ERROR_REMOVE_ACCESS_TOKEN, t);
    } finally {
        closeDaoResources(null, stat, conn);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 57 with ApsSystemException

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

the class OAuth2TokenDAO method updateAccessToken.

public synchronized void updateAccessToken(final String accessToken, long seconds) throws ApsSystemException {
    Connection conn = null;
    PreparedStatement stat = null;
    try {
        conn = this.getConnection();
        conn.setAutoCommit(false);
        stat = conn.prepareStatement(UPDATE_TOKEN);
        Timestamp timestamp = new Timestamp(System.currentTimeMillis() + seconds * 1000);
        stat.setTimestamp(1, timestamp);
        stat.setString(2, accessToken);
        stat.executeUpdate();
        conn.commit();
    } catch (ApsSystemException | SQLException t) {
        this.executeRollback(conn);
        logger.error("Error while update access token", t);
        throw new ApsSystemException("Error while update access token", t);
    } finally {
        closeDaoResources(null, stat, conn);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 58 with ApsSystemException

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

the class OAuth2TokenDAO method deleteExpiredToken.

@Override
public void deleteExpiredToken() throws ApsSystemException {
    Connection conn = null;
    PreparedStatement stat = null;
    try {
        conn = this.getConnection();
        conn.setAutoCommit(false);
        stat = conn.prepareStatement(DELETE_EXPIRED_TOKENS);
        stat.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
        stat.executeUpdate();
        conn.commit();
    } catch (SQLException t) {
        this.executeRollback(conn);
        logger.error(ERROR_REMOVE_ACCESS_TOKEN, t);
        throw new ApsSystemException(ERROR_REMOVE_ACCESS_TOKEN, t);
    } finally {
        closeDaoResources(null, stat, conn);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 59 with ApsSystemException

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

the class OAuthConsumerDAO method deleteConsumer.

public void deleteConsumer(String clientId) {
    Connection conn = null;
    PreparedStatement stat = null;
    try {
        conn = this.getConnection();
        conn.setAutoCommit(false);
        this.delete(clientId, DELETE_CONSUMER_TOKENS, conn);
        this.delete(clientId, DELETE_CONSUMER, conn);
        conn.commit();
    } catch (SQLException | ApsSystemException t) {
        this.executeRollback(conn);
        _logger.error("Error while deleting consumer '{}' and its tokens", clientId, t);
        throw new RuntimeException("Error while deleting a consumer and its tokens", t);
    } finally {
        closeDaoResources(null, stat, conn);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 60 with ApsSystemException

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

the class PageService method movePage.

@Override
public PageDto movePage(String pageCode, PagePositionRequest pageRequest) {
    IPage parent = this.getPageManager().getDraftPage(pageRequest.getParentCode()), page = this.getPageManager().getDraftPage(pageCode);
    boolean moved = true;
    int iterations = Math.abs(page.getPosition() - pageRequest.getPosition());
    boolean moveUp = page.getPosition() > pageRequest.getPosition();
    try {
        if (page.getParentCode().equals(parent.getCode())) {
            while (iterations-- > 0 && (moved = this.getPageManager().movePage(pageCode, moveUp))) ;
        } else {
            moved = this.getPageManager().movePage(page, parent);
        }
        page = this.getPageManager().getDraftPage(pageCode);
    } catch (ApsSystemException e) {
        logger.error("Error moving page {}", pageCode, e);
        throw new RestServerError("error in moving page", e);
    }
    return this.getDtoBuilder().convert(page);
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) RestServerError(org.entando.entando.aps.system.exception.RestServerError) 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