use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.
the class ImportAction method importPackageFilterStream.
private void importPackageFilterStream(XWikiAttachment packFile, XWikiRequest request, XWikiContext context) throws IOException, XWikiException, FilterException {
String[] pages = request.getParameterValues("pages");
XARInputProperties xarProperties = new XARInputProperties();
DocumentInstanceOutputProperties instanceProperties = new DocumentInstanceOutputProperties();
instanceProperties.setSaveComment("Imported from XAR");
if (pages != null) {
EntityReferenceSet entities = new EntityReferenceSet();
EntityReferenceResolver<String> resolver = Utils.getComponent(EntityReferenceResolver.TYPE_STRING, "relative");
for (String pageEntry : pages) {
if (StringUtils.isNotEmpty(pageEntry)) {
String locale = getLocale(pageEntry, request);
int iAction = getAction(pageEntry, locale, request);
String documentReference = getDocumentReference(pageEntry);
if (iAction == DocumentInfo.ACTION_OVERWRITE) {
entities.includes(new LocalDocumentReference(resolver.resolve(documentReference, EntityType.DOCUMENT), LocaleUtils.toLocale(locale)));
}
}
}
xarProperties.setEntities(entities);
}
// Set the appropriate strategy to handle versions
if (StringUtils.equals(request.getParameter("historyStrategy"), "reset")) {
instanceProperties.setPreviousDeleted(true);
instanceProperties.setVersionPreserved(false);
xarProperties.setWithHistory(false);
} else if (StringUtils.equals(request.getParameter("historyStrategy"), "replace")) {
instanceProperties.setPreviousDeleted(true);
instanceProperties.setVersionPreserved(true);
xarProperties.setWithHistory(true);
} else {
instanceProperties.setPreviousDeleted(false);
instanceProperties.setVersionPreserved(false);
xarProperties.setWithHistory(false);
}
// Set the backup pack option
if (StringUtils.equals(request.getParameter("importAsBackup"), "true")) {
instanceProperties.setAuthorPreserved(true);
} else {
instanceProperties.setAuthorPreserved(false);
}
BeanInputFilterStreamFactory<XARInputProperties> xarFilterStreamFactory = Utils.getComponent((Type) InputFilterStreamFactory.class, FilterStreamType.XWIKI_XAR_CURRENT.serialize());
BeanInputFilterStream<XARInputProperties> xarFilterStream = xarFilterStreamFactory.createInputFilterStream(xarProperties);
BeanOutputFilterStreamFactory<InstanceOutputProperties> instanceFilterStreamFactory = Utils.getComponent((Type) OutputFilterStreamFactory.class, FilterStreamType.XWIKI_INSTANCE.serialize());
BeanOutputFilterStream<InstanceOutputProperties> instanceFilterStream = instanceFilterStreamFactory.createOutputFilterStream(instanceProperties);
// Notify all the listeners about import
ObservationManager observation = Utils.getComponent(ObservationManager.class);
InputStream source = packFile.getContentInputStream(context);
xarProperties.setSource(new DefaultInputStreamInputSource(source));
// Setup log
xarProperties.setVerbose(true);
instanceProperties.setVerbose(true);
instanceProperties.setStoppedWhenSaveFail(false);
LoggerManager loggerManager = Utils.getComponent(LoggerManager.class);
LogQueue logger = new LogQueue();
if (loggerManager != null) {
// Isolate log
loggerManager.pushLogListener(new LoggerListener(UUID.randomUUID().toString(), logger));
}
observation.notify(new XARImportingEvent(), null, context);
try {
xarFilterStream.read(instanceFilterStream.getFilter());
xarFilterStream.close();
instanceFilterStream.close();
} finally {
if (loggerManager != null) {
// Stop isolating log
loggerManager.popLogListener();
}
// Print the import log
if (LOGGER.isDebugEnabled()) {
logger.log(LOGGER);
} else {
// TODO: remove when the UI show the log properly
for (LogEvent logEvent : logger.getLogsFrom(LogLevel.ERROR)) {
logEvent.log(LOGGER);
}
}
// Close the input source
source.close();
observation.notify(new XARImportedEvent(), null, context);
}
// Generate import report
// Emulate old packager report (for retro compatibility)
Package oldImporter = new Package();
if (logger.containLogsFrom(LogLevel.ERROR)) {
context.put("install_status", DocumentInfo.INSTALL_ERROR);
} else {
context.put("install_status", DocumentInfo.INSTALL_OK);
}
EntityReferenceSerializer<String> serializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "local");
for (LogEvent log : logger) {
Marker marker = log.getMarker();
if (marker != null) {
if (marker.contains(WikiDocumentFilter.LOG_DOCUMENT_CREATED.getName()) || marker.contains(WikiDocumentFilter.LOG_DOCUMENT_UPDATED.getName())) {
oldImporter.getInstalled(context).add(serializer.serialize((EntityReference) log.getArgumentArray()[0]));
} else if (marker.contains(WikiDocumentFilter.LOG_DOCUMENT_SKIPPED.getName())) {
oldImporter.getSkipped(context).add(serializer.serialize((EntityReference) log.getArgumentArray()[0]));
} else if (marker.contains(WikiDocumentFilter.LOG_DOCUMENT_ERROR.getName())) {
Object entity = log.getArgumentArray()[0];
if (entity != null) {
oldImporter.getErrors(context).add(entity instanceof EntityReference ? serializer.serialize((EntityReference) log.getArgumentArray()[0]) : entity.toString());
}
}
}
}
}
use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.
the class ModelFactory method toRestJobLog.
public JobLog toRestJobLog(Collection<LogEvent> logs, URI self) {
JobLog log = this.objectFactory.createJobLog();
// Serialize log
for (LogEvent logEvent : logs) {
// TODO: add support for log arguments
// TODO: add support for log Marker
org.xwiki.rest.model.jaxb.LogEvent event = this.objectFactory.createLogEvent();
event.setLevel(logEvent.getLevel().name());
Calendar calendarDate = Calendar.getInstance();
calendarDate.setTimeInMillis(logEvent.getTimeStamp());
event.setDate(calendarDate);
event.setFormattedMessage(logEvent.getFormattedMessage());
log.getLogEvents().add(event);
}
// Set link
if (self != null) {
Link link = this.objectFactory.createLink();
link.setHref(self.toString());
link.setRel(Relations.SELF);
log.getLinks().add(link);
}
return log;
}
use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.
the class ExtensionManagerScriptServiceTest method install.
// tools
private Job install(String id, String version, String namespace) throws Throwable {
Job job = this.scriptService.install(id, version, namespace);
if (job == null) {
throw this.scriptService.getLastError();
}
job.join();
List<LogEvent> errors = job.getStatus().getLog().getLogsFrom(LogLevel.WARN);
if (!errors.isEmpty()) {
throw errors.get(0).getThrowable();
}
return job;
}
use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.
the class ExtensionManagerScriptServiceTest method uninstall.
private Job uninstall(String id, String namespace) throws Throwable {
Job job = this.scriptService.uninstall(id, namespace);
if (job == null) {
throw this.scriptService.getLastError();
}
job.join();
List<LogEvent> errors = job.getStatus().getLog().getLogsFrom(LogLevel.WARN);
if (!errors.isEmpty()) {
throw errors.get(0).getThrowable();
}
return job;
}
use of org.xwiki.logging.event.LogEvent in project xwiki-platform by xwiki.
the class ExtensionManagerScriptServiceTest method testOverwriteAllowedNamespaces.
@Test
public void testOverwriteAllowedNamespaces() throws Throwable {
InstallRequest installRequest = this.scriptService.createInstallRequest("extension", "version", "namespace");
// Indicate all extensions of type "test" should be installed on root
((ScriptExtensionRewriter) installRequest.getRewriter()).installExtensionTypeOnRootNamespace("test");
// Allow redirect on root
installRequest.setRootModificationsAllowed(true);
Job job = this.scriptService.install(installRequest);
if (job == null) {
throw this.scriptService.getLastError();
}
job.join();
List<LogEvent> errors = job.getStatus().getLog().getLogsFrom(LogLevel.WARN);
if (!errors.isEmpty()) {
throw errors.get(0).getThrowable();
}
// Validate
InstalledExtensionRepository repository = mocker.getInstance(InstalledExtensionRepository.class);
assertNotNull(repository.getInstalledExtension("extension", null));
}
Aggregations