modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDetails.java
| 126 +++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
| 342 +++-------
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
| 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
| 11
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
| 69 ++
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
| 10
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
| 3
7 files changed, 348 insertions(+), 216 deletions(-)
New commits:
commit 4b12e68d2d7648ed08921f482bb02e3525a3cf81
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Aug 30 21:03:24 2011 -0400
[BZ 734194] Check that content is loaded in db on drift details view
The drift details view page displays links for viewing the current and
previous version of a file as well as a diff between those versions.
The initial implementation failed to take into account that the file
content referenced by the drift may not be in the database. The page
previously attempted to generate a diff report on load instead of on
demand. This of course resulted in an exception getting thrown.
With this commit, links for viewing file content and for viewing a diff
are shown when the file content is available. If the file content is not
available, a message is instead displayed that says the content is not
available.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDetails.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDetails.java
new file mode 100644
index 0000000..283f53f
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDetails.java
@@ -0,0 +1,126 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.domain.drift;
+
+import java.io.Serializable;
+
+/**
+ * Encapsulates information and details about drift that can be used in the UI. This
class
+ * the Drift object, the change set to which the drift belongs, and the change set in
which
+ * the file with drift was last referenced. This class also store statuses of the
current
+ * and previous versions of the file to indicate whether or not the content is in the
+ * database. Lastly, it has a flag to indicate whether or not the file is a binary file.
+ */
+public class DriftDetails implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private Drift drift;
+
+ private DriftChangeSet previousChangeSet;
+
+ private DriftFileStatus newFileStatus;
+
+ private DriftFileStatus oldFileStatus;
+
+ private boolean isBinary;
+
+ /** @return The drift object */
+ public Drift getDrift() {
+ return drift;
+ }
+
+ /** @param drift The Drift object to which the details belong */
+ public void setDrift(Drift drift) {
+ this.drift = drift;
+ }
+
+ /** @return The change set to which the drift is part of */
+ public DriftChangeSet getChangeSet() {
+ return drift.getChangeSet();
+ }
+
+ /**
+ * Returns the previous change set for which there was an occurrence of drift on the
+ * file referenced by the Drift object. This can be null if there was no previous
+ * drift.
+ *
+ * @return The previous change set for which there was drift on the file referenced
by
+ * the Drift object or null if there is not previous drift on the file.
+ */
+ public DriftChangeSet getPreviousChangeSet() {
+ return previousChangeSet;
+ }
+
+ /**
+ * @param changeSet The previous change set in which drift occurred on the file
+ * referenced by the Drift object.
+ */
+ public void setPreviousChangeSet(DriftChangeSet changeSet) {
+ previousChangeSet = changeSet;
+ }
+
+ /**
+ * @return The status of the file as reported in the current change set. Indicates
+ * whether or not the file has been loaded into the database. Can be null if the
type
+ * of drift is a {@link DriftCategory#FILE_REMOVED deletion}.
+ */
+ public DriftFileStatus getNewFileStatus() {
+ return newFileStatus;
+ }
+
+ /**
+ * @param status The status of the file reported in the change set.
+ */
+ public void setNewFileStatus(DriftFileStatus status) {
+ newFileStatus = status;
+ }
+
+ /**
+ * @return The status of the file as reported in the previous change set. Indicates
+ * whether or not the file has been loaded into the database. Can be null if the
type
+ * of drift is a {@link DriftCategory#FILE_ADDED addition}.
+ */
+ public DriftFileStatus getOldFileStatus() {
+ return oldFileStatus;
+ }
+
+ /**
+ * @param status The status of the file as reported in the last change set in which
the
+ * file was referenced.
+ */
+ public void setOldFileStatus(DriftFileStatus status) {
+ oldFileStatus = status;
+ }
+
+ /**
+ * @return true if the file is a binary file.
+ */
+ public boolean isBinaryFile() {
+ return isBinary;
+ }
+
+ /**
+ * @param binaryFile True if the file is a binary type, false otherwise.
+ */
+ public void setBinaryFile(boolean binaryFile) {
+ isBinary = binaryFile;
+ }
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
index 31c888d..1c0b54e 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
@@ -36,24 +36,20 @@ import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.layout.VLayout;
-import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
-import org.rhq.core.domain.criteria.GenericDriftCriteria;
import org.rhq.core.domain.drift.Drift;
-import org.rhq.core.domain.drift.DriftChangeSet;
+import org.rhq.core.domain.drift.DriftDetails;
+import org.rhq.core.domain.drift.DriftFileStatus;
import org.rhq.core.domain.drift.FileDiffReport;
-import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.PopupWindow;
import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.DriftGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
-import static org.rhq.core.domain.drift.DriftCategory.FILE_CHANGED;
+import static org.rhq.core.domain.drift.DriftFileStatus.LOADED;
import static
org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter.DATE_TIME_FORMAT_FULL;
/**
@@ -75,165 +71,30 @@ public class DriftDetailsView extends LocatableVLayout {
show(this.driftId);
}
- private void show(String driftId) {
+ private void show(final String driftId) {
final DriftGWTServiceAsync driftService = GWTServiceLookup.getDriftService();
-
- GenericDriftCriteria criteria = new GenericDriftCriteria();
- criteria.addFilterId(driftId);
- criteria.fetchChangeSet(true);
- driftService.findDriftsByCriteria(criteria,
- new AsyncCallback<PageList<? extends Drift>>() {
- @Override
- public void onSuccess(PageList<? extends Drift> result) {
- if (result.getTotalSize() != 1) {
- CoreGUI.getMessageCenter().notify(
- new Message("Got [" + result.getTotalSize()
- + "] results. Should have been 1. The details shown
here might not be correct.",
- Severity.Warning));
- }
- final Drift drift = result.get(0);
- if (drift.getCategory() == FILE_CHANGED) {
- GenericDriftChangeSetCriteria criteria = new
GenericDriftChangeSetCriteria();
-
criteria.addFilterResourceId(drift.getChangeSet().getResourceId());
-
criteria.addFilterDriftConfigurationId(drift.getChangeSet().getDriftConfigurationId());
-
criteria.addFilterVersion(Integer.toString(drift.getChangeSet().getVersion() - 1));
-
- driftService.findDriftChangeSetsByCriteria(criteria,
- new AsyncCallback<PageList<? extends
DriftChangeSet>>() {
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError("Failed to
load change set", caught);
- }
-
- @Override
- public void onSuccess(PageList<? extends
DriftChangeSet> changeSets) {
- show(drift, changeSets.get(0));
- }
- });
- } else {
- show(drift, null);
- }
- }
-
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_drift_failure_load(),
caught);
- }
- });
- }
-
- private void show(final Drift drift, final DriftChangeSet previousVersion) {
- for (Canvas child : getMembers()) {
- removeMember(child);
- child.destroy();
- }
-
- // the change set to which the drift belongs
-
- DynamicForm changeSetForm = new
LocatableDynamicForm(extendLocatorId("changeSetForm"));
- changeSetForm.setIsGroup(true);
- changeSetForm.setGroupTitle(MSG.view_drift_table_changeSet());
- changeSetForm.setWrapItemTitles(false);
-
- StaticTextItem changeSetId = new StaticTextItem("changeSetId",
MSG.common_title_id());
- changeSetId.setValue(drift.getChangeSet().getId());
- StaticTextItem changeSetCategory = new
StaticTextItem("changeSetCategory", MSG.common_title_category());
- changeSetCategory.setValue(drift.getChangeSet().getCategory().name());
- StaticTextItem changeSetVersion = new
StaticTextItem("changeSetVersion", MSG.common_title_version());
- changeSetVersion.setValue(drift.getChangeSet().getVersion());
- changeSetForm.setItems(changeSetId, changeSetCategory, changeSetVersion);
-
- addMember(changeSetForm);
-
- GWTServiceLookup.getDriftService().isBinaryFile(drift, new
AsyncCallback<Boolean>() {
+ driftService.getDriftDetails(driftId, new AsyncCallback<DriftDetails>() {
@Override
public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError("Failed to look up file
type", caught);
+ CoreGUI.getErrorHandler().handleError("Failed to load drift details
for drift id: " + driftId, caught);
}
@Override
- public void onSuccess(Boolean isBinary) {
- if (isBinary) {
- addMember(createDriftFormForBinaryFile(drift, previousVersion));
- } else {
- addMember(createDriftFormForTextFile(drift, previousVersion));
- }
+ public void onSuccess(final DriftDetails details) {
+ show(details);
}
});
- }
-
- private DynamicForm createDriftFormForBinaryFile(Drift drift, DriftChangeSet
previousVersion) {
- DynamicForm driftForm = new
LocatableDynamicForm(extendLocatorId("form"));
- driftForm.setIsGroup(true);
- driftForm.setGroupTitle(MSG.view_drift());
- driftForm.setWrapItemTitles(false);
- driftForm.setNumCols(4);
-
- SpacerItem spacer = new SpacerItem();
-
- StaticTextItem id = new StaticTextItem("id", MSG.common_title_id());
- id.setValue(drift.getId());
-
- StaticTextItem path = new StaticTextItem("path",
MSG.common_title_path());
- path.setValue(drift.getPath());
- StaticTextItem timestamp = new StaticTextItem("timestamp",
MSG.common_title_timestamp());
- timestamp.setValue(TimestampCellFormatter.format(drift.getCtime(),
DATE_TIME_FORMAT_FULL));
-
- StaticTextItem category = new StaticTextItem("category",
MSG.common_title_category());
-
- LinkedHashMap<String, String> catIconsMap = new LinkedHashMap<String,
String>(3);
- catIconsMap.put(DriftDataSource.CATEGORY_ICON_ADD,
DriftDataSource.CATEGORY_ICON_ADD);
- catIconsMap.put(DriftDataSource.CATEGORY_ICON_CHANGE,
DriftDataSource.CATEGORY_ICON_CHANGE);
- catIconsMap.put(DriftDataSource.CATEGORY_ICON_REMOVE,
DriftDataSource.CATEGORY_ICON_REMOVE);
- LinkedHashMap<String, String> catValueMap = new LinkedHashMap<String,
String>(3);
- catValueMap.put(DriftDataSource.CATEGORY_ICON_ADD,
MSG.view_drift_category_fileAdded());
- catValueMap.put(DriftDataSource.CATEGORY_ICON_CHANGE,
MSG.view_drift_category_fileChanged());
- catValueMap.put(DriftDataSource.CATEGORY_ICON_REMOVE,
MSG.view_drift_category_fileRemoved());
- category.setValueMap(catValueMap);
- category.setValueIcons(catIconsMap);
- category.setShowIcons(true);
-
- StaticTextItem oldFile = new StaticTextItem("oldFile",
MSG.view_drift_table_oldFile());
- FormItem oldFileLink = null;
-
- StaticTextItem newFile = new StaticTextItem("newFile",
MSG.view_drift_table_newFile());
- FormItem newFileLink = null;
+ }
- switch (drift.getCategory()) {
- case FILE_ADDED:
- category.setValue(DriftDataSource.CATEGORY_ICON_ADD);
- oldFile.setValue(MSG.common_label_none());
- oldFileLink = spacer;
- newFile.setValue(drift.getNewDriftFile().getHashId());
- newFileLink = spacer;
- break;
-
- case FILE_CHANGED:
- category.setValue(DriftDataSource.CATEGORY_ICON_CHANGE);
- oldFile.setValue(drift.getOldDriftFile().getHashId());
- oldFileLink = createViewFileLink(drift.getOldDriftFile().getHashId(),
drift.getPath(),
- previousVersion.getVersion());
- newFile.setValue(drift.getNewDriftFile().getHashId());
- newFileLink = spacer;
- break;
-
- case FILE_REMOVED:
- category.setValue(DriftDataSource.CATEGORY_ICON_REMOVE);
- oldFile.setValue(drift.getOldDriftFile().getHashId());
- oldFileLink = spacer;
- newFile.setValue(MSG.common_label_none());
- newFileLink = spacer;
- break;
+ private void show(DriftDetails driftDetails) {
+ for (Canvas child : getMembers()) {
+ removeMember(child);
+ child.destroy();
}
- driftForm.setItems(id, spacer, path, spacer, category, spacer, timestamp, spacer,
oldFile, oldFileLink,
- newFile, newFileLink);
-
- return driftForm;
- }
+ addMember(createChangeSetForm(driftDetails.getDrift()));
- private DynamicForm createDriftFormForTextFile(Drift drift, DriftChangeSet
previousVersion) {
DynamicForm driftForm = new
LocatableDynamicForm(extendLocatorId("form"));
driftForm.setIsGroup(true);
driftForm.setGroupTitle(MSG.view_drift());
@@ -243,13 +104,13 @@ public class DriftDetailsView extends LocatableVLayout {
SpacerItem spacer = new SpacerItem();
StaticTextItem id = new StaticTextItem("id", MSG.common_title_id());
- id.setValue(drift.getId());
+ id.setValue(driftDetails.getDrift().getId());
StaticTextItem path = new StaticTextItem("path",
MSG.common_title_path());
- path.setValue(drift.getPath());
+ path.setValue(driftDetails.getDrift().getPath());
StaticTextItem timestamp = new StaticTextItem("timestamp",
MSG.common_title_timestamp());
- timestamp.setValue(TimestampCellFormatter.format(drift.getCtime(),
DATE_TIME_FORMAT_FULL));
+
timestamp.setValue(TimestampCellFormatter.format(driftDetails.getDrift().getCtime(),
DATE_TIME_FORMAT_FULL));
StaticTextItem category = new StaticTextItem("category",
MSG.common_title_category());
@@ -271,55 +132,102 @@ public class DriftDetailsView extends LocatableVLayout {
StaticTextItem newFile = new StaticTextItem("newFile",
MSG.view_drift_table_newFile());
FormItem newFileLink = null;
- switch (drift.getCategory()) {
- case FILE_ADDED:
- category.setValue(DriftDataSource.CATEGORY_ICON_ADD);
- oldFile.setValue(MSG.common_label_none());
- oldFileLink = spacer;
- newFile.setValue(drift.getNewDriftFile().getHashId());
- newFileLink = createViewFileLink(drift.getNewDriftFile().getHashId(),
drift.getPath(),
- drift.getChangeSet().getVersion());
- break;
-
- case FILE_CHANGED:
- category.setValue(DriftDataSource.CATEGORY_ICON_CHANGE);
- oldFile.setValue(drift.getOldDriftFile().getHashId());
- oldFileLink = createViewFileLink(drift.getOldDriftFile().getHashId(),
drift.getPath(),
- previousVersion.getVersion());
- newFile.setValue(drift.getNewDriftFile().getHashId());
- newFileLink = createViewFileLink(drift.getNewDriftFile().getHashId(),
drift.getPath(),
- drift.getChangeSet().getVersion());
- break;
-
- case FILE_REMOVED:
- category.setValue(DriftDataSource.CATEGORY_ICON_REMOVE);
- oldFile.setValue(drift.getOldDriftFile().getHashId());
- oldFileLink = createViewFileLink(drift.getOldDriftFile().getHashId(),
drift.getPath(),
- drift.getChangeSet().getVersion());
- newFile.setValue(MSG.common_label_none());
- newFileLink = spacer;
- break;
+ if (driftDetails.isBinaryFile()) {
+ switch (driftDetails.getDrift().getCategory()) {
+ case FILE_ADDED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_ADD);
+ oldFile.setValue(MSG.common_label_none());
+ oldFileLink = spacer;
+
newFile.setValue(driftDetails.getDrift().getNewDriftFile().getHashId());
+ newFileLink = spacer;
+ break;
+ case FILE_CHANGED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_CHANGE);
+
oldFile.setValue(driftDetails.getDrift().getOldDriftFile().getHashId());
+ oldFileLink =
createViewFileLink(driftDetails.getDrift().getOldDriftFile().getHashId(),
+ driftDetails.getDrift().getPath(),
driftDetails.getPreviousChangeSet().getVersion());
+
newFile.setValue(driftDetails.getDrift().getNewDriftFile().getHashId());
+ newFileLink = spacer;
+ break;
+ case FILE_REMOVED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_REMOVE);
+
oldFile.setValue(driftDetails.getDrift().getOldDriftFile().getHashId());
+ oldFileLink = spacer;
+ newFile.setValue(MSG.common_label_none());
+ newFileLink = spacer;
+ break;
+ }
+ driftForm.setItems(id, spacer, path, spacer, category, spacer, timestamp,
spacer, oldFile, oldFileLink,
+ newFile, newFileLink);
+ } else {
+ FormItem viewDiffLink = spacer;
+ switch (driftDetails.getDrift().getCategory()) {
+ case FILE_ADDED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_ADD);
+ oldFile.setValue(MSG.common_label_none());
+ oldFileLink = spacer;
+
newFile.setValue(driftDetails.getDrift().getNewDriftFile().getHashId());
+ newFileLink =
createViewFileLink(driftDetails.getDrift().getNewDriftFile().getHashId(),
+ driftDetails.getDrift().getPath(),
driftDetails.getChangeSet().getVersion(),
+ driftDetails.getNewFileStatus());
+ break;
+ case FILE_CHANGED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_CHANGE);
+
oldFile.setValue(driftDetails.getDrift().getOldDriftFile().getHashId());
+ oldFileLink =
createViewFileLink(driftDetails.getDrift().getOldDriftFile().getHashId(),
+ driftDetails.getDrift().getPath(),
driftDetails.getPreviousChangeSet().getVersion(),
+ driftDetails.getOldFileStatus());
+
newFile.setValue(driftDetails.getDrift().getNewDriftFile().getHashId());
+ newFileLink =
createViewFileLink(driftDetails.getDrift().getNewDriftFile().getHashId(),
+ driftDetails.getDrift().getPath(),
driftDetails.getChangeSet().getVersion(),
+ driftDetails.getNewFileStatus());
+ if (driftDetails.getNewFileStatus() == LOADED &&
driftDetails.getOldFileStatus() == LOADED) {
+ viewDiffLink = createViewDiffLink(driftDetails.getDrift(),
+ driftDetails.getPreviousChangeSet().getVersion());
+ }
+ break;
+ case FILE_REMOVED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_REMOVE);
+
oldFile.setValue(driftDetails.getDrift().getOldDriftFile().getHashId());
+ oldFileLink =
createViewFileLink(driftDetails.getDrift().getOldDriftFile().getHashId(),
+ driftDetails.getDrift().getPath(),
driftDetails.getChangeSet().getVersion(),
+ driftDetails.getOldFileStatus());
+ newFile.setValue(MSG.common_label_none());
+ newFileLink = spacer;
+ break;
+ }
+ driftForm.setItems(id, spacer, path, spacer, category, spacer, timestamp,
spacer, oldFile, oldFileLink,
+ newFile, newFileLink, spacer, spacer, spacer, viewDiffLink);
}
+ addMember(driftForm);
+ }
- if (drift.getCategory() == FILE_CHANGED) {
- StaticTextItem numberOfChanges = new
StaticTextItem("numberOfChanges", "Number of Changes");
- numberOfChanges.setValue("Loading...");
+ private DynamicForm createChangeSetForm(Drift drift) {
+ DynamicForm changeSetForm = new
LocatableDynamicForm(extendLocatorId("changeSetForm"));
+ changeSetForm.setIsGroup(true);
+ changeSetForm.setGroupTitle(MSG.view_drift_table_changeSet());
+ changeSetForm.setWrapItemTitles(false);
- LinkItem viewDiffLink = new LinkItem("viewDiff");
- viewDiffLink.setLinkTitle("(view diff)");
- viewDiffLink.setShowTitle(false);
- viewDiffLink.setDisabled(true);
+ StaticTextItem changeSetId = new StaticTextItem("changeSetId",
MSG.common_title_id());
+ changeSetId.setValue(drift.getChangeSet().getId());
+ StaticTextItem changeSetCategory = new
StaticTextItem("changeSetCategory", MSG.common_title_category());
+ changeSetCategory.setValue(drift.getChangeSet().getCategory().name());
+ StaticTextItem changeSetVersion = new
StaticTextItem("changeSetVersion", MSG.common_title_version());
+ changeSetVersion.setValue(drift.getChangeSet().getVersion());
+ changeSetForm.setItems(changeSetId, changeSetCategory, changeSetVersion);
- driftForm.setItems(id, spacer, path, spacer, category, spacer, timestamp,
spacer, oldFile, oldFileLink,
- newFile, newFileLink, numberOfChanges, viewDiffLink);
+ return changeSetForm;
+ }
- generateDiff(drift, previousVersion.getVersion(), numberOfChanges,
viewDiffLink);
- } else {
- driftForm.setItems(id, spacer, path, spacer, category, spacer, timestamp,
spacer, oldFile, oldFileLink,
- newFile, newFileLink);
+ private FormItem createViewFileLink(String hash, String path, int version,
DriftFileStatus status) {
+ if (status == LOADED) {
+ return createViewFileLink(hash, path, version);
}
+ StaticTextItem item = new StaticTextItem(hash + "_fileLink");
+ item.setShowTitle(false);
+ item.setValue("(file not ready for viewing)");
- return driftForm;
+ return item;
}
private LinkItem createViewFileLink(final String hash, final String path, final int
version) {
@@ -333,7 +241,11 @@ public class DriftDetailsView extends LocatableVLayout {
GWTServiceLookup.getDriftService().getDriftFileBits(hash, new
AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError("Failed to load
file", caught);
+ try {
+ throw caught;
+ } catch (Throwable r) {
+ CoreGUI.getErrorHandler().handleError("Failed to load
file", r);
+ }
}
@Override
@@ -397,31 +309,32 @@ public class DriftDetailsView extends LocatableVLayout {
return window;
}
- private void generateDiff(final Drift drift, final int oldVersion, final
StaticTextItem changes,
- final LinkItem viewDiff) {
- GWTServiceLookup.getDriftService().generateUnifiedDiff(drift, new
AsyncCallback<FileDiffReport>() {
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError("Failed to load change
report", caught);
- }
+ private LinkItem createViewDiffLink(final Drift drift, final int oldVersion) {
+ LinkItem viewDiffLink = new LinkItem("viewDiff");
+ viewDiffLink.setLinkTitle("(view diff)");
+ viewDiffLink.setShowTitle(false);
+ viewDiffLink.addClickHandler(new ClickHandler() {
@Override
- public void onSuccess(final FileDiffReport diffReport) {
- changes.setValue(diffReport.getNumberOfChanges());
- viewDiff.setDisabled(false);
- viewDiff.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ GWTServiceLookup.getDriftService().generateUnifiedDiff(drift, new
AsyncCallback<FileDiffReport>() {
@Override
- public void onClick(ClickEvent clickEvent) {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("Failed to generate
diff", caught);
+ }
+
+ @Override
+ public void onSuccess(FileDiffReport diffReport) {
int newVersion = drift.getChangeSet().getVersion();
String diffContents = toHtml(diffReport.getDiff(), oldVersion,
newVersion);
-
- //LocatableWindow window =
createFileViewer(diffReport.getDiff());
- LocatableWindow window = createDiffViewer(diffContents,
drift.getPath(), oldVersion, newVersion);
+ LocatableWindow window = createDiffViewer(diffContents,
drift.getPath(), oldVersion,
+ newVersion);
window.show();
}
});
}
});
+ return viewDiffLink;
}
private String toHtml(List<String> deltas, int oldVersion, int newVersion) {
@@ -441,7 +354,6 @@ public class DriftDetailsView extends LocatableVLayout {
diff.append(line).append("<br/>");
}
}
-
return diff.toString();
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
index 9b96231..d4faced 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
@@ -29,6 +29,7 @@ import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftChangeSet;
import org.rhq.core.domain.drift.DriftComposite;
import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDetails;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.drift.FileDiffReport;
import org.rhq.core.domain.util.PageList;
@@ -115,4 +116,6 @@ public interface DriftGWTService extends RemoteService {
boolean isBinaryFile(Drift drift) throws RuntimeException;
+ DriftDetails getDriftDetails(String driftId) throws RuntimeException;
+
}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
index e8531be..55f9f7e 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
@@ -27,6 +27,7 @@ import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftChangeSet;
import org.rhq.core.domain.drift.DriftComposite;
import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDetails;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.drift.FileDiffReport;
import org.rhq.core.domain.util.PageList;
@@ -160,6 +161,16 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
}
@Override
+ public DriftDetails getDriftDetails(String driftId) throws RuntimeException {
+ try {
+ DriftDetails details = driftManager.getDriftDetails(getSessionSubject(),
driftId);
+ return SerialUtility.prepare(details,
"DriftService.getDriftDetails");
+ } catch (Throwable t) {
+ throw getExceptionToThrowToClient(t);
+ }
+ }
+
+ @Override
public boolean isBinaryFile(Drift drift) throws RuntimeException {
try {
return driftManager.isBinaryFile(drift);
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
index b1a7415..898a4c2 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
@@ -47,6 +47,8 @@ import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.DriftChangeSetCriteria;
import org.rhq.core.domain.criteria.DriftConfigurationCriteria;
import org.rhq.core.domain.criteria.DriftCriteria;
+import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
+import org.rhq.core.domain.criteria.GenericDriftCriteria;
import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftChangeSet;
import org.rhq.core.domain.drift.DriftComposite;
@@ -54,6 +56,7 @@ import org.rhq.core.domain.drift.DriftConfiguration;
import org.rhq.core.domain.drift.DriftConfigurationComparator;
import org.rhq.core.domain.drift.DriftConfigurationComparator.CompareMode;
import org.rhq.core.domain.drift.DriftConfigurationDefinition;
+import org.rhq.core.domain.drift.DriftDetails;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.drift.FileDiffReport;
@@ -115,6 +118,7 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
binaryFileTypes.add("jpg");
binaryFileTypes.add("png");
binaryFileTypes.add("jpeg");
+ binaryFileTypes.add("gif");
binaryFileTypes.add("pdf");
binaryFileTypes.add("swf");
binaryFileTypes.add("bpm");
@@ -389,12 +393,14 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
@Override
@TransactionAttribute(NOT_SUPPORTED)
public String getDriftFileBits(String hash) {
+ log.debug("Retrieving drift file content for " + hash);
DriftServerPluginFacet driftServerPlugin = getServerPlugin();
return driftServerPlugin.getDriftFileBits(hash);
}
@Override
public FileDiffReport generateUnifiedDiff(Drift drift) {
+ log.debug("Generating diff for " + drift);
String oldContent = getDriftFileBits(drift.getOldDriftFile().getHashId());
List<String> oldList = asList(oldContent.split("\\n"));
String newContent = getDriftFileBits(drift.getNewDriftFile().getHashId());
@@ -495,6 +501,69 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
return binaryFileTypes.contains(path.substring(index + 1, path.length()));
}
+ @Override
+ @TransactionAttribute(NOT_SUPPORTED)
+ public DriftDetails getDriftDetails(Subject subject, String driftId) {
+ log.debug("Loading drift details for drift id: " + driftId);
+
+ GenericDriftCriteria criteria = new GenericDriftCriteria();
+ criteria.addFilterId(driftId);
+ criteria.fetchChangeSet(true);
+
+ DriftDetails driftDetails = new DriftDetails();
+ DriftServerPluginFacet driftServerPlugin = getServerPlugin();
+
+ DriftFile newFile = null;
+ DriftFile oldFile = null;
+
+ PageList<? extends Drift<?, ?>> results =
driftServerPlugin.findDriftsByCriteria(subject, criteria);
+ if (results.size() == 0) {
+ log.warn("Unable to get the drift details for drift id " + driftId
+ ". No drift object found with that id.");
+ return null;
+ }
+
+ Drift drift = results.get(0);
+ driftDetails.setDrift(drift);
+ try {
+ switch (drift.getCategory()) {
+ case FILE_ADDED:
+ newFile = driftServerPlugin.getDriftFile(subject,
drift.getNewDriftFile().getHashId());
+ driftDetails.setNewFileStatus(newFile.getStatus());
+ break;
+ case FILE_CHANGED:
+ newFile = driftServerPlugin.getDriftFile(subject,
drift.getNewDriftFile().getHashId());
+ oldFile = driftServerPlugin.getDriftFile(subject,
drift.getOldDriftFile().getHashId());
+
+ driftDetails.setNewFileStatus(newFile.getStatus());
+ driftDetails.setOldFileStatus(oldFile.getStatus());
+
+ driftDetails.setPreviousChangeSet(loadPreviousChangeSet(subject,
drift));
+ break;
+ case FILE_REMOVED:
+ oldFile = driftServerPlugin.getDriftFile(subject,
drift.getOldDriftFile().getHashId());
+ driftDetails.setOldFileStatus(oldFile.getStatus());
+ break;
+ }
+ } catch (Exception e) {
+ log.error("An error occurred while loading the drift details for drift
id " + driftId + ": " +
+ e.getMessage());
+ throw new RuntimeException("An error occurred while loading th drift
details for drift id " + driftId, e);
+ }
+ driftDetails.setBinaryFile(isBinaryFile(drift));
+ return driftDetails;
+ }
+
+ private DriftChangeSet loadPreviousChangeSet(Subject subject, Drift drift) {
+ GenericDriftChangeSetCriteria criteria = new GenericDriftChangeSetCriteria();
+ criteria.addFilterResourceId(drift.getChangeSet().getResourceId());
+
criteria.addFilterDriftConfigurationId(drift.getChangeSet().getDriftConfigurationId());
+ criteria.addFilterVersion(Integer.toString(drift.getChangeSet().getVersion() -
1));
+
+ PageList<? extends DriftChangeSet<?>> results =
findDriftChangeSetsByCriteria(subject, criteria);
+ // TODO handle empty results
+ return results.get(0);
+ }
+
private DriftServerPluginFacet getServerPlugin() {
MasterServerPluginContainer masterPC =
LookupUtil.getServerPluginService().getMasterPluginContainer();
if (masterPC == null) {
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
index 663b626..5d9838f 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
@@ -28,6 +28,7 @@ import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.DriftConfigurationCriteria;
import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDetails;
import org.rhq.core.domain.drift.FileDiffReport;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.server.plugin.pc.drift.DriftServerPluginFacet;
@@ -130,5 +131,14 @@ public interface DriftManagerLocal extends DriftServerPluginFacet,
DriftManagerR
*/
FileDiffReport generateUnifiedDiff(Drift drift);
+ /**
+ * Returns an object that encapsulates the information needed for viewing drift
details
+ *
+ * @param subject
+ * @param driftId
+ * @return
+ */
+ DriftDetails getDriftDetails(Subject subject, String driftId);
+
boolean isBinaryFile(Drift drift);
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
index c3a34bf..daa7a68 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
@@ -77,6 +77,7 @@ import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
import org.rhq.enterprise.server.util.CriteriaQueryRunner;
import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
+import static org.rhq.core.domain.drift.DriftFileStatus.LOADED;
/**
* The SLSB method implementation needed to support the JPA (RHQ Default) Drift Server
Plugin.
@@ -217,7 +218,7 @@ public class JPADriftServerBean implements JPADriftServerLocal {
throw new IllegalArgumentException("JPADriftFile not found [" +
driftFile.getHashId() + "]");
}
df.setData(Hibernate.createBlob(new BufferedInputStream(data)));
- df.setStatus(DriftFileStatus.LOADED);
+ df.setStatus(LOADED);
}
@Override