Skip to content

Commit

Permalink
Merge pull request pentaho#9754 from joana-fb/PDI-20262
Browse files Browse the repository at this point in the history
[PDI-20262] - Uploaded PDI Job/Transformation in PDI and save in Repository has file size of 0 on the Properties screen
  • Loading branch information
smmribeiro authored Dec 10, 2024
2 parents 22c884e + b4ec5fe commit d1c3eb3
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.core.util.Utils;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.core.xml.XMLInterface;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.imp.Import;
import org.pentaho.di.job.JobMeta;
Expand Down Expand Up @@ -101,6 +103,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -3465,18 +3468,21 @@ protected void saveTransOrJob( ISharedObjectsTransformer objectTransformer, Repo
renameKettleEntity( element, null, element.getName() );
}
} else {

int dataSize = calculateDataSize( element );

readWriteLock.writeLock().lock();
try {
file =
new RepositoryFile.Builder( checkAndSanitize( element.getName()
+ element.getRepositoryElementType().getExtension() ) ).versioned( true ).title(
RepositoryFile.DEFAULT_LOCALE, element.getName() ).createdDate(
versionDate != null ? versionDate.getTime() : new Date() ).description( RepositoryFile.DEFAULT_LOCALE,
Const.NVL( element.getDescription(), "" ) ).build();
Const.NVL( element.getDescription(), "" ) ).fileSize( dataSize ).build();

file =
pur.createFile( element.getRepositoryDirectory().getObjectId().getId(), file,
new NodeRepositoryFileData( objectTransformer.elementToDataNode( element ) ), versionComment );
new NodeRepositoryFileData( objectTransformer.elementToDataNode( element ), dataSize ), versionComment );
} catch ( SOAPFaultException e ) {
if ( e.getMessage().contains( UnifiedRepositoryCreateFileException.PREFIX ) ) {
throw new KettleException(
Expand All @@ -3502,6 +3508,16 @@ protected void saveTransOrJob( ISharedObjectsTransformer objectTransformer, Repo
}
}

private static int calculateDataSize( RepositoryElementInterface element ) throws KettleException {
if ( !( element instanceof XMLInterface ) ) {
return 0;
}

String xml = XMLHandler.getXMLHeader() + ( (XMLInterface) element ).getXML();
byte[] bytes = xml.getBytes( StandardCharsets.UTF_8 );
return bytes.length;
}

protected ObjectId renameKettleEntity( final RepositoryElementInterface transOrJob,
final RepositoryDirectoryInterface newDirectory, final String newName ) throws KettleException {
switch ( transOrJob.getRepositoryElementType() ) {
Expand Down

0 comments on commit d1c3eb3

Please sign in to comment.