use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.
the class TransMeta method getMinimum.
/**
* Gets the minimum point on the canvas of a transformation.
*
* @return Minimum coordinate of a step in the transformation
*/
public Point getMinimum() {
int minx = Integer.MAX_VALUE, miny = Integer.MAX_VALUE;
for (int i = 0; i < nrSteps(); i++) {
StepMeta stepMeta = getStep(i);
Point loc = stepMeta.getLocation();
if (loc.x < minx) {
minx = loc.x;
}
if (loc.y < miny) {
miny = loc.y;
}
}
for (int i = 0; i < nrNotes(); i++) {
NotePadMeta notePadMeta = getNote(i);
Point loc = notePadMeta.getLocation();
if (loc.x < minx) {
minx = loc.x;
}
if (loc.y < miny) {
miny = loc.y;
}
}
if (minx > BORDER_INDENT && minx != Integer.MAX_VALUE) {
minx -= BORDER_INDENT;
} else {
minx = 0;
}
if (miny > BORDER_INDENT && miny != Integer.MAX_VALUE) {
miny -= BORDER_INDENT;
} else {
miny = 0;
}
return new Point(minx, miny);
}
use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryNotePadDelegate method loadNotePadMeta.
public NotePadMeta loadNotePadMeta(ObjectId id_note) throws KettleException {
NotePadMeta note = new NotePadMeta();
try {
note.setObjectId(id_note);
RowMetaAndData r = getNote(id_note);
if (r != null) {
note.setNote(r.getString("VALUE_STR", ""));
int x = (int) r.getInteger("GUI_LOCATION_X", 0L);
int y = (int) r.getInteger("GUI_LOCATION_Y", 0L);
note.setLocation(new Point(x, y));
note.setWidth((int) r.getInteger("GUI_LOCATION_WIDTH", 0L));
note.setHeight((int) r.getInteger("GUI_LOCATION_HEIGHT", 0L));
note.setSelected(false);
// Font
note.setFontName(r.getString("FONT_NAME", null));
note.setFontSize((int) r.getInteger("FONT_SIZE", -1));
note.setFontBold(r.getBoolean("FONT_BOLD", false));
note.setFontItalic(r.getBoolean("FONT_ITALIC", false));
// Font color
note.setFontColorRed((int) r.getInteger("FONT_COLOR_RED", NotePadMeta.COLOR_RGB_BLACK_BLUE));
note.setFontColorGreen((int) r.getInteger("FONT_COLOR_GREEN", NotePadMeta.COLOR_RGB_BLACK_GREEN));
note.setFontColorBlue((int) r.getInteger("FONT_COLOR_BLUE", NotePadMeta.COLOR_RGB_BLACK_BLUE));
// Background color
note.setBackGroundColorRed((int) r.getInteger("FONT_BACK_GROUND_COLOR_RED", NotePadMeta.COLOR_RGB_DEFAULT_BG_RED));
note.setBackGroundColorGreen((int) r.getInteger("FONT_BACK_GROUND_COLOR_GREEN", NotePadMeta.COLOR_RGB_DEFAULT_BG_GREEN));
note.setBackGroundColorBlue((int) r.getInteger("FONT_BACK_GROUND_COLOR_BLUE", NotePadMeta.COLOR_RGB_DEFAULT_BG_BLUE));
// Border color
note.setBorderColorRed((int) r.getInteger("FONT_BORDER_COLOR_RED", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_RED));
note.setBorderColorGreen((int) r.getInteger("FONT_BORDER_COLOR_GREEN", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_GREEN));
note.setBorderColorBlue((int) r.getInteger("FONT_BORDER_COLOR_BLUE", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_BLUE));
note.setDrawShadow(r.getBoolean("DRAW_SHADOW", true));
// Done!
return note;
} else {
note.setObjectId(null);
throw new KettleException("I couldn't find Notepad with id_note=" + id_note + " in the repository.");
}
} catch (KettleDatabaseException dbe) {
note.setObjectId(null);
throw new KettleException("Unable to load Notepad from repository (id_note=" + id_note + ")", dbe);
}
}
use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryTransDelegate method saveTransformation.
/**
* Saves the transformation to a repository.
*
* @param transMeta
* the transformation metadata to store
* @param monitor
* the way we report progress to the user, can be null if no UI is present
* @param overwrite
* Overwrite existing object(s)?
* @throws KettleException
* if an error occurs.
*/
public void saveTransformation(TransMeta transMeta, String versionComment, ProgressMonitorListener monitor, boolean overwriteAssociated) throws KettleException {
try {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.LockingRepository"));
}
repository.insertLogEntry("save transformation '" + transMeta.getName() + "'");
// Clear attribute id cache
// force repository lookup.
repository.connectionDelegate.clearNextIDCounters();
// Do we have a valid directory?
if (transMeta.getRepositoryDirectory().getObjectId() == null) {
throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Exception.PlsSelectAValidDirectoryBeforeSavingTheTransformation"));
}
int nrWorks = 2 + transMeta.nrDatabases() + transMeta.nrNotes() + transMeta.nrSteps() + transMeta.nrTransHops();
if (monitor != null) {
monitor.beginTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SavingTransformationTask.Title") + transMeta.getPathAndName(), nrWorks);
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingOfTransformationStarted"));
}
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException();
}
//
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.HandlingOldVersionTransformationTask.Title"));
// transMeta.setObjectId(getTransformationID(transMeta.getName(),
// transMeta.getRepositoryDirectory().getObjectId()));
}
// If no valid id is available in the database, assign one...
if (transMeta.getObjectId() == null) {
transMeta.setObjectId(repository.connectionDelegate.getNextTransformationID());
} else {
// of the database for this id_transformation, before we put it back in...
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.DeletingOldVersionTransformationTask.Title"));
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.DeletingOldVersionTransformation"));
}
repository.deleteTransformation(transMeta.getObjectId());
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.OldVersionOfTransformationRemoved"));
}
}
if (monitor != null) {
monitor.worked(1);
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingNotes"));
}
for (int i = 0; i < transMeta.nrNotes(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SavingNoteTask.Title") +
// (i + 1) + "/" + transMeta.nrNotes());
NotePadMeta ni = transMeta.getNote(i);
repository.saveNotePadMeta(ni, transMeta.getObjectId());
if (ni.getObjectId() != null) {
repository.insertTransNote(transMeta.getObjectId(), ni.getObjectId());
}
if (monitor != null) {
monitor.worked(1);
}
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingDatabaseConnections"));
}
for (int i = 0; i < transMeta.nrDatabases(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG,
// "TransMeta.Monitor.SavingDatabaseTask.Title") + (i + 1) + "/" + transMeta.nrDatabases());
DatabaseMeta databaseMeta = transMeta.getDatabase(i);
// repository)
if (overwriteAssociated || databaseMeta.hasChanged() || databaseMeta.getObjectId() == null) {
repository.save(databaseMeta, versionComment, monitor, overwriteAssociated);
}
if (monitor != null) {
monitor.worked(1);
}
}
// It is possible that we received another step through a plugin.
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.CheckingStepTypes"));
}
repository.updateStepTypes();
repository.updateDatabaseTypes();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingSteps"));
}
for (int i = 0; i < transMeta.nrSteps(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SavingStepTask.Title") +
// (i + 1) + "/" + transMeta.nrSteps());
StepMeta stepMeta = transMeta.getStep(i);
repository.stepDelegate.saveStepMeta(stepMeta, transMeta.getObjectId());
if (monitor != null) {
monitor.worked(1);
}
}
repository.connectionDelegate.closeStepAttributeInsertPreparedStatement();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingHops"));
}
for (int i = 0; i < transMeta.nrTransHops(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SavingHopTask.Title") +
// (i + 1) + "/" + transMeta.nrTransHops());
TransHopMeta hi = transMeta.getTransHop(i);
saveTransHopMeta(hi, transMeta.getObjectId());
if (monitor != null) {
monitor.worked(1);
}
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.FinishingTask.Title"));
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingTransformationInfo"));
}
// save the top level information for the transformation
insertTransformation(transMeta);
saveTransParameters(transMeta);
repository.connectionDelegate.closeTransAttributeInsertPreparedStatement();
//
for (int i = 0; i < transMeta.getPartitionSchemas().size(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
PartitionSchema partitionSchema = transMeta.getPartitionSchemas().get(i);
// See if this transformation really is a consumer of this object
// It might be simply loaded as a shared object from the repository
//
boolean isUsedByTransformation = transMeta.isUsingPartitionSchema(partitionSchema);
repository.save(partitionSchema, versionComment, null, transMeta.getObjectId(), isUsedByTransformation, overwriteAssociated);
}
//
for (int i = 0; i < transMeta.getSlaveServers().size(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
SlaveServer slaveServer = transMeta.getSlaveServers().get(i);
boolean isUsedByTransformation = transMeta.isUsingSlaveServer(slaveServer);
repository.save(slaveServer, versionComment, null, transMeta.getObjectId(), isUsedByTransformation, overwriteAssociated);
}
// Save the clustering schemas
for (int i = 0; i < transMeta.getClusterSchemas().size(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
ClusterSchema clusterSchema = transMeta.getClusterSchemas().get(i);
boolean isUsedByTransformation = transMeta.isUsingClusterSchema(clusterSchema);
repository.save(clusterSchema, versionComment, null, transMeta.getObjectId(), isUsedByTransformation, overwriteAssociated);
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingDependencies"));
}
for (int i = 0; i < transMeta.nrDependencies(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
TransDependency td = transMeta.getDependency(i);
saveTransDependency(td, transMeta.getObjectId());
}
saveTransAttributesMap(transMeta.getObjectId(), transMeta.getAttributesMap());
// Save the step error handling information as well!
for (int i = 0; i < transMeta.nrSteps(); i++) {
StepMeta stepMeta = transMeta.getStep(i);
StepErrorMeta stepErrorMeta = stepMeta.getStepErrorMeta();
if (stepErrorMeta != null) {
repository.stepDelegate.saveStepErrorMeta(stepErrorMeta, transMeta.getObjectId(), stepMeta.getObjectId());
}
}
repository.connectionDelegate.closeStepAttributeInsertPreparedStatement();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingFinished"));
}
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.UnlockingRepository"));
}
repository.unlockRepository();
// Perform a commit!
repository.commit();
transMeta.clearChanged();
if (monitor != null) {
monitor.worked(1);
}
if (monitor != null) {
monitor.done();
}
} catch (KettleDatabaseException dbe) {
// Oops, roll back!
repository.rollback();
log.logError(BaseMessages.getString(PKG, "TransMeta.Log.ErrorSavingTransformationToRepository") + Const.CR + dbe.getMessage());
throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Log.ErrorSavingTransformationToRepository"), dbe);
}
}
use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryJobDelegate method loadJobMeta.
/**
* Load a job in a directory
*
* @param log
* the logging channel
* @param rep
* The Repository
* @param jobname
* The name of the job
* @param repdir
* The directory in which the job resides.
* @throws KettleException
*/
public JobMeta loadJobMeta(String jobname, RepositoryDirectoryInterface repdir, ProgressMonitorListener monitor) throws KettleException {
JobMeta jobMeta = new JobMeta();
synchronized (repository) {
try {
// Clear everything...
jobMeta.clear();
jobMeta.setRepositoryDirectory(repdir);
// Get the transformation id
jobMeta.setObjectId(getJobID(jobname, repdir.getObjectId()));
// If no valid id is available in the database, then give error...
if (jobMeta.getObjectId() != null) {
// Load the notes...
ObjectId[] noteids = repository.getJobNoteIDs(jobMeta.getObjectId());
ObjectId[] jecids = repository.getJobEntryCopyIDs(jobMeta.getObjectId());
ObjectId[] hopid = repository.getJobHopIDs(jobMeta.getObjectId());
int nrWork = 2 + noteids.length + jecids.length + hopid.length;
if (monitor != null) {
monitor.beginTask(BaseMessages.getString(PKG, "JobMeta.Monitor.LoadingJob") + repdir + Const.FILE_SEPARATOR + jobname, nrWork);
}
//
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.ReadingJobInformation"));
}
RowMetaAndData jobRow = getJob(jobMeta.getObjectId());
jobMeta.setName(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_NAME, null));
jobMeta.setDescription(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_DESCRIPTION, null));
jobMeta.setExtendedDescription(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_EXTENDED_DESCRIPTION, null));
jobMeta.setJobversion(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_JOB_VERSION, null));
jobMeta.setJobstatus(Const.toInt(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_JOB_STATUS, null), -1));
jobMeta.setCreatedUser(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_CREATED_USER, null));
jobMeta.setCreatedDate(jobRow.getDate(KettleDatabaseRepository.FIELD_JOB_CREATED_DATE, new Date()));
jobMeta.setModifiedUser(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_MODIFIED_USER, null));
jobMeta.setModifiedDate(jobRow.getDate(KettleDatabaseRepository.FIELD_JOB_MODIFIED_DATE, new Date()));
long id_logdb = jobRow.getInteger(KettleDatabaseRepository.FIELD_JOB_ID_DATABASE_LOG, 0);
if (id_logdb > 0) {
// Get the logconnection
//
DatabaseMeta logDb = repository.loadDatabaseMeta(new LongObjectId(id_logdb), null);
jobMeta.getJobLogTable().setConnectionName(logDb.getName());
// jobMeta.getJobLogTable().getDatabaseMeta().shareVariablesWith(jobMeta);
}
jobMeta.getJobLogTable().setTableName(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_TABLE_NAME_LOG, null));
jobMeta.getJobLogTable().setBatchIdUsed(jobRow.getBoolean(KettleDatabaseRepository.FIELD_JOB_USE_BATCH_ID, false));
jobMeta.getJobLogTable().setLogFieldUsed(jobRow.getBoolean(KettleDatabaseRepository.FIELD_JOB_USE_LOGFIELD, false));
jobMeta.getJobLogTable().setLogSizeLimit(getJobAttributeString(jobMeta.getObjectId(), 0, KettleDatabaseRepository.JOB_ATTRIBUTE_LOG_SIZE_LIMIT));
jobMeta.setBatchIdPassed(jobRow.getBoolean(KettleDatabaseRepository.FIELD_JOB_PASS_BATCH_ID, false));
// Load all the log tables for the job...
//
RepositoryAttributeInterface attributeInterface = new KettleDatabaseRepositoryJobAttribute(repository.connectionDelegate, jobMeta.getObjectId());
for (LogTableInterface logTable : jobMeta.getLogTables()) {
logTable.loadFromRepository(attributeInterface);
}
if (monitor != null) {
monitor.worked(1);
}
//
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.ReadingAvailableDatabasesFromRepository"));
}
// Read objects from the shared XML file & the repository
try {
jobMeta.setSharedObjectsFile(jobRow.getString(KettleDatabaseRepository.FIELD_JOB_SHARED_FILE, null));
jobMeta.setSharedObjects(repository != null ? repository.readJobMetaSharedObjects(jobMeta) : jobMeta.readSharedObjects());
} catch (Exception e) {
log.logError(BaseMessages.getString(PKG, "JobMeta.ErrorReadingSharedObjects.Message", e.toString()));
//
log.logError(Const.getStackTracker(e));
}
if (monitor != null) {
monitor.worked(1);
}
if (log.isDetailed()) {
log.logDetailed("Loading " + noteids.length + " notes");
}
for (int i = 0; i < noteids.length; i++) {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.ReadingNoteNr") + (i + 1) + "/" + noteids.length);
}
NotePadMeta ni = repository.notePadDelegate.loadNotePadMeta(noteids[i]);
if (jobMeta.indexOfNote(ni) < 0) {
jobMeta.addNote(ni);
}
if (monitor != null) {
monitor.worked(1);
}
}
// Load the group attributes map
//
jobMeta.setAttributesMap(loadJobAttributesMap(jobMeta.getObjectId()));
// Load the job entries...
//
// Keep a unique list of job entries to facilitate in the loading.
//
List<JobEntryInterface> jobentries = new ArrayList<JobEntryInterface>();
if (log.isDetailed()) {
log.logDetailed("Loading " + jecids.length + " job entries");
}
for (int i = 0; i < jecids.length; i++) {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.ReadingJobEntryNr") + (i + 1) + "/" + (jecids.length));
}
JobEntryCopy jec = repository.jobEntryDelegate.loadJobEntryCopy(jobMeta.getObjectId(), jecids[i], jobentries, jobMeta.getDatabases(), jobMeta.getSlaveServers(), jobname);
if (jec.isMissing()) {
jobMeta.addMissingEntry((MissingEntry) jec.getEntry());
}
// Also set the copy number...
// We count the number of job entry copies that use the job
// entry
//
int copyNr = 0;
for (JobEntryCopy copy : jobMeta.getJobCopies()) {
if (jec.getEntry() == copy.getEntry()) {
copyNr++;
}
}
jec.setNr(copyNr);
int idx = jobMeta.indexOfJobEntry(jec);
if (idx < 0) {
if (jec.getName() != null && jec.getName().length() > 0) {
jobMeta.addJobEntry(jec);
}
} else {
// replace it!
jobMeta.setJobEntry(idx, jec);
}
if (monitor != null) {
monitor.worked(1);
}
}
// Load the hops...
if (log.isDetailed()) {
log.logDetailed("Loading " + hopid.length + " job hops");
}
for (int i = 0; i < hopid.length; i++) {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.ReadingJobHopNr") + (i + 1) + "/" + (jecids.length));
}
JobHopMeta hi = loadJobHopMeta(hopid[i], jobMeta.getJobCopies());
jobMeta.getJobhops().add(hi);
if (monitor != null) {
monitor.worked(1);
}
}
loadRepParameters(jobMeta);
// Finally, clear the changed flags...
jobMeta.clearChanged();
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.FinishedLoadOfJob"));
}
if (monitor != null) {
monitor.done();
}
// close prepared statements, minimize locking etc.
//
repository.connectionDelegate.closeAttributeLookupPreparedStatements();
return jobMeta;
} else {
throw new KettleException(BaseMessages.getString(PKG, "JobMeta.Exception.CanNotFindJob") + jobname);
}
} catch (KettleException dbe) {
throw new KettleException(BaseMessages.getString(PKG, "JobMeta.Exception.AnErrorOccuredReadingJob", jobname), dbe);
} finally {
jobMeta.initializeVariablesFrom(jobMeta.getParentVariableSpace());
jobMeta.setInternalKettleVariables();
}
}
}
use of org.pentaho.di.core.NotePadMeta in project pentaho-kettle by pentaho.
the class AbstractMeta method raiseNote.
/**
* Raises a note to the "top" of the list by removing the note at the specified index and re-inserting it at the end.
* Also marks that the notes have changed.
*
* @param p the index into the notes list.
*/
public void raiseNote(int p) {
// if valid index and not last index
if ((p >= 0) && (p < notes.size() - 1)) {
NotePadMeta note = notes.remove(p);
notes.add(note);
changedNotes = true;
}
}
Aggregations