Search in sources :

Example 1 with ResourceRecordVO

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO in project entando-core by entando.

the class ResourceManager method loadResource.

/**
 * Restituisce la risorsa con l'id specificato.
 * @param id L'identificativo della risorsa da caricare.
 * @return La risorsa cercata. null se non vi è nessuna risorsa con l'identificativo immesso.
 * @throws ApsSystemException in caso di errore.
 */
@Override
public ResourceInterface loadResource(String id) throws ApsSystemException {
    ResourceInterface resource = null;
    try {
        ResourceRecordVO resourceVo = this.getResourceDAO().loadResourceVo(id);
        if (null != resourceVo) {
            resource = this.createResource(resourceVo);
            resource.setMasterFileName(resourceVo.getMasterFileName());
        }
    } catch (Throwable t) {
        logger.error("Error loading resource : id {}", id, t);
        throw new ApsSystemException("Error loading resource : id " + id, t);
    }
    return resource;
}
Also used : ResourceRecordVO(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 2 with ResourceRecordVO

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO in project entando-core by entando.

the class TestResourceDAO method testAddDeleteResource.

public void testAddDeleteResource() throws Throwable {
    DataSource dataSource = (DataSource) this.getApplicationContext().getBean("portDataSource");
    MockResourcesDAO mockResourcesDao = new MockResourcesDAO();
    mockResourcesDao.setDataSource(dataSource);
    ResourceInterface resource = new ImageResource();
    resource.setId("temp");
    resource.setDescr("temp");
    resource.setMainGroup(Group.FREE_GROUP_NAME);
    resource.setType("Image");
    resource.setFolder("/temp");
    // resource.setBaseURL("temp");
    ResourceRecordVO resourceRecordVO = null;
    try {
        mockResourcesDao.deleteResource("temp");
    } catch (Throwable t) {
        throw t;
    }
    _resourceDao.addResource(resource);
    resourceRecordVO = _resourceDao.loadResourceVo(resource.getId());
    assertEquals(resourceRecordVO.getDescr().equals("temp"), true);
    _resourceDao.deleteResource(resource.getId());
    resourceRecordVO = _resourceDao.loadResourceVo(resource.getId());
    assertNull(resourceRecordVO);
}
Also used : ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) ResourceRecordVO(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) MockResourcesDAO(com.agiletec.aps.services.mock.MockResourcesDAO) DataSource(javax.sql.DataSource)

Example 3 with ResourceRecordVO

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO in project entando-core by entando.

the class ResourceDAO method loadResourceVo.

/**
 * Carica un record di risorse in funzione dell'id Risorsa. Questo record è
 * necessario per l'estrazione della risorse in oggetto tipo
 * AbstractResource da parte del ResourceManager.
 *
 * @param id L'identificativo della risorsa.
 * @return Il record della risorsa.
 */
@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'jacms_resource_'.concat(#id)", condition = "null != #id")
public ResourceRecordVO loadResourceVo(String id) {
    Connection conn = null;
    ResourceRecordVO resourceVo = null;
    PreparedStatement stat = null;
    ResultSet res = null;
    try {
        conn = this.getConnection();
        stat = conn.prepareStatement(LOAD_RESOURCE_VO);
        stat.setString(1, id);
        res = stat.executeQuery();
        if (res.next()) {
            resourceVo = new ResourceRecordVO();
            resourceVo.setId(id);
            resourceVo.setResourceType(res.getString(1));
            resourceVo.setDescr(res.getString(2));
            resourceVo.setMainGroup(res.getString(3));
            resourceVo.setXml(res.getString(4));
            resourceVo.setMasterFileName(res.getString(5));
            resourceVo.setCreationDate(res.getDate(6));
            resourceVo.setLastModified(res.getDate(7));
        }
    } catch (Throwable t) {
        _logger.error("Errore loading resource {}", id, t);
        throw new RuntimeException("Errore loading resource" + id, t);
    } finally {
        closeDaoResources(res, stat, conn);
    }
    return resourceVo;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ResourceRecordVO(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO) PreparedStatement(java.sql.PreparedStatement) CachePut(org.springframework.cache.annotation.CachePut)

Aggregations

ResourceRecordVO (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO)3 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)2 MockResourcesDAO (com.agiletec.aps.services.mock.MockResourcesDAO)1 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 ImageResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 DataSource (javax.sql.DataSource)1 CachePut (org.springframework.cache.annotation.CachePut)1