Skip to content

Commit

Permalink
Merge pull request #775 from eclipse-passage/573533
Browse files Browse the repository at this point in the history
Bug 573533 - [Passage][Operator] failed to load users base
  • Loading branch information
eparovyshnaya authored May 14, 2021
2 parents ca551cd + 7e30c0a commit 6ff2803
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
* Copyright (c) 2020, 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,12 +10,14 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.loc.internal.api.diagnostic.code;
package org.eclipse.passage.lic.emf.resource;

import org.eclipse.passage.lic.internal.api.diagnostic.TroubleCode;
import org.eclipse.passage.lic.internal.emf.i18n.EmfMessages;

@SuppressWarnings("restriction")
/**
* @since 2.0
*/
public final class ResourceLoadFailed extends TroubleCode {

public ResourceLoadFailed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.emf.resource;

import org.eclipse.passage.lic.internal.api.diagnostic.TroubleCode;
import org.eclipse.passage.lic.internal.emf.i18n.EmfMessages;

/**
* @since 2.0
*/
public final class ResourceSaveFailed extends TroubleCode {

public ResourceSaveFailed() {
super(898, EmfMessages.ResourceSaveFailed_explanation);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ public final class EmfMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.passage.lic.internal.emf.i18n.EmfMessages"; //$NON-NLS-1$

public static String BaseDomainRegistry_e_load_failed;

public static String BaseDomainRegistry_e_load_workspace;
public static String BaseDomainRegistry_ok_load;
public static String BaseDomainRegistry_ok_unload;
public static String LicensingEcore_inpur_header;
public static String LicensingEcore_input_entry;
public static String LicensingEcore_input_invalid;
public static String ResourceLoadFailed_explanation;
public static String ResourceSaveFailed_explanation;

public static String XmiToEObject_failed_xmi_read;
public static String XmiToEObject_unexpected_amount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
BaseDomainRegistry_ok_load=Loaded {0}
BaseDomainRegistry_ok_unload=Unloaded {0}
###############################################################################
# Copyright (c) 2019, 2020 ArSysOp and others
# Copyright (c) 2019, 2021 ArSysOp and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -13,11 +11,15 @@ BaseDomainRegistry_ok_unload=Unloaded {0}
# ArSysOp - initial API and implementation
###############################################################################

BaseDomainRegistry_ok_load=Loaded {0}
BaseDomainRegistry_ok_unload=Unloaded {0}
BaseDomainRegistry_e_load_failed=Failed to load {0}
BaseDomainRegistry_e_load_workspace=Failed to load workspace
LicensingEcore_inpur_header=%s error(s) occurred while analyzing your inputs:
LicensingEcore_input_entry=%s. %s
LicensingEcore_input_invalid=Input is invalid
ResourceLoadFailed_explanation=EMF resource loading failed
ResourceSaveFailed_explanation=EMF resource saving failed

XmiToEObject_failed_xmi_read=Reading xmi content failed
XmiToEObject_unexpected_amount=Unexpected amount of contents in Floating License Access file: %d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class UsersResourceHandler extends MigratingResourceHandler {
protected void ensureMigrations() {
migrate033();
migrate040();
migrate050();
}

@Override
Expand All @@ -50,4 +51,10 @@ private void migrate040() {
UsersPackage delegate = UsersPackage.eINSTANCE;
EPackage.Registry.INSTANCE.put(nsUri, delegate);
}

private void migrate050() {
String nsUri = "http://www.eclipse.org/passage/lic/users/0.5.0"; //$NON-NLS-1$
UsersPackage delegate = UsersPackage.eINSTANCE;
EPackage.Registry.INSTANCE.put(nsUri, delegate);
}
}
11 changes: 0 additions & 11 deletions bundles/org.eclipse.passage.loc.api/.settings/.api_filters

This file was deleted.

2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.passage.loc.api
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.passage.loc.api
Bundle-Version: 1.1.0.qualifier
Bundle-Version: 2.0.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
Expand All @@ -31,11 +32,14 @@
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.osgi.util.NLS;
import org.eclipse.passage.lic.emf.resource.ResourceLoadFailed;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.diagnostic.Diagnostic;
import org.eclipse.passage.lic.internal.api.diagnostic.Trouble;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.diagnostic.DiagnosticExplained;
import org.eclipse.passage.lic.internal.base.diagnostic.NoErrors;
import org.eclipse.passage.lic.internal.emf.i18n.EmfMessages;
import org.eclipse.passage.loc.internal.api.diagnostic.code.ResourceLoadFailed;

@SuppressWarnings("restriction")
public abstract class BaseDomainRegistry<I> implements EditingDomainRegistry<I>, IEditingDomainProvider {
Expand Down Expand Up @@ -69,13 +73,20 @@ protected void loadResourceSet() {
if (!Files.exists(domainPath)) {
return;
}
Files.readAllLines(domainPath).forEach(this::registerSource);
Files.readAllLines(domainPath).stream()//
.map(this::registerSource)//
.map(ServiceInvocationResult::diagnostic)//
.filter(new NoErrors().negate())//
.forEach(this::logDiagnostic);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Platform.getLog(getClass()).error(EmfMessages.BaseDomainRegistry_e_load_workspace, e);
}
}

protected void logDiagnostic(Diagnostic diagnostic) {
Platform.getLog(getClass()).error(new DiagnosticExplained(diagnostic).get());
}

protected abstract Path getResourceSetPath() throws Exception;

protected abstract DomainContentAdapter<I, ? extends EditingDomainRegistry<I>> createContentAdapter();
Expand Down Expand Up @@ -115,6 +126,7 @@ public ServiceInvocationResult<Boolean> loadSource(String source) {
URI uri = createURI(source);
ResourceSet set = editingDomain.getResourceSet();
Resource resource = createResource(uri);
resource.eAdapters().add(contentAdapter);
set.getResources().add(resource);
try {
resource.load(getLoadOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public final class WorkbenchEmfformsMessages extends NLS {

private static final String BUNDLE_NAME = "org.eclipse.passage.loc.internal.workbench.emfforms.i18n.WorkbenchEmfformsMessages"; //$NON-NLS-1$

public static String DetailsView_e_save_title;

public static String DetailsView_label_details;
public static String TextWithButtonRenderer_button_edit;
public static String ConditionExpressionRenderer_condition_expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ArSysOp - initial API and implementation
###############################################################################

DetailsView_e_save_title=Error
DetailsView_label_details=Details
TextWithButtonRenderer_button_edit=Edit...

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2020 ArSysOp
* Copyright (c) 2018, 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -12,14 +12,17 @@
*******************************************************************************/
package org.eclipse.passage.loc.workbench.emfforms.parts;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.Persist;
Expand All @@ -46,6 +49,7 @@
import org.eclipse.emfforms.spi.swt.treemasterdetail.actions.MasterDetailAction;
import org.eclipse.emfforms.spi.swt.treemasterdetail.util.CreateElementCallback;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ISelection;
Expand Down Expand Up @@ -250,13 +254,17 @@ public void save() {
}
Resource eResource = root.get(0).eResource();
if (eResource != null) {
IStatus status = LocWokbench.save(eResource);
if (status.isOK()) {
try {
eResource.save(new HashMap<>());
if (commandStack instanceof BasicCommandStack) {
BasicCommandStack basicCommandStack = (BasicCommandStack) commandStack;
basicCommandStack.saveIsDone();
part.setDirty(basicCommandStack.isSaveNeeded());
}
} catch (IOException e) {
String message = WorkbenchEmfformsMessages.DetailsView_e_save_title;
IStatus error = new Status(IStatus.ERROR, getClass(), message, e);
ErrorDialog.openError(content.getShell(), message, message, error);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
import org.eclipse.passage.lic.jface.resource.LicensingColorResolver;
import org.eclipse.passage.loc.workbench.LocWokbench;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
Expand Down Expand Up @@ -106,7 +105,7 @@ protected String getTextMessage() {
.getDisplayName(getVElement().getDomainModelReference(), getViewModelContext().getDomainModel())
.getValue();
} catch (final NoLabelFoundException ex) {
Status status = new Status(IStatus.ERROR, LocWokbench.BUNDLE_SYMBOLIC_NAME, ex.getMessage(), ex);
Status status = new Status(IStatus.ERROR, getClass(), ex.getMessage(), ex);
getReportService().report(new StatusReport(status));
}
return TEXT_MESSAGE_DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class WorkbenchMessages extends NLS {
public static String RedoHandler_label_base;
public static String RedoHandler_label_pattern;
public static String BaseClassifierWizard_e_registry_null;
public static String InnerClassifierWizard_e_store;
public static String InnerClassifierWizardPage_e_specify_container;
public static String InnerClassifierWizardPage_text_select;
public static String BaseClassifierWizard_message_e_cancelled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ LocWokbench_e_saving=Error saving resource
RedoHandler_label_base=Redo
RedoHandler_label_pattern={0} {1}
BaseClassifierWizard_e_registry_null=EditingDomainRegistry must not be null
InnerClassifierWizard_e_store=Failed to store created object
InnerClassifierWizardPage_e_specify_container=Please specify {0}
InnerClassifierWizardPage_text_select=Select...
BaseClassifierWizard_message_e_cancelled=Operation failed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.passage.lic.emf.meta.EntityMetadata;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry;
import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages;
import org.osgi.framework.Bundle;
Expand Down Expand Up @@ -110,7 +111,7 @@ public boolean performFinish() {
}
}

protected abstract void store();
protected abstract ServiceInvocationResult<Boolean> store();

protected void failed(Throwable target) {
Bundle bundle = FrameworkUtil.getBundle(getClass());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.eclipse.passage.loc.internal.workbench.wizards;

import java.io.IOException;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.util.Optional;

Expand All @@ -9,10 +11,14 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.passage.lic.emf.meta.ComposableClassMetadata;
import org.eclipse.passage.lic.emf.meta.EntityMetadata;
import org.eclipse.passage.lic.emf.resource.ResourceSaveFailed;
import org.eclipse.passage.lic.internal.api.MandatoryService;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.diagnostic.Trouble;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry;
import org.eclipse.passage.loc.internal.workbench.SelectRequest;
import org.eclipse.passage.loc.workbench.LocWokbench;
import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages;

/**
* Creates new root licensing object. Can be asked for a reference to a created
Expand Down Expand Up @@ -62,18 +68,28 @@ protected InnerClassifierWizardPage<R> createNewClassifierPage() {
}

@Override
protected void store() {
store(newClassifierPage.container(), newClassifierPage.candidate());
protected ServiceInvocationResult<Boolean> store() {
return store(newClassifierPage.container(), newClassifierPage.candidate());
}

protected void store(Optional<R> container, EObject candidate) {
// FIXME: AF: rework to remove Optional
protected ServiceInvocationResult<Boolean> store(Optional<R> container, EObject candidate) {
if (!container.isPresent()) {
return;
return new BaseServiceInvocationResult<>(Boolean.FALSE);
}
EReference reference = containerEReference(candidate.eClass()).get();
candidate.eSet(reference, container.get());
Resource resource = candidate.eResource();
Optional.ofNullable(resource).ifPresent(LocWokbench::save);
if (resource == null) {
return new BaseServiceInvocationResult<>(Boolean.FALSE);
}
try {
resource.save(new HashMap<>());
return new BaseServiceInvocationResult<>(Boolean.TRUE);
} catch (IOException e) {
return new BaseServiceInvocationResult<>(
new Trouble(new ResourceSaveFailed(), WorkbenchMessages.InnerClassifierWizard_e_store, e));
}
}

private Optional<EReference> containerEReference(EClass eClass) {
Expand Down
Loading

0 comments on commit 6ff2803

Please sign in to comment.