Search in sources :

Example 1 with IRepositoryVersionManager

use of org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager in project pentaho-platform by pentaho.

the class DefaultRepositoryVersioningManagerTest method testPartialTrue.

/*
   * Test a file set to versioningEnable=True, versionCommentsEnabled=false with various combinations
   * of the master switch.
   */
@Test
public void testPartialTrue() {
    IRepositoryVersionManager repositoryVersionManager = defaultRepositoryVersionManagerFullTrue;
    assertTrue(repositoryVersionManager.isVersioningEnabled(PART_VERSIONING_PATH));
    assertFalse(repositoryVersionManager.isVersionCommentEnabled(PART_VERSIONING_PATH));
    repositoryVersionManager = defaultRepositoryVersionManagerPartialTrue;
    assertTrue(repositoryVersionManager.isVersioningEnabled(PART_VERSIONING_PATH));
    assertFalse(repositoryVersionManager.isVersionCommentEnabled(PART_VERSIONING_PATH));
    repositoryVersionManager = defaultRepositoryVersionManagerFalse;
    assertFalse(repositoryVersionManager.isVersioningEnabled(PART_VERSIONING_PATH));
    assertFalse(repositoryVersionManager.isVersionCommentEnabled(PART_VERSIONING_PATH));
}
Also used : IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) Test(org.junit.Test)

Example 2 with IRepositoryVersionManager

use of org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager in project pentaho-platform by pentaho.

the class FileResource method doVersioningConfiguration.

/**
 * This method is used to determine whether versioning should be active for the given path
 *
 * <p><b>Example Request:</b><br />
 *    GET pentaho/api/repo/files/:jmeter-test:test_file_1.ktr/versioningConfiguration
 *  </pre>
 * </p>
 *
 * @param pathId Colon separated path for the repository file.
 *
 * @return The Versioning Configuration applicable to the path submitted
 *
 * <p><b>Example Response:</b></p>
 *  <pre function="syntax.xml">
 * &lt;fileVersioningConfiguration&gt;
 *   &lt;versionCommentEnabled&gt;true&lt;/versionCommentEnabled&gt;
 *   &lt;versioningEnabled&gt;true&lt;/versioningEnabled&gt;
 * &lt;/fileVersioningConfiguration&gt;
 *  </pre>
 */
@GET
@Path("{pathId : .+}/versioningConfiguration")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully returns the versioning configuration") })
public FileVersioningConfiguration doVersioningConfiguration(@PathParam("pathId") String pathId) {
    IRepositoryVersionManager repositoryVersionManager = PentahoSystem.get(IRepositoryVersionManager.class);
    String path = FileUtils.idToPath(pathId);
    return new FileVersioningConfiguration(repositoryVersionManager.isVersioningEnabled(path), repositoryVersionManager.isVersionCommentEnabled(path));
}
Also used : FileVersioningConfiguration(org.pentaho.platform.repository2.unified.webservices.FileVersioningConfiguration) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes)

Example 3 with IRepositoryVersionManager

use of org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager in project pentaho-platform by pentaho.

the class RepositoryFileAdapter method toFileDto.

public static RepositoryFileDto toFileDto(final RepositoryFile v, Set<String> memberSet, boolean exclude, boolean includeAcls) {
    if (v == null) {
        return null;
    }
    RepositoryFileDto f = new RepositoryFileDto();
    // no longer exists, so it returns null
    try {
        if (include("name", memberSet, exclude)) {
            f.name = v.getName();
        }
        if (include("path", memberSet, exclude)) {
            f.path = v.getPath();
        }
        if (include("hidden", memberSet, exclude)) {
            f.hidden = v.isHidden();
        }
        if (include("aclNode", memberSet, exclude)) {
            f.aclNode = v.isAclNode();
        }
        if (include("createDate", memberSet, exclude)) {
            f.createdDate = v.getCreatedDate();
        }
        if (include("creatorId", memberSet, exclude)) {
            f.creatorId = v.getCreatorId();
        }
        if (include("fileSize", memberSet, exclude)) {
            f.fileSize = v.getFileSize();
        }
        if (include("description", memberSet, exclude)) {
            f.description = v.getDescription();
        }
        if (include("folder", memberSet, exclude)) {
            f.folder = v.isFolder();
        }
        // it must be present or the tree rest service call will error
        if (v.getId() != null) {
            f.id = v.getId().toString();
        }
        if (include("lastModifiedDate", memberSet, exclude)) {
            f.lastModifiedDate = v.getLastModifiedDate();
        }
        if (include("locale", memberSet, exclude)) {
            f.locale = v.getLocale();
        }
        if (include("originalParentFolderPath", memberSet, exclude)) {
            f.originalParentFolderPath = v.getOriginalParentFolderPath();
        }
        if (include("deletedDate", memberSet, exclude)) {
            f.deletedDate = v.getDeletedDate();
        }
        if (include("lockDate", memberSet, exclude)) {
            f.lockDate = v.getLockDate();
        }
        if (include("locked", memberSet, exclude)) {
            f.locked = v.isLocked();
        }
        if (include("lockMessage", memberSet, exclude)) {
            f.lockMessage = v.getLockMessage();
        }
        if (include("lockOwner", memberSet, exclude)) {
            f.lockOwner = v.getLockOwner();
        }
        if (include("title", memberSet, exclude)) {
            f.title = v.getTitle();
        }
        if (include("versioned", memberSet, exclude)) {
            f.versioned = v.isVersioned();
        }
        if (include("versionId", memberSet, exclude)) {
            if (v.getVersionId() != null) {
                f.versionId = v.getVersionId().toString();
            }
        }
    } catch (NullPointerException e) {
        getLogger().warn("NullPointerException while reading file attributes, returning null. Probable cause: File does not" + "exist anymore: ");
        return null;
    }
    if (includeAcls) {
        if (v.getId() != null) {
            try {
                f.repositoryFileAclDto = getRepoWs().getAcl(v.getId().toString());
                if (f.repositoryFileAclDto.isEntriesInheriting()) {
                    List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAces(v.getId().toString());
                    f.repositoryFileAclDto.setAces(aces, f.repositoryFileAclDto.isEntriesInheriting());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (include("owner", memberSet, exclude)) {
            Serializable id = v.getId();
            if (id != null) {
                RepositoryFileAclDto acl = getRepoWs().getAcl("" + id);
                if (acl != null) {
                    f.owner = acl.getOwner();
                }
            }
        }
    }
    if (include("locales", memberSet, exclude)) {
        if (v.getLocalePropertiesMap() != null) {
            f.localePropertiesMapEntries = new ArrayList<LocaleMapDto>();
            for (Map.Entry<String, Properties> entry : v.getLocalePropertiesMap().entrySet()) {
                LocaleMapDto localeMapDto = new LocaleMapDto();
                List<StringKeyStringValueDto> valuesDto = new ArrayList<StringKeyStringValueDto>();
                Properties properties = entry.getValue();
                if (properties != null) {
                    for (String propertyName : properties.stringPropertyNames()) {
                        valuesDto.add(new StringKeyStringValueDto(propertyName, properties.getProperty(propertyName)));
                    }
                }
                localeMapDto.setLocale(entry.getKey());
                localeMapDto.setProperties(valuesDto);
                f.localePropertiesMapEntries.add(localeMapDto);
            }
        }
    }
    IRepositoryVersionManager repositoryVersionManager;
    try {
        repositoryVersionManager = JcrRepositoryFileUtils.getRepositoryVersionManager();
        // Not found, must be in Spoon
        if (repositoryVersionManager == null) {
            return f;
        }
    } catch (NoClassDefFoundError ex) {
        // support tree and child calls.
        return f;
    }
    if (include("versioningEnabled", memberSet, exclude)) {
        f.setVersioningEnabled(repositoryVersionManager.isVersioningEnabled(v.getPath()));
    }
    if (include("versionCommentEnabled", memberSet, exclude)) {
        f.setVersionCommentEnabled(repositoryVersionManager.isVersionCommentEnabled(v.getPath()));
    }
    return f;
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Properties(java.util.Properties) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) Map(java.util.Map)

Example 4 with IRepositoryVersionManager

use of org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryAuthorizationIT method setup.

@Before
public void setup() {
    IRepositoryVersionManager mockRepositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(mockRepositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    when(mockRepositoryVersionManager.isVersionCommentEnabled(anyString())).thenReturn(false);
    JcrRepositoryFileUtils.setRepositoryVersionManager(mockRepositoryVersionManager);
}
Also used : IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) Before(org.junit.Before)

Example 5 with IRepositoryVersionManager

use of org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager in project pentaho-platform by pentaho.

the class JcrRepositoryFileDaoIT method beforeTest.

@Before
public void beforeTest() {
    IRepositoryVersionManager mockRepositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(mockRepositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    when(mockRepositoryVersionManager.isVersionCommentEnabled(anyString())).thenReturn(false);
    JcrRepositoryFileUtils.setRepositoryVersionManager(mockRepositoryVersionManager);
}
Also used : IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) Before(org.junit.Before)

Aggregations

IRepositoryVersionManager (org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager)15 Before (org.junit.Before)7 Test (org.junit.Test)4 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 Map (java.util.Map)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 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1