Search in sources :

Example 1 with IPathConversionHelper

use of org.pentaho.platform.repository2.unified.jcr.IPathConversionHelper in project pentaho-platform by pentaho.

the class JcrRepositoryFileUtils method nodeToFileOld.

public static RepositoryFile nodeToFileOld(final Session session, final PentahoJcrConstants pentahoJcrConstants, final IPathConversionHelper pathConversionHelper, final ILockHelper lockHelper, final Node node, final boolean loadMaps, IPentahoLocale pentahoLocale) throws RepositoryException {
    if (session.getRootNode().isSame(node)) {
        return getRootFolder(session);
    }
    Serializable id = null;
    String name = null;
    String path = null;
    long fileSize = 0;
    Date created = null;
    String creatorId = null;
    Boolean hidden = RepositoryFile.HIDDEN_BY_DEFAULT;
    Boolean schedulable = RepositoryFile.SCHEDULABLE_BY_DEFAULT;
    Date lastModified = null;
    boolean folder = false;
    boolean versioned = false;
    Serializable versionId = null;
    boolean locked = false;
    String lockOwner = null;
    Date lockDate = null;
    String lockMessage = null;
    String title = null;
    String description = null;
    Boolean aclNode = false;
    Map<String, Properties> localePropertiesMap = null;
    id = getNodeId(session, pentahoJcrConstants, node);
    if (logger.isDebugEnabled()) {
        // $NON-NLS-1$
        logger.debug(String.format("reading file with id '%s' and path '%s'", id, node.getPath()));
    }
    path = pathConversionHelper.absToRel((getAbsolutePath(session, pentahoJcrConstants, node)));
    // if the rel path is / then name the folder empty string instead of its true name (this hides the tenant name)
    // $NON-NLS-1$
    name = RepositoryFile.SEPARATOR.equals(path) ? "" : getNodeName(session, pentahoJcrConstants, node);
    if (isPentahoFolder(pentahoJcrConstants, node)) {
        folder = true;
    }
    // jcr:created nodes have OnParentVersion values of INITIALIZE
    if (node.hasProperty(pentahoJcrConstants.getJCR_CREATED())) {
        Calendar tmpCal = node.getProperty(pentahoJcrConstants.getJCR_CREATED()).getDate();
        if (tmpCal != null) {
            created = tmpCal.getTime();
        }
    }
    // Expensive
    Map<String, Serializable> metadata = getFileMetadata(session, id);
    if (metadata != null) {
        creatorId = (String) metadata.get(PentahoJcrConstants.PHO_CONTENTCREATOR);
        Serializable schedulableValue = metadata.get(RepositoryFile.SCHEDULABLE_KEY);
        if (schedulableValue instanceof String) {
            schedulable = BooleanUtils.toBoolean((String) schedulableValue);
        }
    }
    if (node.hasProperty(pentahoJcrConstants.getPHO_HIDDEN())) {
        hidden = node.getProperty(pentahoJcrConstants.getPHO_HIDDEN()).getBoolean();
    }
    if (node.hasProperty(pentahoJcrConstants.getPHO_FILESIZE())) {
        fileSize = node.getProperty(pentahoJcrConstants.getPHO_FILESIZE()).getLong();
    }
    if (node.hasProperty(pentahoJcrConstants.getPHO_ACLNODE())) {
        aclNode = node.getProperty(pentahoJcrConstants.getPHO_ACLNODE()).getBoolean();
    }
    if (isPentahoFile(pentahoJcrConstants, node)) {
        // pho:lastModified nodes have OnParentVersion values of IGNORE; i.e. they don't exist in frozen nodes
        if (!node.isNodeType(pentahoJcrConstants.getNT_FROZENNODE())) {
            Calendar tmpCal = node.getProperty(pentahoJcrConstants.getPHO_LASTMODIFIED()).getDate();
            if (tmpCal != null) {
                lastModified = tmpCal.getTime();
            }
        }
    }
    // Get default locale if null
    if (pentahoLocale == null) {
        Locale currentLocale = LocaleHelper.getLocale();
        if (currentLocale != null) {
            pentahoLocale = new PentahoLocale(currentLocale);
        } else {
            pentahoLocale = new PentahoLocale();
        }
    }
    // Not needed for content generators and the like
    if (isPentahoHierarchyNode(session, pentahoJcrConstants, node)) {
        if (node.hasNode(pentahoJcrConstants.getPHO_LOCALES())) {
            // Expensive
            localePropertiesMap = getLocalePropertiesMap(session, pentahoJcrConstants, node.getNode(pentahoJcrConstants.getPHO_LOCALES()));
            // [BISERVER-8337] localize title and description
            LocalePropertyResolver lpr = new LocalePropertyResolver(name);
            LocalizationUtil localizationUtil = new LocalizationUtil(localePropertiesMap, pentahoLocale.getLocale());
            title = localizationUtil.resolveLocalizedString(lpr.resolveDefaultTitleKey(), null);
            if (org.apache.commons.lang.StringUtils.isBlank(title)) {
                title = localizationUtil.resolveLocalizedString(lpr.resolveTitleKey(), null);
                if (org.apache.commons.lang.StringUtils.isBlank(title)) {
                    title = localizationUtil.resolveLocalizedString(lpr.resolveNameKey(), title);
                }
            }
            description = localizationUtil.resolveLocalizedString(lpr.resolveDefaultDescriptionKey(), null);
            if (org.apache.commons.lang.StringUtils.isBlank(description)) {
                description = localizationUtil.resolveLocalizedString(lpr.resolveDescriptionKey(), description);
            }
        }
        // found
        if (title == null && node.hasNode(pentahoJcrConstants.getPHO_TITLE())) {
            title = getLocalizedString(session, pentahoJcrConstants, node.getNode(pentahoJcrConstants.getPHO_TITLE()), pentahoLocale);
        }
        if (description == null && node.hasNode(pentahoJcrConstants.getPHO_DESCRIPTION())) {
            description = getLocalizedString(session, pentahoJcrConstants, node.getNode(pentahoJcrConstants.getPHO_DESCRIPTION()), pentahoLocale);
        }
    }
    if (!loadMaps) {
        // remove reference, allow garbage collection
        localePropertiesMap = null;
    }
    versioned = isVersioned(session, pentahoJcrConstants, node);
    if (versioned) {
        versionId = getVersionId(session, pentahoJcrConstants, node);
    }
    locked = isLocked(pentahoJcrConstants, node);
    if (locked) {
        Lock lock = session.getWorkspace().getLockManager().getLock(node.getPath());
        lockOwner = lockHelper.getLockOwner(session, pentahoJcrConstants, lock);
        lockDate = lockHelper.getLockDate(session, pentahoJcrConstants, lock);
        lockMessage = lockHelper.getLockMessage(session, pentahoJcrConstants, lock);
    }
    RepositoryFile file = new RepositoryFile.Builder(id, name).createdDate(created).creatorId(creatorId).lastModificationDate(lastModified).folder(folder).versioned(versioned).path(path).versionId(versionId).fileSize(fileSize).locked(locked).lockDate(lockDate).hidden(hidden).schedulable(schedulable).lockMessage(lockMessage).lockOwner(lockOwner).title(title).description(description).locale(pentahoLocale.toString()).localePropertiesMap(localePropertiesMap).aclNode(aclNode).build();
    return file;
}
Also used : Locale(java.util.Locale) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) Serializable(java.io.Serializable) Calendar(java.util.Calendar) Properties(java.util.Properties) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) Date(java.util.Date) Lock(javax.jcr.lock.Lock) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean)

Example 2 with IPathConversionHelper

use of org.pentaho.platform.repository2.unified.jcr.IPathConversionHelper in project pentaho-platform by pentaho.

the class JcrRepositoryFileDaoTest method setUp.

@Before
public void setUp() throws RepositoryException {
    Node node = mock(Node.class);
    Node nodeParent = mock(Node.class);
    when(node.getIdentifier()).thenReturn("");
    when(nodeParent.getIdentifier()).thenReturn("");
    when(node.getParent()).thenReturn(nodeParent);
    when(node.isNodeType("null:pentahoFile")).thenReturn(true);
    when(node.isNodeType("null:pentahoVersionable")).thenReturn(true);
    VersionManagerImpl versionManager = mock(VersionManagerImpl.class);
    Workspace workspace = mock(Workspace.class);
    when(workspace.getVersionManager()).thenReturn(versionManager);
    Session session = mock(Session.class);
    when(session.getWorkspace()).thenReturn(workspace);
    when(session.getNodeByIdentifier(anyString())).thenReturn(node);
    when(session.getItem(anyString())).thenReturn(node);
    pentahoSession = mock(IPentahoSession.class);
    PentahoSessionHolder.setSession(pentahoSession);
    IRepositoryVersionManager repositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(repositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    PentahoSystem.registerObject(repositoryVersionManager);
    JcrTemplate jcrTemplate = new JcrTemplate() {

        @Override
        public Object execute(JcrCallback callback) throws DataAccessException {
            try {
                return callback.doInJcr(session);
            } catch (Exception e) {
                // wrapping exception to comply overriding rules
                throw new RuntimeException(e);
            }
        }
    };
    List<ITransformer<IRepositoryFileData>> transformerList = Collections.emptyList();
    IPathConversionHelper pathConversionHelper = new DefaultPathConversionHelper();
    IRepositoryFileAclDao aclDao = mock(IRepositoryFileAclDao.class);
    accessVoterManager = mock(IRepositoryAccessVoterManager.class);
    JcrRepositoryFileDao jcrDao = new JcrRepositoryFileDao(jcrTemplate, transformerList, null, null, pathConversionHelper, aclDao, null, accessVoterManager);
    dao = spy(jcrDao);
}
Also used : JcrTemplate(org.springframework.extensions.jcr.JcrTemplate) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(javax.jcr.Node) JcrCallback(org.springframework.extensions.jcr.JcrCallback) IRepositoryFileAclDao(org.pentaho.platform.repository2.unified.IRepositoryFileAclDao) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) DataAccessException(org.springframework.dao.DataAccessException) AccessDeniedException(javax.jcr.AccessDeniedException) RepositoryException(javax.jcr.RepositoryException) VersionManagerImpl(org.apache.jackrabbit.core.VersionManagerImpl) IRepositoryAccessVoterManager(org.pentaho.platform.api.repository2.unified.IRepositoryAccessVoterManager) Workspace(javax.jcr.Workspace) Session(javax.jcr.Session) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Before(org.junit.Before)

Example 3 with IPathConversionHelper

use of org.pentaho.platform.repository2.unified.jcr.IPathConversionHelper in project data-access by pentaho.

the class AgileMartDatasourceLifecycleManager method getInstance.

public static AgileMartDatasourceLifecycleManager getInstance() {
    if (instance == null) {
        TransactionTemplate txnTemplate = PentahoSystem.get(TransactionTemplate.class, "jcrTransactionTemplate", PentahoSessionHolder.getSession());
        JcrTemplate adminJcrTemplate = PentahoSystem.get(JcrTemplate.class, "adminJcrTemplate", PentahoSessionHolder.getSession());
        IPathConversionHelper pathConversionHelper = PentahoSystem.get(IPathConversionHelper.class, "pathConversionHelper", PentahoSessionHolder.getSession());
        IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, PentahoSessionHolder.getSession());
        IDatasourceMgmtService datasourceMgmtService = PentahoSystem.get(IDatasourceMgmtService.class, PentahoSessionHolder.getSession());
        instance = new AgileMartDatasourceLifecycleManager(txnTemplate, adminJcrTemplate, pathConversionHelper, datasourceMgmtService, resLoader);
    }
    return instance;
}
Also used : JcrTemplate(org.springframework.extensions.jcr.JcrTemplate) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) IPathConversionHelper(org.pentaho.platform.repository2.unified.jcr.IPathConversionHelper) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)

Aggregations

JcrTemplate (org.springframework.extensions.jcr.JcrTemplate)2 Serializable (java.io.Serializable)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Locale (java.util.Locale)1 Properties (java.util.Properties)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 Workspace (javax.jcr.Workspace)1 Lock (javax.jcr.lock.Lock)1 MutableBoolean (org.apache.commons.lang.mutable.MutableBoolean)1 VersionManagerImpl (org.apache.jackrabbit.core.VersionManagerImpl)1 Before (org.junit.Before)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)1 IPentahoLocale (org.pentaho.platform.api.locale.IPentahoLocale)1 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)1 IRepositoryAccessVoterManager (org.pentaho.platform.api.repository2.unified.IRepositoryAccessVoterManager)1