Search in sources :

Example 11 with ObjectRevision

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

the class JobMetaTest method testEquals_sameNameSameDirDiffRev.

@Test
public void testEquals_sameNameSameDirDiffRev() {
    ObjectRevision otherRevision = mock(ObjectRevision.class);
    when(otherRevision.getName()).thenReturn("otherRevision");
    assertFalse(testEquals(JOB_META_NAME, directoryJob, otherRevision, null));
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) Test(org.junit.Test)

Example 12 with ObjectRevision

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

the class AbstractMetaTest method testGetObjectNameCopyRevision.

@Test
public void testGetObjectNameCopyRevision() throws Exception {
    assertNull(meta.getObjectName());
    meta.setName("x");
    assertEquals("x", meta.getObjectName());
    assertNull(meta.getObjectCopy());
    assertNull(meta.getObjectRevision());
    ObjectRevision rev = mock(ObjectRevision.class);
    meta.setObjectRevision(rev);
    assertEquals(rev, meta.getObjectRevision());
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) Test(org.junit.Test)

Example 13 with ObjectRevision

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

the class PurRepositoryIT method testExport.

@Test
public void testExport() throws Exception {
    // $NON-NLS-1$
    final String exportFileName = new File("test.export").getAbsolutePath();
    RepositoryDirectoryInterface rootDir = initRepo();
    String uniqueTransName = EXP_TRANS_NAME.concat(EXP_DBMETA_NAME);
    TransMeta transMeta = createTransMeta(EXP_DBMETA_NAME);
    // Create a database association
    DatabaseMeta dbMeta = createDatabaseMeta(EXP_DBMETA_NAME);
    repository.save(dbMeta, VERSION_COMMENT_V1, null);
    TableInputMeta tableInputMeta = new TableInputMeta();
    tableInputMeta.setDatabaseMeta(dbMeta);
    transMeta.addStep(new StepMeta(EXP_TRANS_STEP_1_NAME, tableInputMeta));
    RepositoryDirectoryInterface transDir = rootDir.findDirectory(DIR_TRANSFORMATIONS);
    repository.save(transMeta, VERSION_COMMENT_V1, null);
    // So this transformation is cleaned up afterward
    deleteStack.push(transMeta);
    assertNotNull(transMeta.getObjectId());
    ObjectRevision version = transMeta.getObjectRevision();
    assertNotNull(version);
    assertTrue(hasVersionWithComment(transMeta, VERSION_COMMENT_V1));
    assertTrue(repository.exists(uniqueTransName, transDir, RepositoryObjectType.TRANSFORMATION));
    JobMeta jobMeta = createJobMeta(EXP_JOB_NAME);
    RepositoryDirectoryInterface jobsDir = rootDir.findDirectory(DIR_JOBS);
    repository.save(jobMeta, VERSION_COMMENT_V1, null);
    deleteStack.push(jobMeta);
    assertNotNull(jobMeta.getObjectId());
    version = jobMeta.getObjectRevision();
    assertNotNull(version);
    assertTrue(hasVersionWithComment(jobMeta, VERSION_COMMENT_V1));
    assertTrue(repository.exists(EXP_JOB_NAME, jobsDir, RepositoryObjectType.JOB));
    LogListener errorLogListener = new LogListener(LogLevel.ERROR);
    KettleLogStore.getAppender().addLoggingEventListener(errorLogListener);
    try {
        // $NON-NLS-1$
        repository.getExporter().exportAllObjects(new MockProgressMonitorListener(), exportFileName, null, "all");
        FileObject exportFile = KettleVFS.getFileObject(exportFileName);
        assertFalse("file left open", exportFile.getContent().isOpen());
        assertNotNull(exportFile);
        MockRepositoryExportParser parser = new MockRepositoryExportParser();
        SAXParserFactory.newInstance().newSAXParser().parse(KettleVFS.getInputStream(exportFile), parser);
        if (parser.getFatalError() != null) {
            throw parser.getFatalError();
        }
        // $NON-NLS-1$
        assertNotNull("No nodes found in export", parser.getNodeNames());
        // $NON-NLS-1$
        assertTrue("No nodes found in export", !parser.getNodeNames().isEmpty());
        // $NON-NLS-1$
        assertEquals("Incorrect number of nodes", 5, parser.getNodeNames().size());
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals("Incorrect number of transformations", 1, parser.getNodesWithName("transformation").size());
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals("Incorrect number of jobs", 1, parser.getNodesWithName("job").size());
        assertTrue("log error", errorLogListener.getEvents().isEmpty());
    } finally {
        KettleVFS.getFileObject(exportFileName).delete();
        KettleLogStore.getAppender().removeLoggingEventListener(errorLogListener);
    }
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) Matchers.anyString(org.mockito.Matchers.anyString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 14 with ObjectRevision

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

the class UIEETransformationTest method testRevisions.

@Test
public void testRevisions() throws Exception {
    final String revisionName = "revisionName";
    final String commitMessage = "commitMessage";
    ObjectRevision mockObjectRevision = mock(ObjectRevision.class);
    when(mockObjectRevision.getName()).thenReturn(revisionName);
    List<ObjectRevision> mockRevisions = Arrays.asList(new ObjectRevision[] { mockObjectRevision });
    when(mockRevisionService.getRevisions(any(ObjectId.class))).thenReturn(mockRevisions);
    uiTransformation.refreshRevisions();
    verify(mockRevisionService, times(1)).getRevisions(mockObjectId);
    UIRepositoryObjectRevisions revisions = uiTransformation.getRevisions();
    assertEquals(1, revisions.size());
    assertEquals("revisionName", revisions.get(0).getName());
    verify(mockRevisionService, times(1)).getRevisions(mockObjectId);
    uiTransformation.restoreRevision(revisions.get(0), commitMessage);
    verify(mockRevisionService).restoreTransformation(mockObjectId, revisionName, commitMessage);
    verify(mockParent, times(1)).fireCollectionChanged();
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) ObjectId(org.pentaho.di.repository.ObjectId) Test(org.junit.Test)

Example 15 with ObjectRevision

use of org.pentaho.di.repository.ObjectRevision 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

ObjectRevision (org.pentaho.di.repository.ObjectRevision)15 Test (org.junit.Test)6 KettleException (org.pentaho.di.core.exception.KettleException)4 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)4 StringObjectId (org.pentaho.di.repository.StringObjectId)3 ArrayList (java.util.ArrayList)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)2 JobMeta (org.pentaho.di.job.JobMeta)2 ObjectId (org.pentaho.di.repository.ObjectId)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2 TransMeta (org.pentaho.di.trans.TransMeta)2 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)2 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)2 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)2 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)2 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)2 File (java.io.File)1