Skip to content

Commit

Permalink
[PDI-13028] - Extract messages into message bundle. Added default bun…
Browse files Browse the repository at this point in the history
…dle.
  • Loading branch information
YuryBY committed Sep 23, 2015
1 parent 6d35886 commit 193f76b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
Expand Up @@ -32,6 +32,7 @@
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.core.vfs.KettleVFS;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.imp.ImportRules;
import org.pentaho.di.imp.rule.ImportValidationFeedback;
import org.pentaho.di.job.JobMeta;
Expand All @@ -50,6 +51,9 @@
public class PurRepositoryExporter implements IRepositoryExporter, java.io.Serializable {

private static final long serialVersionUID = -8972308694755905930L; /* EESOURCE: UPDATE SERIALVERUID */

private static Class<?> PKG = PurRepositoryExporter.class;

/**
* Amount of repository files and content to load from the repository at once.
*/
Expand Down Expand Up @@ -116,7 +120,8 @@ public synchronized void exportAllObjects(ProgressMonitorListener monitor, Strin
monitor.worked(1);
}
} catch (IOException e) {
System.out.println("Couldn't create file [" + xmlFilename + "]"); //$NON-NLS-1$ //$NON-NLS-2$
log.logError( BaseMessages.getString( PKG, "PurRepositoryExporter.ERROR_CREATE_FILE", xmlFilename ),
e ); //$NON-NLS-1$
} finally {
try {
if (writer != null) {
Expand All @@ -126,7 +131,8 @@ public synchronized void exportAllObjects(ProgressMonitorListener monitor, Strin
os.close();
}
} catch (Exception e) {
System.out.println("Exception closing XML file writer to [" + xmlFilename + "]"); //$NON-NLS-1$ //$NON-NLS-2$
log.logError( BaseMessages.getString( PKG, "PurRepositoryExporter.ERROR_CLOSE_FILE", xmlFilename ),
e ); //$NON-NLS-1$
}
}

Expand Down Expand Up @@ -154,9 +160,12 @@ private void initBatchSize() {
}
if (err) {
batchSize = DEFAULT_BATCH_SIZE;
log.logError("Invalid {0} [{1}]. Reverting to [{2}].", REPOSITORY_BATCH_SIZE_PROPERTY, batchProp, batchSize); //$NON-NLS-1$
log.logError( BaseMessages
.getString( PKG, "PurRepositoryExporter.ERROR_INVALID_BATCH_SIZE", REPOSITORY_BATCH_SIZE_PROPERTY, batchProp,
batchSize ), err ); //$NON-NLS-1$
}
log.logDetailed("Using batch size of {0}", batchSize); //$NON-NLS-1$
log.logDetailed(
BaseMessages.getString( PKG, "PurRepositoryExporter.DETAILED_USED_BATCH_SIZE", batchSize ) ); //$NON-NLS-1$
}

/**
Expand Down Expand Up @@ -219,32 +228,28 @@ public void export( ProgressMonitorListener monitor, List<RepositoryFile> files,
}
} catch ( Exception ex ) {
//if exception while writing one item is occurred logging it and continue looping
String message =
"An error occured while saving transformation [" + trans.getName() + "] from [" + file.getPath()
+ "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
log.logError( message, ex );
log.logError( BaseMessages
.getString( PKG, "PurRepositoryExporter.ERROR_SAVE_TRANSFORMATION", trans.getName(), file.getPath() ),
ex ); //$NON-NLS-1$
}
}
}
}

private boolean toExport( AbstractMeta meta ) {
boolean shouldImport = true;
boolean shouldExport = true;
List<ImportValidationFeedback> feedback = importRules.verifyRules( meta );
List<ImportValidationFeedback> errors = ImportValidationFeedback.getErrors( feedback );
if ( !errors.isEmpty() ) {
shouldImport = false;
StringBuilder message =
new StringBuilder( "Imported intity " + meta.getName() + " is not satisfied to import rule(s)" );
message.append( Const.CR );
shouldExport = false;
log.logError(
BaseMessages.getString( PKG, "PurRepositoryExporter.ERROR_EXPORT_ITEM", meta.getName() ) ); //$NON-NLS-1$
for ( ImportValidationFeedback error : errors ) {
message.append( " - " );
message.append( error.toString() );
message.append( Const.CR );
log.logError( BaseMessages
.getString( PKG, "PurRepositoryExporter.ERROR_EXPORT_ITEM_RULE", error.toString() ) ); //$NON-NLS-1$
}
log.logError( message.toString() );
}
return shouldImport;
return shouldExport;
}

private class JobBatchExporter implements RepositoryFileBatchExporter {
Expand All @@ -271,10 +276,9 @@ public void export( ProgressMonitorListener monitor, List<RepositoryFile> files,
}
} catch ( Exception ex ) {
//if exception while writing one item is occurred logging it and continue looping
String message =
"An error occured while saving job [" + meta.getName() + "] from [" + file.getPath()
+ "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
log.logError( message, ex );
log.logError(
BaseMessages.getString( PKG, "PurRepositoryExporter.ERROR_SAVE_JOB", meta.getName(), file.getPath() ),
ex ); //$NON-NLS-1$
}
}
}
Expand Down Expand Up @@ -311,23 +315,23 @@ private void export(final ProgressMonitorListener monitor, final RepositoryFileT
files.add(repObj.getFile());
}
if (!files.isEmpty()) {
log.logBasic(
"Exporting {0} {1} from directory [{2}]", files.size(), exporter.getFriendlyTypeName(), root.getFile().getPath()); //$NON-NLS-1$
log.logBasic( BaseMessages
.getString( PKG, "PurRepositoryExporter.BASIC_EXPORT_FROM", files.size(), exporter.getFriendlyTypeName(),
root.getFile().getPath() ) ); //$NON-NLS-1$
// Only fetch batchSize transformations at a time
for (int i = 0; (monitor == null || !monitor.isCanceled()) && i < files.size(); i += batchSize) {
int start = i;
int end = Math.min(i + batchSize, files.size());
List<RepositoryFile> group = files.subList(start, end);
if (monitor != null) {
monitor
.subTask("Loading " + group.size() + " " + exporter.getFriendlyTypeName() + " from " + root.getFile().getPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if ( monitor != null ) {
monitor.subTask( "Loading " + group.size() + " " + exporter.getFriendlyTypeName() + " from " + root.getFile().getPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
try {
exporter.export(monitor, group, writer);
} catch (KettleException ex) {
// TODO i18n
log.logError(
"Error exporting " + exporter.getFriendlyTypeName() + " from directory [" + root.getFile().getPath() + "]", ex); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} catch ( KettleException ex ) {
log.logError( BaseMessages
.getString( PKG, "PurRepositoryExporter.ERROR_EXPORT", exporter.getFriendlyTypeName(),
root.getFile().getPath() ), ex ); //$NON-NLS-1$
}
}
}
Expand Down
Expand Up @@ -15,8 +15,7 @@ UserRoleDelegate.ERROR_0014_INSUFFICIENT_PRIVILEGES=User does not have necessary
UserRoleDelegate.ERROR_0015_USER_NAME_ALREADY_EXISTS=Someone already has that user name. Please try another.
UserRoleDelegate.ERROR_0016_ROLE_NAME_ALREADY_EXISTS=That role is already in use. Please try another.
UserRoleListDelegate.ERROR_0001_UNABLE_TO_INITIALIZE_USER_ROLE_LIST_WEBSVC=Unable to initialize User Role list webservice
#
AbsSecurityProvider.ERROR_0001_UNABLE_TO_INITIALIZE_AUTH_POLICY_WEBSVC=Unable to initialize AuthorizationPolicyWebservice
#AbsSecurityProvider.ERROR_0001_UNABLE_TO_INITIALIZE_AUTH_POLICY_WEBSVC=Unable to initialize AuthorizationPolicyWebservice
AbsSecurityProvider.ERROR_0002_UNABLE_TO_ACCESS_IS_ALLOWED=Unable to access getAllowedActions method on AuthorizationPolicyService {0}
AbsSecurityProvider.ERROR_0003_UNABLE_TO_ACCESS_GET_ALLOWED_ACTIONS=Unable to access getAllowedActions method on AuthorizationPolicyService
#
Expand Down Expand Up @@ -81,3 +80,16 @@ PurRepositoryImporter.WhichFile.Log=Importing objects from file "{0}"
PurRepositoryImporter.LookupRepoRefsError.Log=Could not lookup repository references for "{0}"
PurRepositoryImporter.FileNotFound.Message=The file to import, {0}, was not found.
PurRepositoryImporter.ParseError.Message=There was an error parsing the file {0}.

PurRepositoryExporter.ERROR_CREATE_FILE=Couldn't create file [ "{0}" ].
PurRepositoryExporter.ERROR_CLOSE_FILE=Exception closing XML file writer to [ "{0}" ].
PurRepositoryExporter.ERROR_INVALID_BATCH_SIZE=Invalid {0} [{1}]. Reverting to [{2}].
PurRepositoryExporter.ERROR_SAVE_TRANSFORMATION=An error occured while saving transformation ["{0}"] from ["{1}"].
PurRepositoryExporter.ERROR_SAVE_JOB=An error occured while saving job ["{0}"] from ["{1}"].
PurRepositoryExporter.ERROR_EXPORT=Error exporting "{0}" from directory ["{1}"].
PurRepositoryExporter.ERROR_EXPORT_ITEM=Exported entity "{0}" is not satisfied following rule(s):
PurRepositoryExporter.ERROR_EXPORT_ITEM_RULE= - "{0}" ;

PurRepositoryExporter.DETAILED_USED_BATCH_SIZE=Using batch size of "{0}".

PurRepositoryExporter.BASIC_EXPORT_FROM=Exporting "{0}" "{1}" from directory ["{2}"].

0 comments on commit 193f76b

Please sign in to comment.