import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.operations.ProvisioningJob;
-import org.eclipse.equinox.p2.operations.ProvisioningSession;
-import org.eclipse.equinox.p2.operations.Update;
-import org.eclipse.equinox.p2.operations.UpdateOperation;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.IRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
}
PreferencesUtil.setP2Repositories(repoElements);
}
-
- /**
- *
- *
- */
- public static void checkForUpdates() {
-
- Job updateJob = new Job("Update Job") {
- @Override
- public IStatus run(IProgressMonitor monitor) {
- return doCheckForUpdates(monitor);
- }
- };
- updateJob.schedule();
- }
-
- /**
- * @param monitor
- * @return
- */
- private static IStatus doCheckForUpdates(IProgressMonitor monitor) {
-
- // force refresh all the caches before
- IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
- URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
- for(URI repo : repos) {
- try {
- metaManager.refreshRepository(repo, monitor);
- } catch (ProvisionException pe) {
- IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
- "Error occured while reloading cache.", pe);
-
- } catch (OperationCanceledException oce) {
- IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
- "Error occured while reloading cache.", oce);
- }
- }
- BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
- ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
- if (reference == null) {
- IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
- "No provisioning agent found. This application is not set up for updates.");
- return errorStatus;
- }
-
- final IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
- IStatus updateStatus;
- try {
- updateStatus = P2Util.checkForUpdates(agent, monitor);
- MessagingUtils.info(updateStatus);
- } finally {
- bundleContext.ungetService(reference);
- }
- return updateStatus;
- }
-
- /**
- * @param agent
- * @param monitor
- * @return
- * @throws OperationCanceledException
- */
- static IStatus checkForUpdates(IProvisioningAgent agent, final IProgressMonitor monitor) {
- ProvisioningSession session = new ProvisioningSession(agent);
- // the default update operation looks for updates to the currently
- // running profile, using the default profile root marker. To change
- // which installable units are being updated, use the more detailed
- // constructors.
- final UpdateOperation operation = new UpdateOperation(session);
-// try {
-// setUpdateRepositories(operation);
-// } catch (URISyntaxException e) {
-// MessagingUtils.errorDialog("Invalid update site URI",
-// operation,
-// "The update site URI has an invalid syntax",
-// TaxonomicEditorPlugin.PLUGIN_ID,
-// e,
-// false);
-// return null;
-// }
-
- final IStatus status = operation.resolveModal(monitor);
-
- if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
- return status;
- }
-
- if (status.isOK() && status.getSeverity() != IStatus.ERROR) {
- // We need this block of code to be in async execution
- // since the confirm dialogs work only on the UI thread
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- String updates = "";
- Update[] possibleUpdates = operation
- .getPossibleUpdates();
- for (Update update : possibleUpdates) {
- updates += update + "\n";
- }
-
- boolean doInstall = MessagingUtils.confirmDialog("Updates available", "Do you want to install the available updates ?");
- // We may need to think whether we still run in async mode once
- // the user agrees to update. Maybe be reasonable to change to blocking
- // from this point until the update is complete.
-
- // More complex status handling might include showing the user what
- // updates are available if there are multiples, differentiating
- // patches vs. updates, etc. In this example, we simply update as
- // suggested by the operation.
- if(doInstall) {
- ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
- if (provisioningJob == null) {
- MessagingUtils.messageDialog("Error in performing update",
- operation,
- "ProvisioningJob could not be created." + System.getProperty("line.separator") +
- "Either this application does not support p2 software installation or this application has been launched from within the Eclipse IDE",
- null,
- false);
-
- } else {
- // register a job change listener to track
- // installation progress and notify user upon success
- provisioningJob
- .addJobChangeListener(new JobChangeAdapter() {
- @Override
- public void done(IJobChangeEvent event) {
- if (event.getResult().isOK()) {
- // We need this block of code to be in async execution
- // since the confirm dialogs work only on the UI thread
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- boolean restart = MessagingUtils.confirmDialog(
- "Updates installed, restart?",
- "Updates have been installed successfully, do you want to restart?");
- if (restart) {
- PlatformUI.getWorkbench().restart();
- }
- }
- });
- }
- super.done(event);
- }
- });
- provisioningJob.schedule();
- }
- }
- }
- });
- }
- return status;
- }
}
*******************************************************************************/
package eu.etaxonomy.taxeditor.update;
+import java.net.URI;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
-import org.eclipse.equinox.p2.operations.RepositoryTracker;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.operations.UpdateOperation;
+import org.eclipse.equinox.p2.repository.IRepositoryManager;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.wizard.WizardDialog;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
/**
* UpdateHandler invokes the check for updates UI
*/
public class UpdateHandler extends PreloadingRepositoryHandler {
- boolean hasNoRepos = false;
- @Override
+ @Override
protected void doExecute(LoadMetadataRepositoryJob job) {
- if (hasNoRepos) {
- return;
- }
- UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null);
-
-
- // check for updates
- operation.resolveModal(null);
- if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
- if (UpdateSingleIUWizard.validFor(operation)) {
- // Special case for only updating a single root
- UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
- WizardDialog dialog = new WizardDialog(getShell(), wizard);
- dialog.create();
- dialog.open();
- } else {
- // Open the normal version of the update wizard
- getProvisioningUI().openUpdateWizard(false, operation, job);
- }
- }
- }
-
- @Override
- protected boolean preloadRepositories() {
- hasNoRepos = false;
- RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
- if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
- hasNoRepos = true;
- return false;
- }
- return super.preloadRepositories();
- }
+
+ UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
+
+ // check for updates
+ checkForUpdates(operation);
+ if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
+ if (UpdateSingleIUWizard.validFor(operation)) {
+ // Special case for only updating a single root
+ UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
+ WizardDialog dialog = new WizardDialog(getShell(), wizard);
+ dialog.create();
+ dialog.open();
+ } else {
+ // Open the normal version of the update wizard
+ getProvisioningUI().openUpdateWizard(false, operation, job);
+ }
+ }
+ }
+
+
+ /**
+ * @param monitor
+ * @return
+ */
+ private IStatus checkForUpdates(UpdateOperation operation) {
+
+ // force refresh all the caches before
+ IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
+ URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
+ for(URI repo : repos) {
+ try {
+ metaManager.refreshRepository(repo, null);
+ } catch (ProvisionException pe) {
+ IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
+ "Error occured while reloading cache.", pe);
+
+ } catch (OperationCanceledException oce) {
+ IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
+ "Error occured while reloading cache.", oce);
+ }
+ }
+ BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
+ ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
+ if (reference == null) {
+ IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
+ "No provisioning agent found. This application is not set up for updates.");
+ return errorStatus;
+ }
+
+ try {
+ return operation.resolveModal(null);
+ } finally {
+ bundleContext.ungetService(reference);
+ }
+ }
+
}
public boolean merge(T entity, T mergeTarget) {
if (entity instanceof IMergable) {
try {
- CdmStore.getCommonService().merge(mergeTarget.getId(), entity.getId(), (Class<? extends CdmBase>)entity.getClass());
+ CdmStore.getCommonService().merge(mergeTarget.getUuid(), entity.getUuid(), (Class<? extends CdmBase>)entity.getClass());
} catch (MergeException e) {
MessagingUtils.errorDialog("Bulk Editor Merge Error",
this,
if(entity instanceof Person && mergeTarget instanceof Person) {
IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(Person.class);
strategy.setMergeMode("institutionalMemberships", MergeMode.FIRST);
- CdmStore.getCommonService().merge(mergeTarget.getId(), entity.getId(), Person.class);
+ CdmStore.getCommonService().merge(mergeTarget.getUuid(), entity.getUuid(), Person.class);
} else {
IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(TeamOrPersonBase.class);
- CdmStore.getCommonService().merge(mergeTarget.getId(), entity.getId(), TeamOrPersonBase.class);
+ CdmStore.getCommonService().merge(mergeTarget.getUuid(), entity.getUuid(), TeamOrPersonBase.class);
}
} catch (MergeException e) {
MessagingUtils.errorDialog("Bulk Editor Merge Error",
private ICdmEntitySession cdmEntitySession;
public ReferencingObjectsView() {
- cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+ cdmEntitySession = CdmStore.getCurrentSessionManager().bindNullSession();
}
/* (non-Javadoc)
import org.springframework.beans.BeansException;\r
import org.springframework.context.ApplicationContext;\r
import org.springframework.context.ApplicationContextAware;\r
+import org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor;\r
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;\r
import org.springframework.security.access.AccessDecisionVoter;\r
import org.springframework.security.authentication.AuthenticationProvider;\r
import eu.etaxonomy.cdm.api.service.IIdentificationKeyService;\r
import eu.etaxonomy.cdm.api.service.ILocationService;\r
import eu.etaxonomy.cdm.api.service.IMediaService;\r
+import eu.etaxonomy.cdm.api.service.IMetadataService;\r
import eu.etaxonomy.cdm.api.service.INameService;\r
import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;\r
\r
public CdmApplicationRemoteConfiguration(ICdmRemoteSource remoteSource) {\r
this.remoteSource = remoteSource;\r
+\r
}\r
\r
public void setRemoteSource(ICdmRemoteSource remoteSource) {\r
this.remoteSource = remoteSource;\r
}\r
\r
- private Object getService(Class<?> clazz, String serviceSuffix, CdmAuthenticatedHttpInvokerRequestExecutor executor) {\r
+ private Object getService(Class<?> clazz, String serviceSuffix, CommonsHttpInvokerRequestExecutor executor) {\r
if(serviceMap.containsKey(clazz)) {\r
return serviceMap.get(clazz);\r
}\r
+ Object service = getService(clazz, serviceSuffix, remoteSource, executor);\r
+ serviceMap.put(clazz, service);\r
+ return service;\r
+ }\r
+\r
+ public static Object getService(Class<?> clazz,\r
+ String serviceSuffix,\r
+ ICdmRemoteSource remoteSource,\r
+ CommonsHttpInvokerRequestExecutor executor) {\r
+\r
String baseUrl;\r
if(remoteSource.getContextPath() == null || remoteSource.getContextPath().equals("")) {\r
baseUrl = "http://" + remoteSource.getServer() + ":" + String.valueOf(remoteSource.getPort());\r
proxy.setHttpInvokerRequestExecutor(executor);\r
}\r
proxy.afterPropertiesSet();\r
- Object service = proxy.getObject();\r
- serviceMap.put(clazz, service);\r
- return service;\r
+ return proxy.getObject();\r
}\r
\r
// ****************************** APPLICATION CONTEXT *************************************************/\r
return (IUserService) getService(IUserService.class, "/remoting-public/user.service", new CdmServiceRequestExecutor());\r
}\r
\r
+ @Override\r
+ public IMetadataService getMetadataService() {\r
+ return (IMetadataService) getService(IMetadataService.class, "/remoting-public/metadata.service", new CommonsHttpInvokerRequestExecutor());\r
+ }\r
+\r
+ public static IMetadataService getMetadataService(ICdmRemoteSource remoteSource) {\r
+ return (IMetadataService) getService(IMetadataService.class, "/remoting-public/metadata.service", remoteSource, new CommonsHttpInvokerRequestExecutor());\r
+ }\r
+\r
@Override\r
public IGrantedAuthorityService getGrantedAuthorityService(){\r
return (IGrantedAuthorityService) getService(IGrantedAuthorityService.class, "/remoting/grantedauthority.service", new CdmServiceRequestExecutor());\r
} else {
throw new CdmRemoteSourceException("Remote source '" + remoteSource + "' does not exist in settings file");
}
- initDatabaseConnection();
}
private static void checkProperties(Properties cdmSourceProperties) throws CdmRemoteSourceException {
import java.util.Map;
-import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
-
-import eu.etaxonomy.cdm.api.service.IUserService;
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
+import eu.etaxonomy.cdm.api.service.IMetadataService;
import eu.etaxonomy.cdm.config.CdmSource;
import eu.etaxonomy.cdm.config.CdmSourceException;
import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;
private String contextPath;
private String baseUrl;
- private IUserService userService;
+ private IMetadataService metadataService;
/**
* Constructs a CdmRemoteSourceBase object with default values.
setPort(port);
setContextPath(contextPath);
setNomenclaturalCode(nomenclaturalCode);
- initDatabaseConnection();
+ metadataService = CdmApplicationRemoteConfiguration.getMetadataService(this);
}
- protected void initDatabaseConnection() {
- if(getContextPath() == null || getContextPath().equals("")) {
- setBaseUrl("http://" + getServer() + ":" + String.valueOf(getPort()));
- } else {
- setBaseUrl("http://" + getServer() + ":" + String.valueOf(getPort()) + "/" + getContextPath());
- }
- // the database service needs to be initialised (before the spring
- // application context initialsation) since it is required to
- // to make queries related to the source database
- HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
- proxy.setServiceInterface(IUserService.class);
- // FIXME:Remoting need to fix this hardcoded url and make it configurable somehow
- proxy.setServiceUrl(baseUrl + "/remoting-public/user.service");
- proxy.afterPropertiesSet();
- userService = (IUserService) proxy.getObject();
-
- }
/* (non-Javadoc)
* @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
*/
@Override
public String getDbSchemaVersion() throws CdmSourceException {
- return userService.getDbSchemaVersion();
+ return metadataService.getDbSchemaVersion();
}
*/
@Override
public boolean isDbEmpty() throws CdmSourceException {
- return userService.isDbEmpty();
+ return metadataService.isDbEmpty();
}
// if no exception is thrown then we assume that the
// connection is up
// FIXME:Remoting is this really correct?
- userService.getDbSchemaVersion();
+ metadataService.getDbSchemaVersion();
return true;
}
@Override
public Map<MetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
- return userService.getCdmMetadataMap();
+ return metadataService.getCdmMetadataMap();
}
*/
@Override
public List<String> getPropertyPaths(Object obj) {
+ if(sessionOwner == null) {
+ return null;
+ }
Map<Object, List<String>> propertyPathsMap = sessionOwner.getPropertyPathsMap();
if(propertyPathsMap == null || propertyPathsMap.isEmpty()) {
return null;
import eu.etaxonomy.cdm.api.service.IIdentificationKeyService;
import eu.etaxonomy.cdm.api.service.ILocationService;
import eu.etaxonomy.cdm.api.service.IMediaService;
+import eu.etaxonomy.cdm.api.service.IMetadataService;
import eu.etaxonomy.cdm.api.service.INameService;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
public IProgressMonitorService getProgressMonitorService() {
return defaultApplicationConfiguration.getProgressMonitorService();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IMetadataService getMetadataService() {
+ return defaultApplicationConfiguration.getMetadataService();
+ }
}
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
/** {@inheritDoc} */
@Override
public DescriptionElementSource createNewElement() {
- /* if(getEntity().getId() == 0) {
- MessagingUtils.warningDialog("Description not saved", this, "Please save the newly created description before adding source");
- return null;
- }*/
return DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
}
contextPath,
NomenclaturalCode.ICNAFP);
try {
- inactiveCrs.getDbSchemaVersion();
+ String dbSchemaVersion = inactiveCrs.getDbSchemaVersion();
Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException");
} catch(CdmSourceException cse) {
Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
}
- @Test
- public void whenConnectingToAnActiveServerWithServicesBlockedThenFailToAccessServices() {
-
- }
-
@Test
public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
// check if active server throws the right exception