Search in sources :

Example 31 with ApsSystemException

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

the class SearchEngineDAOFactory method getSearcher.

@Override
public ISearcherDAO getSearcher(String subDir) throws ApsSystemException {
    ISearcherDAO searcherDao = null;
    try {
        Class searcherClass = Class.forName(this.getSearcherClassName());
        searcherDao = (ISearcherDAO) searcherClass.newInstance();
        searcherDao.init(this.getDirectory(subDir));
    } catch (Throwable t) {
        _logger.error("Error creating new searcher", t);
        throw new ApsSystemException("Error creating new searcher", t);
    }
    return searcherDao;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 32 with ApsSystemException

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

the class SearchEngineDAOFactory method getIndexer.

@Override
public IIndexerDAO getIndexer(String subDir) throws ApsSystemException {
    IIndexerDAO indexerDao = null;
    try {
        Class indexerClass = Class.forName(this.getIndexerClassName());
        indexerDao = (IIndexerDAO) indexerClass.newInstance();
        indexerDao.setLangManager(this.getLangManager());
        indexerDao.init(this.getDirectory(subDir));
    } catch (Throwable t) {
        _logger.error("Error getting indexer", t);
        throw new ApsSystemException("Error creating new indexer", t);
    }
    return indexerDao;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 33 with ApsSystemException

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

the class SearchEngineDAOFactory method getDirectory.

private File getDirectory(String subDirectory) throws ApsSystemException {
    String dirName = this.getIndexDiskRootFolder();
    if (!dirName.endsWith("/")) {
        dirName += "/";
    }
    dirName += "cmscontents/" + subDirectory;
    _logger.debug("Index Directory: {}", dirName);
    File dir = new File(dirName);
    if (!dir.exists() || !dir.isDirectory()) {
        dir.mkdirs();
        _logger.debug("Index Directory created");
    }
    if (!dir.canRead() || !dir.canWrite()) {
        throw new ApsSystemException(dirName + " does not have r/w rights");
    }
    return dir;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) File(java.io.File)

Example 34 with ApsSystemException

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

the class AuthEndpointServlet method validateClient.

private boolean validateClient(final OAuthAuthzRequest oauthRequest, HttpServletRequest request, HttpServletResponse response) throws OAuthProblemException {
    final IOAuthConsumerManager consumerManager = (IOAuthConsumerManager) ApsWebApplicationUtils.getBean(SystemConstants.OAUTH_CONSUMER_MANAGER, request);
    final String clientId = oauthRequest.getClientId();
    try {
        final ConsumerRecordVO clientDetail = consumerManager.getConsumerRecord(clientId);
        if (clientDetail != null) {
            if (!clientDetail.getKey().equals(oauthRequest.getClientId())) {
                throw OAuthUtils.handleOAuthProblemException("Invalid clientId");
            } else if (clientDetail.getExpirationDate().getTime() < System.currentTimeMillis()) {
                throw OAuthUtils.handleOAuthProblemException("ClientId is expired");
            } else if (!clientDetail.getCallbackUrl().equals(oauthRequest.getRedirectURI())) {
                throw OAuthUtils.handleOAuthProblemException("Invalid redirectUri");
            }
            return true;
        }
    } catch (ApsSystemException e) {
        logger.error("ApsSystemException {}", e.getMessage());
        try {
            response.sendError(500);
        } catch (IOException e1) {
            logger.error("IOException {}", e1);
        }
        return false;
    }
    return false;
}
Also used : ConsumerRecordVO(org.entando.entando.aps.system.services.oauth2.model.ConsumerRecordVO) IOAuthConsumerManager(org.entando.entando.aps.system.services.oauth2.IOAuthConsumerManager) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IOException(java.io.IOException)

Example 35 with ApsSystemException

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

the class ApiEntityTypeInterface method addEntityType.

public StringApiResponse addEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        IEntityManager manager = this.getEntityManager();
        String typeCode = jaxbEntityType.getTypeCode();
        IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
        if (null != masterEntityType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' already exists");
        }
        if (typeCode == null || typeCode.length() != 3) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
        }
        Map<String, AttributeInterface> attributes = manager.getEntityAttributePrototypes();
        IApsEntity newEntityType = jaxbEntityType.buildEntityType(manager.getEntityClass(), attributes);
        this.checkNewEntityType(jaxbEntityType, newEntityType, response);
        ((IEntityTypesConfigurer) manager).addEntityPrototype(newEntityType);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error extracting entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "getEntityType");
        throw new ApsSystemException("Error extracting entity type", t);
    }
    return response;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

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