Merge branch 'master' into simulator.
authorG S Senthil Kumar <senthil.gs@samsung.com>
Fri, 18 Dec 2015 10:21:44 +0000 (15:51 +0530)
committerG S Senthil Kumar <senthil.gs@samsung.com>
Fri, 18 Dec 2015 10:30:35 +0000 (16:00 +0530)
Change-Id: Ib0054018e0b27b9eb84ac8bb4dd7955c98ec731a
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
1  2 
service/simulator/java/eclipse-plugin/ClientControllerPlugin/.classpath
service/simulator/java/eclipse-plugin/ClientControllerPlugin/.project
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.classpath
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java

@@@ -1,8 -1,8 +1,11 @@@
  <?xml version="1.0" encoding="UTF-8"?>
  <classpath>
-     <classpathentry exported="true" kind="lib" path="libs/Simulator.jar"/>
-     <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-     <classpathentry kind="src" path="src"/>
-     <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
-     <classpathentry kind="output" path="bin"/>
 -      <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
 -      <classpathentry kind="src" path="src"/>
 -      <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 -      <classpathentry kind="lib" path="libs/Simulator.jar"/>
 -      <classpathentry kind="output" path="bin"/>
++    <classpathentry exported="true" kind="lib"
++        path="libs/Simulator.jar" />
++    <classpathentry kind="con"
++        path="org.eclipse.pde.core.requiredPlugins" />
++    <classpathentry kind="src" path="src" />
++    <classpathentry kind="con"
++        path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7" />
++    <classpathentry kind="output" path="bin" />
  </classpath>
@@@ -1,28 -1,28 +1,28 @@@
  <?xml version="1.0" encoding="UTF-8"?>
  <projectDescription>
--      <name>ClientControllerPlugin</name>
--      <comment></comment>
--      <projects>
--      </projects>
--      <buildSpec>
--              <buildCommand>
--                      <name>org.eclipse.jdt.core.javabuilder</name>
--                      <arguments>
--                      </arguments>
--              </buildCommand>
--              <buildCommand>
--                      <name>org.eclipse.pde.ManifestBuilder</name>
--                      <arguments>
--                      </arguments>
--              </buildCommand>
--              <buildCommand>
--                      <name>org.eclipse.pde.SchemaBuilder</name>
--                      <arguments>
--                      </arguments>
--              </buildCommand>
--      </buildSpec>
--      <natures>
--              <nature>org.eclipse.pde.PluginNature</nature>
--              <nature>org.eclipse.jdt.core.javanature</nature>
--      </natures>
++    <name>ClientControllerPlugin</name>
++    <comment></comment>
++    <projects>
++    </projects>
++    <buildSpec>
++        <buildCommand>
++            <name>org.eclipse.jdt.core.javabuilder</name>
++            <arguments>
++            </arguments>
++        </buildCommand>
++        <buildCommand>
++            <name>org.eclipse.pde.ManifestBuilder</name>
++            <arguments>
++            </arguments>
++        </buildCommand>
++        <buildCommand>
++            <name>org.eclipse.pde.SchemaBuilder</name>
++            <arguments>
++            </arguments>
++        </buildCommand>
++    </buildSpec>
++    <natures>
++        <nature>org.eclipse.pde.PluginNature</nature>
++        <nature>org.eclipse.jdt.core.javanature</nature>
++    </natures>
  </projectDescription>
@@@ -114,6 -144,6 +114,12 @@@ public class ResourceManager 
                              return;
                          }
  
++                        // Ignore the response if the resource is a device or platform.
++                        Vector<String> resTypes = resourceN.getResourceTypes();
++                        if(null != resTypes && resTypes.contains("oic.wk.d") || resTypes.contains("oic.wk.p")) {
++                            return;
++                        }
++
                          // If id is not available, then it cannot be added to
                          // the local map as null value should not be allowed as
                          // key.
                                                  + "].");
  
                          // Send an initial GET request to get the resource
--                        // attributes
++                        // attributes.
                          try {
                              resourceN.get(null, getListener);
                          } catch (SimulatorException e) {
@@@ -1,8 -1,8 +1,10 @@@
  <?xml version="1.0" encoding="UTF-8"?>
  <classpath>
-     <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
 -    <classpathentry kind="lib" path="libs/Simulator.jar"/>
 -    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
--    <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
--    <classpathentry kind="src" path="src"/>
-     <classpathentry kind="lib" path="libs/Simulator.jar"/>
--    <classpathentry kind="output" path="bin"/>
++    <classpathentry kind="con"
++        path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7" />
++    <classpathentry kind="con"
++        path="org.eclipse.pde.core.requiredPlugins" />
++    <classpathentry kind="src" path="src" />
++    <classpathentry kind="lib" path="libs/Simulator.jar" />
++    <classpathentry kind="output" path="bin" />
  </classpath>
@@@ -16,6 -16,6 +16,7 @@@
  
  package oic.simulator.serviceprovider.view.dialogs;
  
++import java.io.FileInputStream;
  import java.lang.reflect.InvocationTargetException;
  import java.net.URL;
  import java.util.Date;
@@@ -52,20 -53,22 +53,19 @@@ import org.oic.simulator.SimulatorResou
   */
  public class CreateResourceWizard extends Wizard {
  
 -    private MainPage                           mainPage;
 -    private SimpleResourceBasicDetailsPage     simpleResourceBasicDetailsPage;
 -    private SimpleResourceAddAttributePage     simpleResourceAddAttributePage;
 -    private SimpleResourceOtherDetailsPage     simpleResourceOtherDetailsPage;
 -    private CollectionResourceBasicDetailsPage collectionResourceBasicDetailsPage;
 -    private AddResourcesToCollectionPage       addResourcesToCollectionPage;
 -    private LoadRamlPage                       loadRamlPage;
 -    private UpdatePropertiesPage               updatePropPage;
 -    private DevicePage                         devicePage;
 -    private StartStopResourcePage              startStopPage;
 +    private MainPage                       mainPage;
 +    private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage;
 +    private SimpleResourceAddAttributePage simpleResourceAddAttributePage;
 +    private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage;
 +    private LoadRamlPage                   loadRamlPage;
 +    private UpdatePropertiesPage           updatePropPage;
-     private StartStopResourcePage          startStopPage;
  
 -    // private SingleResource simResource;
 -    private String                             status;
 +    private String                         status;
  
 -    private WizardDialog                       wizDialog;
 -    private boolean                            dlgForceClosed;
 +    private WizardDialog                   wizDialog;
 +    private boolean                        dlgForceClosed;
 +
 +    private Resource                       createdResource;
  
      public CreateResourceWizard() {
          setWindowTitle("Create resources");
          simpleResourceBasicDetailsPage = new SimpleResourceBasicDetailsPage();
          simpleResourceAddAttributePage = new SimpleResourceAddAttributePage();
          simpleResourceOtherDetailsPage = new SimpleResourceOtherDetailsPage();
 -        collectionResourceBasicDetailsPage = new CollectionResourceBasicDetailsPage();
 -        addResourcesToCollectionPage = new AddResourcesToCollectionPage();
          loadRamlPage = new LoadRamlPage();
          updatePropPage = new UpdatePropertiesPage();
 -        devicePage = new DevicePage();
--        startStopPage = new StartStopResourcePage();
  
          addPage(mainPage);
          addPage(simpleResourceBasicDetailsPage);
          addPage(simpleResourceAddAttributePage);
          addPage(simpleResourceOtherDetailsPage);
 -        addPage(collectionResourceBasicDetailsPage);
 -        if (Activator.getDefault().getResourceManager().isAnyResourceExist())
 -            addPage(addResourcesToCollectionPage);
          addPage(loadRamlPage);
          addPage(updatePropPage);
 -        addPage(devicePage);
--        addPage(startStopPage);
      }
  
      public void setWizardDialog(WizardDialog dlg) {
          return loadRamlPage.getResourceCount();
      }
  
 +    public Resource getCreatedResource() {
 +        return createdResource;
 +    }
 +
      @Override
      public boolean canFinish() {
 -        System.out.println("canFinish()");
          IWizardPage curPage = this.getContainer().getCurrentPage();
 -        System.out.println(curPage.getName());
 -        if ((curPage == updatePropPage && ((mainPage.getResourceOption() == ResourceOption.SIMPLE_FROM_RAML) || !Activator
 +        if ((curPage == updatePropPage && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
                  .getDefault().getResourceManager().isAnyResourceExist()))
 -                || (curPage == collectionResourceBasicDetailsPage
 -                        && !Activator.getDefault().getResourceManager()
 -                                .isAnyResourceExist() && collectionResourceBasicDetailsPage
 -                            .isSelectionDone())
 -                || curPage == addResourcesToCollectionPage
                  || curPage == simpleResourceAddAttributePage
                  || (curPage == loadRamlPage && loadRamlPage.isSelectionDone() && loadRamlPage
-                         .isMultiResourceCreation())) {
 -                        .isMultiResourceCreation()) || curPage == devicePage) {
++                .isMultiResourceCreation())) {
              return true;
          }
          return false;
                  });
              } catch (InvocationTargetException e) {
                  Activator.getDefault().getLogManager()
--                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++                .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
                  e.printStackTrace();
              } catch (InterruptedException e) {
                  Activator.getDefault().getLogManager()
--                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++                .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
                  e.printStackTrace();
              }
 -        } else if (curPage == loadRamlPage) { // Handling multi-instance
 -            // creation of simple resource
 -            // with RAML
 +        } else if (curPage == loadRamlPage) {
++            // Validate the file path.
+             try {
 -                getContainer().run(true, true, new IRunnableWithProgress() {
++                new FileInputStream(loadRamlPage.getConfigFilePath());
++            } catch (Exception e) {
++                MessageDialog
++                .openError(getShell(), "Invalid File",
++                        "File doesn't exist. Either the file path or file name is invalid.");
++                // TODO: Instead of MessageDialog, errors may be shown on wizard
++                // itself.
++                return false;
++            }
++
 +            // Handling multiple instance creation of simple resource with RAML
 +            if ((loadRamlPage.getResourceCount() + Activator.getDefault()
 +                    .getResourceManager().getResourceCount()) > Constants.MAX_RESOURCE_COUNT) {
 +                MessageDialog
-                         .openInformation(Display.getDefault().getActiveShell(),
-                                 "Resource limit exceeded",
-                                 "Exceeded the limit of resources that can exist in the server.");
++                .openInformation(Display.getDefault().getActiveShell(),
++                        "Resource limit exceeded",
++                        "Exceeded the limit of resources that can exist in the server.");
 +                return false;
 +            }
 +
 +            try {
 +                getContainer().run(true, false, new IRunnableWithProgress() {
  
                      @Override
                      public void run(IProgressMonitor monitor)
                  });
              } catch (InvocationTargetException e) {
                  Activator.getDefault().getLogManager()
--                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++                .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
                  e.printStackTrace();
              } catch (InterruptedException e) {
                  Activator.getDefault().getLogManager()
--                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++                .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
                  e.printStackTrace();
              }
 -        } else if (curPage == updatePropPage) { // Handling the single instance
 -            // creation of simple resource
 -            // with RAML
 -            // String resURI = updatePropPage.getResURI();
 -            // Checking whether the uri is used by any other resource.
 +        } else if (curPage == updatePropPage) {
 +            // Handling the single instance
 +            String resName = updatePropPage.getResName();
 +            String resURI = updatePropPage.getResURI();
 +            if (null == resName || resName.trim().length() < 1) {
 +                MessageDialog.openError(Display.getDefault().getActiveShell(),
 +                        "Invalid Resource Name.", "Resource name is invalid");
 +                return false;
 +            }
 +            if (!Utility.isUriValid(resURI)) {
 +                MessageDialog.openError(Display.getDefault().getActiveShell(),
 +                        "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
 +                return false;
 +            }
 +            // Creation of simple resource with RAML
 +            // Checking whether the URI is used by any other resource.
              if (Activator.getDefault().getResourceManager()
                      .isResourceExist(updatePropPage.getResURI())) {
                  MessageDialog
--                        .openError(getShell(), "Resource URI in use",
--                                "Entered resource URI is in use. Please try a different one.");
++                .openError(getShell(), "Resource URI in use",
++                        "Entered resource URI is in use. Please try a different one.");
                  // TODO: Instead of MessageDialog, errors may be shown on wizard
                  // itself.
                  return false;
                  });
              } catch (InvocationTargetException e) {
                  Activator.getDefault().getLogManager()
 -                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
 -                e.printStackTrace();
 -            } catch (InterruptedException e) {
 -                Activator.getDefault().getLogManager()
 -                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
 -                e.printStackTrace();
 -            }
 -        } else if (curPage == collectionResourceBasicDetailsPage
 -                || curPage == addResourcesToCollectionPage) { // Handling
 -            // Collection
 -            // Resource
 -            // Creation
 -            // without RAML
 -            if (mainPage.getResourceOption() == ResourceOption.COLLECTION_FROM_RAML) {
 -                Resource res = loadRamlPage.getResource();
 -                if (null != res && res instanceof CollectionResource) {
 -                    Set<Resource> selectedResources = addResourcesToCollectionPage
 -                            .getSelectedResourceList();
 -                    if (!selectedResources.isEmpty()) {
 -                        int addedCount = Activator
 -                                .getDefault()
 -                                .getResourceManager()
 -                                .addResourceToCollection(
 -                                        (CollectionResource) res,
 -                                        selectedResources);
 -                        if (addedCount > 0) {
 -
 -                            status = "[" + addedCount + "/"
 -                                    + selectedResources.size()
 -                                    + "] resources added to the collection";
 -
 -                            UiListenerHandler.getInstance()
 -                                    .resourceListUpdateUINotification(
 -                                            ResourceType.COLLECTION);
 -                        } else {
 -                            status = "Failed to add resources to the collection";
 -                        }
 -                    }
 -                }
 -            } else {
 -                // Checking whether the uri is used by any other resource.
 -                if (Activator
 -                        .getDefault()
 -                        .getResourceManager()
 -                        .isResourceExist(
 -                                collectionResourceBasicDetailsPage.getResURI())) {
 -                    MessageDialog
 -                            .openError(getShell(), "Resource URI in use",
 -                                    "Entered resource URI is in use. Please try a different one.");
 -                    // TODO: Instead of MessageDialog, errors may be shown on
 -                    // wizard
 -                    // itself.
 -                    return false;
 -                }
 -                try {
 -                    getContainer().run(true, true, new IRunnableWithProgress() {
 -
 -                        @Override
 -                        public void run(IProgressMonitor monitor)
 -                                throws InvocationTargetException,
 -                                InterruptedException {
 -                            try {
 -                                monitor.beginTask(
 -                                        "Collection Resource Creation Without RAML",
 -                                        3);
 -                                monitor.worked(1);
 -                                createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true
 -                                        : false);
 -                                monitor.worked(1);
 -                                if (curPage == addResourcesToCollectionPage) {
 -                                    UiListenerHandler.getInstance()
 -                                            .resourceListUpdateUINotification(
 -                                                    ResourceType.COLLECTION);
 -                                }
 -                                monitor.worked(1);
 -                            } finally {
 -                                monitor.done();
 -                            }
 -                        }
 -                    });
 -                } catch (InvocationTargetException e) {
 -                    Activator
 -                            .getDefault()
 -                            .getLogManager()
 -                            .log(Level.ERROR.ordinal(), new Date(),
 -                                    e.getMessage());
 -                    e.printStackTrace();
 -                } catch (InterruptedException e) {
 -                    Activator
 -                            .getDefault()
 -                            .getLogManager()
 -                            .log(Level.ERROR.ordinal(), new Date(),
 -                                    e.getMessage());
 -                    e.printStackTrace();
 -                }
 -            }
 -        } else if (curPage == devicePage) {
 -            final String devName = devicePage.getDeviceName();
 -            final Set<Resource> resourceList = devicePage
 -                    .getSelectedResourceList();
 -            try {
 -                getContainer().run(true, true, new IRunnableWithProgress() {
 -
 -                    @Override
 -                    public void run(IProgressMonitor monitor)
 -                            throws InvocationTargetException,
 -                            InterruptedException {
 -                        try {
 -                            monitor.beginTask("Device Creation", 3);
 -                            monitor.worked(1);
 -                            createDevice(devName, resourceList);
 -                            monitor.worked(1);
 -                            UiListenerHandler.getInstance()
 -                                    .resourceListUpdateUINotification(
 -                                            ResourceType.DEVICE);
 -                            status = "Device Created.";
 -                            monitor.worked(1);
 -                        } finally {
 -                            monitor.done();
 -                        }
 -                    }
 -                });
 -            } catch (InvocationTargetException e) {
 -                Activator.getDefault().getLogManager()
--                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++                .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
                  e.printStackTrace();
              } catch (InterruptedException e) {
                  Activator.getDefault().getLogManager()
--                        .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
++                .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
                  e.printStackTrace();
              }
          }
          return updatePropPage;
      }
  
 -    public DevicePage getDevicePage() {
 -        return devicePage;
 -    }
 -
--    public StartStopResourcePage getStartStopPage() {
--        return startStopPage;
--    }
 -
 -    /*
 -     * public SingleResource getSimResource() { return simResource; }
 -     * 
 -     * public void setSimResource(SingleResource simResource) { this.simResource
 -     * = simResource; }
 -     */
--
      public void setStatus(String status) {
          this.status = status;
      }
diff --cc service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java
index a56bc8a,4f2a3c8..0000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,105 -1,90 +1,0 @@@
- /*
-  * Copyright 2015 Samsung Electronics All Rights Reserved.
-  *
-  * Licensed under the Apache License, Version 2.0 (the "License");
-  * you may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at
-  *
-  *      http://www.apache.org/licenses/LICENSE-2.0
-  *
-  * Unless required by applicable law or agreed to in writing, software
-  * distributed under the License is distributed on an "AS IS" BASIS,
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  */
--package oic.simulator.serviceprovider.view.dialogs;
--
--import oic.simulator.serviceprovider.utils.Constants;
--
--import org.eclipse.jface.wizard.IWizardPage;
--import org.eclipse.jface.wizard.WizardPage;
--import org.eclipse.swt.SWT;
--import org.eclipse.swt.events.SelectionAdapter;
--import org.eclipse.swt.events.SelectionEvent;
--import org.eclipse.swt.layout.GridData;
--import org.eclipse.swt.layout.GridLayout;
--import org.eclipse.swt.widgets.Button;
--import org.eclipse.swt.widgets.Composite;
--import org.eclipse.swt.widgets.Label;
--import org.eclipse.swt.widgets.Text;
--
--public class StartStopResourcePage extends WizardPage {
--
--    private Button  startButton;
--
--    private boolean start;
--
--    protected StartStopResourcePage() {
--        super("Start/Stop Resource");
--        setStart(true);
--    }
--
--    @Override
--    public void createControl(Composite parent) {
--        setPageComplete(false);
--        setTitle(Constants.START_STOP_PAGE_TITLE);
--        setMessage(Constants.START_STOP_PAGE_MESSAGE);
--        Composite compContent = new Composite(parent, SWT.NONE);
--        GridLayout gridLayout = new GridLayout();
--        compContent.setLayout(gridLayout);
--        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
--        compContent.setLayoutData(gd);
--
--        startButton = new Button(compContent, SWT.CHECK);
--        startButton.setText("Start Resource(s)");
--        startButton.setSelection(true);
--        gd = new GridData();
--        gd.verticalIndent = 10;
--        startButton.setLayoutData(gd);
--
--        Label descLbl = new Label(compContent, SWT.NONE);
--        descLbl.setText("Description:");
--        gd = new GridData();
--        gd.verticalIndent = 50;
--        descLbl.setLayoutData(gd);
--
--        final Text text = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
--                | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
--        text.setText("Starting the resource will register it with the platform and makes it visible on the network.\n"
--                + "Resources can be started or stopped later from 'Resource Manager' view.");
--        gd = new GridData();
--        gd.horizontalAlignment = SWT.FILL;
--        gd.grabExcessHorizontalSpace = true;
--        gd.heightHint = 100;
--        gd.verticalAlignment = SWT.BOTTOM;
--        text.setLayoutData(gd);
--
--        addUIListeners();
--
--        setControl(compContent);
--    }
--
--    private void addUIListeners() {
--        startButton.addSelectionListener(new SelectionAdapter() {
--            @Override
--            public void widgetSelected(SelectionEvent e) {
--                setStart(startButton.getSelection());
--            }
--        });
--    }
--
--    public boolean isStart() {
--        return start;
--    }
--
--    public void setStart(boolean start) {
--        this.start = start;
--    }
--
--    @Override
--    public IWizardPage getNextPage() {
 -        System.out.println(this.getClass().getName() + ": getNextPage");
--        return null;
--    }
--}