Search in sources :

Example 1 with PurObjectRevision

use of org.pentaho.di.repository.pur.PurObjectRevision in project pentaho-kettle by pentaho.

the class RevisionResourceTest method testDoGetVersions.

/**
 * @throws Exception
 */
@org.junit.Test
public void testDoGetVersions() throws Exception {
    Response response = revisionResource.doGetVersions(MOCK_FILE_PATH);
    Object entity = response.getEntity();
    // Yeah this gets weird: List, wrapped in a Response, wrapped in GenericEnttiy
    List<PurObjectRevision> revisionList = (List<PurObjectRevision>) ((GenericEntity) entity).getEntity();
    Assert.assertTrue(revisionList.size() == 1);
    Assert.assertTrue(revisionList.get(0).getLogin().equals(MOCK_VERSION_AUTHOR_1));
}
Also used : Response(javax.ws.rs.core.Response) PurObjectRevision(org.pentaho.di.repository.pur.PurObjectRevision) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with PurObjectRevision

use of org.pentaho.di.repository.pur.PurObjectRevision in project pentaho-kettle by pentaho.

the class RevisionResource method doGetVersions.

/**
 * Retrieves the version history of a selected repository file
 *
 * <p>
 * <b>Example Request:</b><br>
 * GET /pur-repository-plugin/api/revision/path:to:file/revisions
 * </p>
 *
 * @param pathId
 *          (colon separated path for the repository file)
 *
 *          <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @return file revisions objects <code> purObjectRevisions </code>
 *
 *         <pre function="syntax.xml">
 * &lt;purObjectRevisions&gt;
 * &lt;revision&gt;
 * &lt;versionId&gt;1.0&lt;/versionId&gt;
 * &lt;creationDate&gt;2014-07-22T14:42:46.029-04:00&lt;/creationDate&gt;
 * &lt;login&gt;admin&lt;/login&gt;
 * &lt;comment&gt;JMeter test&lt;/comment&gt;
 * &lt;/revision&gt;
 * &lt;/purObjectRevisions&gt;
 * </pre>
 */
@GET
@Path("{pathId : .+}/revisions")
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully returns list of revisions"), @ResponseCode(code = 500, condition = "Something failed when attempting to retrieve revisions"), @ResponseCode(code = 404, condition = "Invalid path") })
@Produces({ APPLICATION_XML, APPLICATION_JSON })
public Response doGetVersions(@PathParam("pathId") String pathId) {
    Serializable fileId = null;
    List<ObjectRevision> originalRevisions = null;
    RepositoryFile repositoryFile = repository.getFile(FileUtils.idToPath(pathId));
    if (repositoryFile != null) {
        fileId = repositoryFile.getId();
    }
    if (fileId != null) {
        try {
            originalRevisions = revisionService.getRevisions(new StringObjectId(fileId.toString()));
        } catch (KettleException e) {
            return Response.serverError().build();
        }
        List<PurObjectRevision> revisions = new ArrayList();
        for (ObjectRevision revision : originalRevisions) {
            revisions.add((PurObjectRevision) revision);
        }
        GenericEntity<List<PurObjectRevision>> genericRevisionsEntity = new GenericEntity<List<PurObjectRevision>>(revisions) {
        };
        return Response.ok(genericRevisionsEntity).build();
    } else {
        return Response.serverError().build();
    }
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) PurObjectRevision(org.pentaho.di.repository.pur.PurObjectRevision) KettleException(org.pentaho.di.core.exception.KettleException) Serializable(java.io.Serializable) GenericEntity(javax.ws.rs.core.GenericEntity) PurObjectRevision(org.pentaho.di.repository.pur.PurObjectRevision) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ArrayList(java.util.ArrayList) List(java.util.List) StringObjectId(org.pentaho.di.repository.StringObjectId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 PurObjectRevision (org.pentaho.di.repository.pur.PurObjectRevision)2 Serializable (java.io.Serializable)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 GenericEntity (javax.ws.rs.core.GenericEntity)1 Response (javax.ws.rs.core.Response)1 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)1 KettleException (org.pentaho.di.core.exception.KettleException)1 ObjectRevision (org.pentaho.di.repository.ObjectRevision)1 StringObjectId (org.pentaho.di.repository.StringObjectId)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1