}
}
private void initGrid() {
User user = (User) getUser();
Authorization auth = m_userAdmin.getAuthorization(user);
int count = 0;
for (String role : new String[] { "viewArtifact", "viewFeature", "viewDistribution", "viewTarget" }) {
if (auth.hasRole(role)) {
count++;
}
}
final GenericUploadHandler uploadHandler = new GenericUploadHandler(m_sessionDir) {
@Override
public void updateProgress(long readBytes, long contentLength) {
Float percentage = new Float(readBytes / (float) contentLength);
m_progress.setValue(percentage);
}
@Override
protected void artifactsUploaded(List<UploadHandle> uploadedArtifacts) {
StringBuilder failedMsg = new StringBuilder();
StringBuilder successMsg = new StringBuilder();
Set<String> selection = new HashSet<String>();
for (UploadHandle handle : uploadedArtifacts) {
if (!handle.isSuccessful()) {
// Upload failed, so let's report this one...
appendFailure(failedMsg, handle);
m_log.log(LogService.LOG_ERROR, "Upload of " + handle.getFile() + " failed.", handle.getFailureReason());
}
else {
try {
// Upload was successful, try to upload it to our OBR...
ArtifactObject artifact = uploadToOBR(handle);
if (artifact != null) {
selection.add(artifact.getDefinition());
appendSuccess(successMsg, handle);
}
}
catch (ArtifactAlreadyExistsException exception) {
appendFailureExists(failedMsg, handle);
m_log.log(LogService.LOG_WARNING, "Upload of " + handle.getFilename() + " failed, as it already exists!");
}
catch (Exception exception) {
appendFailure(failedMsg, handle, exception);
m_log.log(LogService.LOG_ERROR, "Upload of " + handle.getFilename() + " failed.", exception);
}
}
// We're done with this (temporary) file, so we can remove it...
handle.cleanup();
}
m_artifactsPanel.setValue(selection);
// Notify the user what the overall status was...
Notification notification = createNotification(failedMsg, successMsg);
getMainWindow().showNotification(notification);
m_progress.setStyleName("invisible");
m_statusLine.setStatus(notification.getCaption() + "...");
}
@Override
protected void uploadStarted(UploadHandle upload) {
m_progress.setStyleName("visible");
m_progress.setValue(new Float(0.0f));
m_statusLine.setStatus("Upload of '%s' started...", upload.getFilename());
}
private void appendFailure(StringBuilder sb, UploadHandle handle) {
appendFailure(sb, handle, handle.getFailureReason());
}
private void appendFailure(StringBuilder sb, UploadHandle handle, Exception cause) {
sb.append("<li>'").append(handle.getFile().getName()).append("': failed");
if (cause != null) {
sb.append(", possible reason:<br/>").append(cause.getMessage());
}
sb.append("</li>");
}
private void appendFailureExists(StringBuilder sb, UploadHandle handle) {
sb.append("<li>'").append(handle.getFile().getName()).append("': already exists in repository</li>");
}
private void appendSuccess(StringBuilder sb, UploadHandle handle) {
sb.append("<li>'").append(handle.getFile().getName()).append("': added to repository</li>");
}
private Notification createNotification(StringBuilder failedMsg, StringBuilder successMsg) {
String caption = "Upload completed";
int delay = 500; // msec.
StringBuilder notification = new StringBuilder();
if (failedMsg.length() > 0) {
caption = "Upload completed with failures";
delay = -1;
notification.append("<ul>").append(failedMsg).append("</ul>");
}
if (successMsg.length() > 0) {
notification.append("<ul>").append(successMsg).append("</ul>");
}
if (delay < 0) {
notification.append("<p>(click to dismiss this notification).</p>");
}
Notification summary = new Notification(caption, notification.toString(), Notification.TYPE_TRAY_NOTIFICATION);
summary.setDelayMsec(delay);
return summary;
}
private ArtifactObject uploadToOBR(UploadHandle handle) throws IOException {
return UploadHelper.importRemoteBundle(m_artifactRepository, handle.getFile());
}
};
m_grid = new GridLayout(count, 4);
m_grid.setSpacing(true);
m_grid.setSizeFull();
m_mainToolbar = createToolbar();
m_grid.addComponent(m_mainToolbar, 0, 0, count - 1, 0);
m_artifactsPanel = createArtifactsPanel();
m_artifactToolbar = createArtifactToolbar();
final DragAndDropWrapper artifactsPanelWrapper = new DragAndDropWrapper(m_artifactsPanel);
artifactsPanelWrapper.setDragStartMode(DragStartMode.HTML5);
artifactsPanelWrapper.setDropHandler(new ArtifactDropHandler(uploadHandler));
artifactsPanelWrapper.setCaption(m_artifactsPanel.getCaption());
artifactsPanelWrapper.setSizeFull();
count = 0;
if (auth.hasRole("viewArtifact")) {
m_grid.addComponent(artifactsPanelWrapper, count, 2);
m_grid.addComponent(m_artifactToolbar, count, 1);
count++;
}
m_featuresPanel = createFeaturesPanel();
m_featureToolbar = createFeatureToolbar();
if (auth.hasRole("viewFeature")) {
m_grid.addComponent(m_featuresPanel, count, 2);
m_grid.addComponent(m_featureToolbar, count, 1);
count++;
}
m_distributionsPanel = createDistributionsPanel();
m_distributionToolbar = createDistributionToolbar();
if (auth.hasRole("viewDistribution")) {
m_grid.addComponent(m_distributionsPanel, count, 2);
m_grid.addComponent(m_distributionToolbar, count, 1);
count++;
}
m_targetsPanel = createTargetsPanel();
m_targetToolbar = createTargetToolbar();
if (auth.hasRole("viewTarget")) {
m_grid.addComponent(m_targetsPanel, count, 2);
m_grid.addComponent(m_targetToolbar, count, 1);
}
m_statusLine = new StatusLine();