Removed depcrecated package com.arsdigita.ui.admin.importexport from ccm-core
parent
473240777a
commit
c9f48f042b
|
|
@ -1,182 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 LibreCCM Foundation.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.importexport;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.ui.admin.AdminUiConstants;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ExportSection extends BoxPanel {
|
|
||||||
|
|
||||||
public ExportSection() {
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
add(new ExportForm());
|
|
||||||
add(new StatusLabel());
|
|
||||||
add(new ReportForm());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ExportForm extends Form implements FormProcessListener {
|
|
||||||
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public ExportForm() {
|
|
||||||
super("exportForm");
|
|
||||||
|
|
||||||
// This placeholder will be replaced with a list of the available
|
|
||||||
// exporters and checkboxes to select the exporters to use.
|
|
||||||
add(new Text("export section placeholder"));
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
saveCancelSection.getSaveButton().setButtonLabel(
|
|
||||||
new GlobalizedMessage("ui.admin.importexport.export.start",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
add(saveCancelSection);
|
|
||||||
addProcessListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
return !monitor.isLocked();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportController controller = cdiUtil
|
|
||||||
.findBean(ImportExportController.class);
|
|
||||||
controller.export(new ArrayList<>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class StatusLabel extends Label {
|
|
||||||
|
|
||||||
public StatusLabel() {
|
|
||||||
super(event -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
final Label target = (Label) event.getTarget();
|
|
||||||
if (monitor.isExportActive()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.export.status.export_active",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
} else if (monitor.isImportActive()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.export.status.import_active",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.export.status.locked",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
return monitor.isLocked();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ReportForm extends Form {
|
|
||||||
|
|
||||||
public ReportForm() {
|
|
||||||
|
|
||||||
super("exportReportForm", new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
final Label title = new Label(event -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
|
|
||||||
final Label target = (Label) event.getTarget();
|
|
||||||
|
|
||||||
if (monitor.isExportActive()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.export.current_status",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
} else if (monitor.isExportReportAvailable()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.export.report",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
add(title);
|
|
||||||
|
|
||||||
final Text text = new Text(event -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
final Text target = (Text) event.getTarget();
|
|
||||||
target.setText(monitor.getReport().toString());
|
|
||||||
});
|
|
||||||
text.setClassAttr("preformatted-text");
|
|
||||||
add(text);
|
|
||||||
|
|
||||||
add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.report.update",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
|
|
||||||
return monitor.isExportActive()
|
|
||||||
|| monitor.isExportReportAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 LibreCCM Foundation.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.importexport;
|
|
||||||
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.core.UnexpectedErrorException;
|
|
||||||
import org.libreccm.files.CcmFiles;
|
|
||||||
import org.libreccm.files.FileAccessException;
|
|
||||||
import org.libreccm.files.FileDoesNotExistException;
|
|
||||||
import org.libreccm.files.InsufficientPermissionsException;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.ejb.Asynchronous;
|
|
||||||
import javax.ejb.Stateless;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@Stateless
|
|
||||||
public class ImportExportController {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ConfigurationManager confManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ImportExportMonitor monitor;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private CcmFiles ccmFiles;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the fully qualified class names for all available exporters.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<String> getAvailableExporters() {
|
|
||||||
// Note: Return value may needs to be adjusted. Possibly we need a
|
|
||||||
// data structure which contains some more information like a
|
|
||||||
// localised label for the exporters etc.
|
|
||||||
throw new UnsupportedOperationException("Not implemented yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an export into the directory configured by
|
|
||||||
* {@link KernelConfig#exportPath} using the provided exporters.
|
|
||||||
*
|
|
||||||
* @param exporters The exporters to use.
|
|
||||||
*/
|
|
||||||
@Asynchronous
|
|
||||||
public void export(final List<String> exporters) {
|
|
||||||
monitor.startExport();
|
|
||||||
|
|
||||||
final long start = System.currentTimeMillis();
|
|
||||||
|
|
||||||
while (System.currentTimeMillis() < start + 60 * 1000) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(3 * 1000);
|
|
||||||
} catch (InterruptedException ex) {
|
|
||||||
throw new UnexpectedErrorException(ex);
|
|
||||||
}
|
|
||||||
monitor.getReport().append(String.format("...%tF %<tT%n",
|
|
||||||
new Date()));
|
|
||||||
}
|
|
||||||
|
|
||||||
monitor.finishExport();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getAvailableImportFiles() {
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager
|
|
||||||
.findConfiguration(KernelConfig.class);
|
|
||||||
final String importPath = kernelConfig.getImportPath();
|
|
||||||
|
|
||||||
try {
|
|
||||||
return ccmFiles.listFiles(importPath);
|
|
||||||
} catch (FileAccessException
|
|
||||||
| FileDoesNotExistException
|
|
||||||
| InsufficientPermissionsException ex) {
|
|
||||||
throw new UnexpectedErrorException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void importFiles(final List<String> filesToImport) {
|
|
||||||
monitor.startImport();
|
|
||||||
|
|
||||||
// ToDol Import code here
|
|
||||||
|
|
||||||
monitor.finishImport();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,155 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 LibreCCM Foundation.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.importexport;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@ApplicationScoped
|
|
||||||
public class ImportExportMonitor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates that an export process is running.
|
|
||||||
*/
|
|
||||||
private boolean exportActive = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates that an import process is running.
|
|
||||||
*/
|
|
||||||
private boolean importActive = false;
|
|
||||||
|
|
||||||
private boolean exportReportAvailable = false;
|
|
||||||
|
|
||||||
private boolean importReportAvailable = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A UUID to identify to the import/export process.
|
|
||||||
*/
|
|
||||||
private String importExportProcessUuid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link StringBuffer} for creating a report of the import/export
|
|
||||||
* process. The report of the last import/export process will be stored
|
|
||||||
* until another import/export process is started or the application is
|
|
||||||
* restarted.
|
|
||||||
*/
|
|
||||||
private StringBuffer report;
|
|
||||||
|
|
||||||
public boolean isExportActive() {
|
|
||||||
return exportActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isImportActive() {
|
|
||||||
return importActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns {@code true} if either an import process or an export process is
|
|
||||||
* active.
|
|
||||||
*
|
|
||||||
* @return {@code true} if an import or export process is active.
|
|
||||||
*/
|
|
||||||
public boolean isLocked() {
|
|
||||||
return exportActive || importActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExportReportAvailable() {
|
|
||||||
return exportReportAvailable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isImportReportAvailable() {
|
|
||||||
return importReportAvailable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startExport() {
|
|
||||||
if (exportActive) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Can't start a new export process "
|
|
||||||
+ "because there is already an export process running");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (importActive) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Can't start a export process "
|
|
||||||
+ "because there is already an import process running");
|
|
||||||
}
|
|
||||||
|
|
||||||
exportActive = true;
|
|
||||||
importExportProcessUuid = UUID.randomUUID().toString();
|
|
||||||
report = new StringBuffer();
|
|
||||||
report.append(String
|
|
||||||
.format("Lock for export process %s accquired at %tF %<tT%n",
|
|
||||||
importExportProcessUuid,
|
|
||||||
new Date()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void finishExport() {
|
|
||||||
exportActive = false;
|
|
||||||
report.append(String
|
|
||||||
.format("Lock for export process %s released at %tF %<tT%n",
|
|
||||||
importExportProcessUuid,
|
|
||||||
new Date()));
|
|
||||||
importExportProcessUuid = null;
|
|
||||||
exportReportAvailable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startImport() {
|
|
||||||
if (exportActive) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Can't start a new import process "
|
|
||||||
+ "because there is already an export process running");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (importActive) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Can't start a new import process "
|
|
||||||
+ "because there is already an import process running");
|
|
||||||
}
|
|
||||||
|
|
||||||
importActive = true;
|
|
||||||
importExportProcessUuid = UUID.randomUUID().toString();
|
|
||||||
report = new StringBuffer();
|
|
||||||
report.append(String
|
|
||||||
.format("Lock for import process %s released at %tF %<tT%n",
|
|
||||||
importExportProcessUuid,
|
|
||||||
new Date()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void finishImport() {
|
|
||||||
importActive = false;
|
|
||||||
report.append(String
|
|
||||||
.format("Lock for import process %s released at %tF %<tT%n",
|
|
||||||
importExportProcessUuid,
|
|
||||||
new Date()));
|
|
||||||
importExportProcessUuid = null;
|
|
||||||
importReportAvailable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringBuffer getReport() {
|
|
||||||
return report;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,182 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 LibreCCM Foundation.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.importexport;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.List;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Resettable;
|
|
||||||
import com.arsdigita.bebop.list.ListModel;
|
|
||||||
import com.arsdigita.bebop.list.ListModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
import com.arsdigita.ui.admin.AdminUiConstants;
|
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ImportExportTab extends LayoutPanel {
|
|
||||||
|
|
||||||
private List sections;
|
|
||||||
private final java.util.List<Component> components = new ArrayList<>();
|
|
||||||
private final java.util.List<Label> keys = new ArrayList<>();
|
|
||||||
|
|
||||||
public ImportExportTab() {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
setClassAttr("sidebarNavPanel");
|
|
||||||
|
|
||||||
sections = new List(new SectionsListModelBuilder());
|
|
||||||
|
|
||||||
sections.addChangeListener(event -> {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final int selectedIndex = Integer
|
|
||||||
.parseInt((String) sections.getSelectedKey(state));
|
|
||||||
setSection(selectedIndex, state);
|
|
||||||
});
|
|
||||||
sections.setClassAttr("navbar");
|
|
||||||
|
|
||||||
final BoxPanel body = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
addSection(
|
|
||||||
new Label(
|
|
||||||
new GlobalizedMessage("ui.admin.importexport.export.title",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE)),
|
|
||||||
new ExportSection(),
|
|
||||||
body);
|
|
||||||
addSection(
|
|
||||||
new Label(
|
|
||||||
new GlobalizedMessage("ui.admin.importexport.import.title",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE)),
|
|
||||||
new ImportSection(),
|
|
||||||
body);
|
|
||||||
|
|
||||||
setLeft(sections);
|
|
||||||
setBody(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method for adding a section
|
|
||||||
*
|
|
||||||
* @param label The label of the section.
|
|
||||||
* @param component The component which provides the section.
|
|
||||||
* @param panel The panel to which the component is added.
|
|
||||||
*/
|
|
||||||
private void addSection(final Label label,
|
|
||||||
final Component component,
|
|
||||||
final BoxPanel panel) {
|
|
||||||
Assert.isUnlocked(this);
|
|
||||||
components.add(component);
|
|
||||||
component.setClassAttr("main");
|
|
||||||
panel.add(component);
|
|
||||||
keys.add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the components in the page
|
|
||||||
*
|
|
||||||
* @param page The Admin UI page.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
Assert.isUnlocked(this);
|
|
||||||
|
|
||||||
components.forEach(c -> page.setVisibleDefault(c, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the current section.
|
|
||||||
*
|
|
||||||
* @param index The index of the section.
|
|
||||||
* @param state The page state.
|
|
||||||
*/
|
|
||||||
public void setSection(final int index, final PageState state) {
|
|
||||||
sections.setSelectedKey(state, String.valueOf(index));
|
|
||||||
for (int i = 0; i < components.size(); i++) {
|
|
||||||
if (i == index) {
|
|
||||||
final Component component = components.get(i);
|
|
||||||
component.setVisible(state, true);
|
|
||||||
if (component instanceof Resettable) {
|
|
||||||
final Resettable resettable = (Resettable) component;
|
|
||||||
resettable.reset(state);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
components.get(i).setVisible(state, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model Builder for the section list.
|
|
||||||
*/
|
|
||||||
private class SectionsListModelBuilder extends LockableImpl
|
|
||||||
implements ListModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ListModel makeModel(final List list,
|
|
||||||
final PageState state) {
|
|
||||||
if (sections.getSelectedKey(state) == null) {
|
|
||||||
sections.setSelectedKey(state, String.valueOf(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SectionsListModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model for the section list.
|
|
||||||
*/
|
|
||||||
private class SectionsListModel implements ListModel {
|
|
||||||
|
|
||||||
private int index = -1;
|
|
||||||
private final PageState state;
|
|
||||||
|
|
||||||
public SectionsListModel(final PageState state) {
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() {
|
|
||||||
final boolean result = (index < keys.size() - 1);
|
|
||||||
index++;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
return keys.get(index).getLabel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKey() {
|
|
||||||
return String.valueOf(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,213 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 LibreCCM Foundation.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.importexport;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.parameters.ArrayParameter;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.ui.admin.AdminUiConstants;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.core.UnexpectedErrorException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ImportSection extends BoxPanel {
|
|
||||||
|
|
||||||
public ImportSection() {
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
add(new ImportForm());
|
|
||||||
add(new StatusLabel());
|
|
||||||
add(new ReportForm());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ImportForm extends Form implements FormProcessListener {
|
|
||||||
|
|
||||||
private static final String SELECTED_IMPORTS_PARAM
|
|
||||||
= "selectedImportsParam";
|
|
||||||
|
|
||||||
private final CheckboxGroup importsSelector;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public ImportForm() {
|
|
||||||
super("importForm", new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
add(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.import.select_files_to_import",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE)));
|
|
||||||
importsSelector = new CheckboxGroup(SELECTED_IMPORTS_PARAM);
|
|
||||||
try {
|
|
||||||
importsSelector.addPrintListener(event -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportController controller = cdiUtil
|
|
||||||
.findBean(ImportExportController.class);
|
|
||||||
final CheckboxGroup target = (CheckboxGroup) event
|
|
||||||
.getTarget();
|
|
||||||
final List<String> importFiles = controller
|
|
||||||
.getAvailableImportFiles();
|
|
||||||
importFiles.forEach(file -> {
|
|
||||||
target.addOption(new Option(file, new Text(file)));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UnexpectedErrorException(ex);
|
|
||||||
}
|
|
||||||
add(importsSelector);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
saveCancelSection
|
|
||||||
.getSaveButton()
|
|
||||||
.setButtonLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.import.execute",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
add(saveCancelSection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
return !monitor.isLocked();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void process(final FormSectionEvent event)
|
|
||||||
throws FormProcessException {
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportController controller = cdiUtil
|
|
||||||
.findBean(ImportExportController.class);
|
|
||||||
|
|
||||||
final String[] selectedFiles = (String[]) importsSelector
|
|
||||||
.getValue(state);
|
|
||||||
controller.importFiles(Arrays.asList(selectedFiles));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class StatusLabel extends Label {
|
|
||||||
|
|
||||||
public StatusLabel() {
|
|
||||||
super(event -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
final Label target = (Label) event.getTarget();
|
|
||||||
if (monitor.isExportActive()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.import.status.export_active",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
} else if (monitor.isImportActive()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.import.status.import_active",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.import.status.locked",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
return monitor.isLocked();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ReportForm extends Form {
|
|
||||||
|
|
||||||
public ReportForm() {
|
|
||||||
|
|
||||||
super("importReportForm", new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
final Label title = new Label(event -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
|
|
||||||
final Label target = (Label) event.getTarget();
|
|
||||||
|
|
||||||
if (monitor.isExportActive()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.import.current_status",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
} else if (monitor.isExportReportAvailable()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.import.report",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
add(title);
|
|
||||||
|
|
||||||
final Text text = new Text(event -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
final Text target = (Text) event.getTarget();
|
|
||||||
target.setText(monitor.getReport().toString());
|
|
||||||
});
|
|
||||||
text.setClassAttr("preformatted-text");
|
|
||||||
add(text);
|
|
||||||
|
|
||||||
add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.importexport.report.update",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ImportExportMonitor monitor = cdiUtil
|
|
||||||
.findBean(ImportExportMonitor.class);
|
|
||||||
|
|
||||||
return monitor.isImportActive()
|
|
||||||
|| monitor.isImportReportAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue