[Simulator] Minor UI changes fixing the IOT-1087.
authorG S Senthil Kumar <senthil.gs@samsung.com>
Thu, 12 May 2016 06:49:52 +0000 (12:19 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 12 May 2016 14:01:47 +0000 (14:01 +0000)
1. Added UI support to allow the resource type property to be editable
during resource creation from RAML.
2. Added a new dialog to edit the resource name and resource type during
the creation of multiple resource instances from RAML.
3. Removed the native code which forms rt when it is not specified
in RAML. For this case, plugin will pop-up the above mentioned dialog to
get the resource type from user.

Change-Id: I9a7c927fc63e3ff22db62ae07ce23e63ec8e05d8
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8115
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Harish Marappa <h.marappa@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java
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/LoadRamlPage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/ResourceWizardDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateMultiInstanceCreationPropertiesPage.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java
service/simulator/src/server/simulator_resource_factory.cpp

index 44fc3ee..c3e0604 100644 (file)
@@ -657,19 +657,26 @@ public class ResourceManager {
         Resource resource = new SingleResource();
         resource.setSimulatorResource(jSimulatorResource);
 
-        // Fetch and locally store the resource name and uri.
+        // Fetch and locally store the resource name, type and uri.
         String uri = jSimulatorResource.getURI();
         if (null == uri || uri.trim().isEmpty()) {
+            // URI is mandatory to be present in RAML. If it is not there, then
+            // resource can't be created.
             return null;
         }
         resource.setResourceURI(uri.trim());
 
-        String name = jSimulatorResource.getName();
-        if (null == name || name.trim().isEmpty()) {
-            return null;
+        String type = jSimulatorResource.getResourceType();
+        if (null != type) {
+            type = type.trim();
         }
+        resource.setResourceType(type);
 
-        resource.setResourceName(name.trim());
+        String name = jSimulatorResource.getName();
+        if (null != name) {
+            name = name.trim();
+        }
+        resource.setResourceName(name);
 
         return resource;
     }
@@ -682,7 +689,7 @@ public class ResourceManager {
      * notifies the UI listeners.
      */
     public boolean completeSingleResourceCreationByRAML(Resource resource,
-            String uri, String name, boolean multiInstance)
+            String uri, String name, String type, boolean multiInstance)
             throws SimulatorException {
         if (null == resource || !(resource instanceof SingleResource)) {
             return false;
@@ -697,21 +704,30 @@ public class ResourceManager {
             }
 
             // Update resource URI and Name if they are changed.
-            String newUri = uri.trim();
-            String newName = name.trim();
-
-            if (multiInstance) {
+            String newUri = "";
+            String newName = "";
+            String newType = "";
+
+            if (null != uri)
+                newUri = uri.trim();
+            if (null != name)
+                newName = name.trim();
+            if (null != type)
+                newType = type.trim();
+
+            if (!multiInstance && !singleRes.getResourceURI().equals(newUri)) {
+                jSimulatorSingleResource.setURI(newUri);
                 singleRes.setResourceURI(newUri);
+            }
+            String currentName = singleRes.getResourceName();
+            if (null == currentName || !currentName.equals(newName)) {
+                jSimulatorSingleResource.setName(newName);
                 singleRes.setResourceName(newName);
-            } else {
-                if (!singleRes.getResourceURI().equals(newUri)) {
-                    jSimulatorSingleResource.setURI(newUri);
-                    singleRes.setResourceURI(newUri);
-                }
-                if (!singleRes.getResourceName().equals(newName)) {
-                    jSimulatorSingleResource.setName(newName);
-                    singleRes.setResourceName(newName);
-                }
+            }
+            String currentType = singleRes.getResourceType();
+            if (null == currentType || !currentType.equals(newType)) {
+                jSimulatorSingleResource.setResourceType(newType);
+                singleRes.setResourceType(newType);
             }
 
             // Set the model change listener.
@@ -733,8 +749,6 @@ public class ResourceManager {
             singleRes.setResourceModel(jResModel);
 
             // Fetch the basic details of the resource.
-            singleRes.setResourceType(jSimulatorSingleResource
-                    .getResourceType());
             singleRes
                     .setResourceInterfaces(Utility
                             .convertVectorToSet(jSimulatorSingleResource
@@ -785,7 +799,6 @@ public class ResourceManager {
             }
             SimulatorSingleResource jResource;
             SingleResource resource;
-            boolean result;
             for (SimulatorResource jSimulatorResource : jSimulatorResources) {
                 // If the resource creation progress is canceled, then stop the
                 // creation and stop/delete
@@ -798,11 +811,27 @@ public class ResourceManager {
                 resource = new SingleResource();
                 resource.setSimulatorResource(jResource);
                 try {
-                    result = completeSingleResourceCreationByRAML(resource,
-                            jResource.getURI(), jResource.getName(), true);
-                    if (result) {
-                        resultSet.add(resource);
+                    String uri = jSimulatorResource.getURI();
+                    if (null == uri || uri.trim().isEmpty()) {
+                        // URI is mandatory to be present in RAML. If it is not
+                        // there, then resource will be ignored.
+                        continue;
+                    }
+                    resource.setResourceURI(uri.trim());
+
+                    String type = jSimulatorResource.getResourceType();
+                    if (null != type) {
+                        type = type.trim();
                     }
+                    resource.setResourceType(type);
+
+                    String name = jSimulatorResource.getName();
+                    if (null != name) {
+                        name = name.trim();
+                    }
+                    resource.setResourceName(name);
+
+                    resultSet.add(resource);
                 } catch (SimulatorException eInner) {
                     Activator
                             .getDefault()
index ecbec24..225a340 100644 (file)
@@ -429,7 +429,7 @@ public class ResourceManagerView extends ViewPart {
                                         .getDefault()
                                         .getLogManager()
                                         .log(Level.ERROR.ordinal(), new Date(),
-                                                "There is an error while creating the wizard.\n");
+                                                "There is an error while reading information from the UI wizard.\n");
                                 return;
                             }
 
index f45afec..88f50fd 100644 (file)
@@ -28,9 +28,6 @@ import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.widgets.Display;
 
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.util.Date;
@@ -58,21 +55,21 @@ import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
  */
 public class CreateResourceWizard extends Wizard {
 
-    private MainPage                       mainPage;
-    private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage;
-    private SimpleResourceAddAttributePage simpleResourceAddAttributePage;
-    private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage;
-    private LoadRamlPage                   loadRamlPage;
-    private UpdatePropertiesPage           updatePropPage;
+    private MainPage                                  mainPage;
+    private SimpleResourceBasicDetailsPage            simpleResourceBasicDetailsPage;
+    private SimpleResourceAddAttributePage            simpleResourceAddAttributePage;
+    private SimpleResourceOtherDetailsPage            simpleResourceOtherDetailsPage;
+    private LoadRamlPage                              loadRamlPage;
+    private UpdatePropertiesPage                      updatePropPage;
+    private UpdateMultiInstanceCreationPropertiesPage updateMultiInstanceCreationPropPage;
 
-    private String                         status;
+    private String                                    status;
 
-    private WizardDialog                   wizDialog;
-    private boolean                        dlgForceClosed;
+    private WizardDialog                              wizDialog;
+    private boolean                                   dlgForceClosed;
 
-    private Resource                       createdResource;
-
-    private IProgressMonitor               progressMonitor;
+    private Resource                                  createdResource;
+    private Set<SingleResource>                       multiInstanceResourceSet;
 
     public CreateResourceWizard() {
         setWindowTitle("Create resources");
@@ -92,6 +89,7 @@ public class CreateResourceWizard extends Wizard {
         simpleResourceOtherDetailsPage = new SimpleResourceOtherDetailsPage();
         loadRamlPage = new LoadRamlPage();
         updatePropPage = new UpdatePropertiesPage();
+        updateMultiInstanceCreationPropPage = new UpdateMultiInstanceCreationPropertiesPage();
 
         addPage(mainPage);
         addPage(simpleResourceBasicDetailsPage);
@@ -99,6 +97,7 @@ public class CreateResourceWizard extends Wizard {
         addPage(simpleResourceOtherDetailsPage);
         addPage(loadRamlPage);
         addPage(updatePropPage);
+        addPage(updateMultiInstanceCreationPropPage);
     }
 
     public void setWizardDialog(WizardDialog dlg) {
@@ -135,14 +134,17 @@ public class CreateResourceWizard extends Wizard {
         return createdResource;
     }
 
+    public Set<SingleResource> getCreatedMultiInstanceResourceSet() {
+        return multiInstanceResourceSet;
+    }
+
     @Override
     public boolean canFinish() {
         IWizardPage curPage = this.getContainer().getCurrentPage();
-        if ((curPage == updatePropPage && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
-                .getDefault().getResourceManager().isAnyResourceExist()))
-                || curPage == simpleResourceAddAttributePage
-                || (curPage == loadRamlPage && loadRamlPage.isSelectionDone() && loadRamlPage
-                        .isMultiResourceCreation())) {
+        if ((curPage == updateMultiInstanceCreationPropPage || curPage == updatePropPage
+                && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
+                        .getDefault().getResourceManager().isAnyResourceExist()))
+                || curPage == simpleResourceAddAttributePage) {
             return true;
         }
         return false;
@@ -179,107 +181,58 @@ public class CreateResourceWizard extends Wizard {
                         .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
                 e.printStackTrace();
             }
-        } else if (curPage == loadRamlPage) {
-            // Validate the file path.
-            FileInputStream fileStream = null;
-            try {
-                fileStream = new FileInputStream(
-                        loadRamlPage.getConfigFilePath());
-            } catch (FileNotFoundException e) {
-                MessageDialog
-                        .openError(getShell(), "Invalid File",
-                                "File doesn't exist. Either the file path or file name is invalid.");
-                return false;
-            } finally {
-                if (null != fileStream) {
-                    try {
-                        fileStream.close();
-                    } catch (IOException e) {
-                        Activator
-                                .getDefault()
-                                .getLogManager()
-                                .log(Level.ERROR.ordinal(), new Date(),
-                                        "There is an error while closing the file stream.\n");
-                    }
-                }
-            }
-
-            // 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",
-                        Constants.RESOURCE_LIMIT_EXCEEDED_MSG);
-                return false;
-            }
-
-            final int[] resCreatedCount = new int[1];
-            try {
-                getContainer().run(true, true, new IRunnableWithProgress() {
-
-                    @Override
-                    public void run(final IProgressMonitor monitor)
-                            throws InvocationTargetException,
-                            InterruptedException {
-                        progressMonitor = monitor;
-                        try {
-                            monitor.beginTask(
-                                    "Single Resource Creation(multi-instance) With RAML",
-                                    loadRamlPage.getResourceCount());
-                            resCreatedCount[0] = createMultiInstanceSingleResourceWithoutRAML();
-
-                        } 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();
-            }
-            boolean canceled = false;
-            if (null != progressMonitor && progressMonitor.isCanceled()
-                    && 0 == resCreatedCount[0]) {
-                canceled = true;
-            }
-            progressMonitor = null;
-            if (canceled) {
-                return false;
+        } else if (curPage == updatePropPage
+                || curPage == updateMultiInstanceCreationPropPage) {
+            multiInstanceResourceSet = loadRamlPage
+                    .getMultiInstanceResourceSet();
+            createdResource = loadRamlPage.getResource();
+
+            String resName;
+            String resURI;
+            String resType;
+            boolean multiInstanceCreation = loadRamlPage
+                    .isMultiResourceCreation();
+
+            if (curPage == updatePropPage) {
+                resName = updatePropPage.getResName();
+                resURI = updatePropPage.getResURI();
+                resType = updatePropPage.getResType();
             } else {
-                if (resCreatedCount[0] > 0) {
-                    UiListenerHandler.getInstance()
-                            .resourceCreatedUINotification(ResourceType.SINGLE);
-                }
+                resName = updateMultiInstanceCreationPropPage.getResName();
+                resURI = "";
+                resType = updateMultiInstanceCreationPropPage.getResType();
             }
-        } 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)) {
+
+            if (!multiInstanceCreation && !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())) {
+            if (!multiInstanceCreation
+                    && Activator.getDefault().getResourceManager()
+                            .isResourceExist(resURI)) {
                 MessageDialog
                         .openError(getShell(), "Resource URI in use",
                                 "Entered resource URI is in use. Please try a different one.");
                 return false;
             }
 
+            if (!Utility.isResourceTypeValid(resType)) {
+                MessageDialog.openError(Display.getDefault().getActiveShell(),
+                        "Invalid Resource Type.",
+                        Constants.INVALID_RESOURCE_TYPE_MESSAGE);
+                return false;
+            }
+
             try {
                 getContainer().run(true, false, new IRunnableWithProgress() {
 
@@ -290,7 +243,11 @@ public class CreateResourceWizard extends Wizard {
                         try {
                             monitor.beginTask("Completing Resource Creation", 2);
                             monitor.worked(1);
-                            completeResourceCreationWithRAML();
+                            if (loadRamlPage.isMultiResourceCreation()) {
+                                completeMultiInstanceResourceCreationWithRAML();
+                            } else {
+                                completeSingleInstanceResourceCreationWithRAML();
+                            }
                             monitor.worked(1);
                         } finally {
                             monitor.done();
@@ -334,6 +291,15 @@ public class CreateResourceWizard extends Wizard {
         return updatePropPage;
     }
 
+    public UpdateMultiInstanceCreationPropertiesPage getUpdateMultiInstanceCreationPropPage() {
+        return updateMultiInstanceCreationPropPage;
+    }
+
+    public void setUpdateMultiInstanceCreationPropPage(
+            UpdateMultiInstanceCreationPropertiesPage updateMultiInstanceCreationPropPage) {
+        this.updateMultiInstanceCreationPropPage = updateMultiInstanceCreationPropPage;
+    }
+
     public void setStatus(String status) {
         this.status = status;
     }
@@ -395,22 +361,23 @@ public class CreateResourceWizard extends Wizard {
         }
     }
 
-    private void completeResourceCreationWithRAML() {
+    private void completeSingleInstanceResourceCreationWithRAML() {
+        String resName = updatePropPage.getResName();
+        String resURI = updatePropPage.getResURI();
+        String resType = updatePropPage.getResType();
+
         try {
             boolean result = false;
-            Resource res = loadRamlPage.getResource();
-            if (res instanceof SingleResource) {
+            if (createdResource instanceof SingleResource) {
                 result = Activator
                         .getDefault()
                         .getResourceManager()
-                        .completeSingleResourceCreationByRAML(res,
-                                updatePropPage.getResURI(),
-                                updatePropPage.getResName(), false);
+                        .completeSingleResourceCreationByRAML(createdResource,
+                                resURI, resName, resType, false);
             }
 
             if (result) {
                 status = "Resource created.";
-                createdResource = res;
             } else {
                 status = "Failed to create resource.";
                 createdResource = null;
@@ -422,47 +389,43 @@ public class CreateResourceWizard extends Wizard {
         }
     }
 
-    private int createMultiInstanceSingleResourceWithoutRAML() {
-        int toCreateCount = loadRamlPage.getResourceCount();
-        int resCreatedCount = 0;
-        Set<SingleResource> resources;
-        try {
-            resources = Activator
-                    .getDefault()
-                    .getResourceManager()
-                    .createSingleResourceMultiInstances(
-                            loadRamlPage.getConfigFilePath(), toCreateCount,
-                            progressMonitor);
-            if (null != progressMonitor && progressMonitor.isCanceled()) {
-                try {
-                    Activator.getDefault().getResourceManager()
-                            .removeSingleResources(resources);
-                } catch (SimulatorException e) {
-                    Activator
-                            .getDefault()
-                            .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "There is an error while updating the resource model.\n"
-                                            + Utility.getSimulatorErrorString(
-                                                    e, null));
+    private void completeMultiInstanceResourceCreationWithRAML() {
+        String resName = updateMultiInstanceCreationPropPage.getResName();
+        String resType = updateMultiInstanceCreationPropPage.getResType();
+
+        if (null == multiInstanceResourceSet)
+            return;
+
+        boolean result = false;
+        int count = loadRamlPage.getResourceCount();
+        int successCount = 0;
+        SingleResource resource;
+        Iterator<SingleResource> itr = multiInstanceResourceSet.iterator();
+        while (itr.hasNext()) {
+            resource = itr.next();
+            try {
+                result = Activator
+                        .getDefault()
+                        .getResourceManager()
+                        .completeSingleResourceCreationByRAML(resource, null,
+                                resName, resType, true);
+                if (result) {
+                    successCount++;
                 }
-                return 0;
-            }
-            if (null != resources)
-                resCreatedCount = resources.size();
-            if (resCreatedCount > 0) {
-                status = "[" + resCreatedCount + " out of " + toCreateCount
-                        + "]";
-                status += ((resCreatedCount == 1) ? "resource" : "resources")
-                        + " created successfully.";
-            } else {
-                status = "Failed to create resources.";
+
+            } catch (SimulatorException e) {
+                // Do Nothing.
             }
-        } catch (SimulatorException e) {
-            status = "Failed to create resource.\n"
-                    + Utility.getSimulatorErrorString(e, null);
         }
-        return resCreatedCount;
+        if (successCount > 0) {
+            UiListenerHandler.getInstance().resourceCreatedUINotification(
+                    ResourceType.SINGLE);
+
+            status = "[" + successCount + " out of " + count + "]";
+            status += ((successCount == 1) ? "resource" : "resources")
+                    + " created successfully.";
+        } else {
+            status = "Failed to create resources.";
+        }
     }
 }
\ No newline at end of file
index 0a253eb..8c0c778 100644 (file)
@@ -46,6 +46,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Date;
+import java.util.Set;
 
 import org.oic.simulator.ILogger.Level;
 import org.oic.simulator.SimulatorException;
@@ -74,9 +75,12 @@ public class LoadRamlPage extends WizardPage {
     private int                    resourceCount;
 
     private Resource               resource;
+    private Set<SingleResource>    multiInstanceResourceSet;
 
     private SimulatorResource.Type typeOfResource;
 
+    private IProgressMonitor       progressMonitor;
+
     protected LoadRamlPage() {
         super("Create Resource");
         resourceCount = -1;
@@ -217,7 +221,7 @@ public class LoadRamlPage extends WizardPage {
             resourceCount = -1;
         }
         if (null != configFilePath && configFilePath.trim().length() > 0) {
-            if (resourceCount == 1) {
+            if (resourceCount >= 1) {
                 done = true;
             }
         }
@@ -282,57 +286,165 @@ public class LoadRamlPage extends WizardPage {
             return null;
         }
 
+        IWizardPage nextPage;
+        String resName;
+        String resURI;
+        String resType;
         final CreateResourceWizard wizard = ((CreateResourceWizard) getWizard());
+        if (isMultiResourceCreation()) {
+            final int[] resCreatedCount = new int[1];
+            try {
+                getContainer().run(true, true, new IRunnableWithProgress() {
+
+                    @Override
+                    public void run(final IProgressMonitor monitor)
+                            throws InvocationTargetException,
+                            InterruptedException {
+                        progressMonitor = monitor;
+                        try {
+                            monitor.beginTask(
+                                    "Single Resource Creation(multi-instance) With RAML",
+                                    wizard.getLoadRamlPage().getResourceCount());
+                            resCreatedCount[0] = createMultiInstanceSingleResourceWithRAML();
+
+                        } 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();
+            }
 
-        try {
-            getContainer().run(true, false, new IRunnableWithProgress() {
-                @Override
-                public void run(IProgressMonitor monitor)
-                        throws InvocationTargetException, InterruptedException {
-                    try {
-                        monitor.beginTask("Resource Creation With RAML", 2);
-                        monitor.worked(1);
-                        resource = Activator.getDefault().getResourceManager()
-                                .createResourceByRAML(configFilePath);
-                        monitor.worked(1);
-                    } catch (SimulatorException e) {
-                        wizard.setStatus("Failed to create resource.\n"
-                                + Utility.getSimulatorErrorString(e, null));
-                    } finally {
-                        monitor.done();
+            if (0 == resCreatedCount[0]) {
+                wizard.setStatus("Failed to create Resources.");
+                wizard.getWizardDialog().close();
+                return null;
+            }
+
+            boolean canceled = false;
+            if (null != progressMonitor && progressMonitor.isCanceled()) {
+                canceled = true;
+            }
+            progressMonitor = null;
+            if (canceled) {
+                return null;
+            }
+
+            // It is guaranteed that will be at least one resource at this
+            // point.
+            SingleResource resourceInstance = (SingleResource) multiInstanceResourceSet
+                    .toArray()[0];
+            resName = resourceInstance.getResourceName();
+            resType = resourceInstance.getResourceType();
+            resURI = resourceInstance.getResourceURI();
+            UpdateMultiInstanceCreationPropertiesPage updatePageRef = wizard
+                    .getUpdateMultiInstanceCreationPropPage();
+            updatePageRef.setResName(resName);
+            updatePageRef.setResType(resType);
+            nextPage = updatePageRef;
+        } else {
+            try {
+                getContainer().run(true, false, new IRunnableWithProgress() {
+                    @Override
+                    public void run(IProgressMonitor monitor)
+                            throws InvocationTargetException,
+                            InterruptedException {
+                        try {
+                            monitor.beginTask("Resource Creation With RAML", 2);
+                            monitor.worked(1);
+                            resource = Activator.getDefault()
+                                    .getResourceManager()
+                                    .createResourceByRAML(configFilePath);
+                            monitor.worked(1);
+                        } catch (SimulatorException e) {
+                            wizard.setStatus("Failed to create resource.\n"
+                                    + Utility.getSimulatorErrorString(e, null));
+                        } 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();
+            }
+            if (null == resource) {
+                wizard.setStatus("Failed to create Resource.");
+                wizard.getWizardDialog().close();
+                return null;
+            } else {
+                // Checking whether the resource is of type single.
+                Option intendedResource = wizard.getMainPage().getOption();
+                if ((intendedResource == Option.SIMPLE_FROM_RAML && !(resource instanceof SingleResource))) {
+                    MessageDialog
+                            .openError(
+                                    getShell(),
+                                    "Invalid RAML",
+                                    "Uploaded RAML is not of simple type. "
+                                            + "Please upload the proper RAML of simple type.");
+                    return null;
                 }
-            });
-        } 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();
+            }
+            resName = resource.getResourceName();
+            resURI = resource.getResourceURI();
+            resType = resource.getResourceType();
+            UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage();
+            updatePageRef.setResName(resName);
+            updatePageRef.setResURI(resURI);
+            updatePageRef.setResType(resType);
+            nextPage = updatePageRef;
         }
-        if (null == resource) {
-            wizard.setStatus("Failed to create Resource.");
-            wizard.getWizardDialog().close();
-            return null;
-        } else {
-            // Checking whether the resource is of type single.
-            Option intendedResource = wizard.getMainPage().getOption();
-            if ((intendedResource == Option.SIMPLE_FROM_RAML && !(resource instanceof SingleResource))) {
-                MessageDialog
-                        .openError(
-                                getShell(),
-                                "Invalid RAML",
-                                "Uploaded RAML is not of simple type. "
-                                        + "Please upload the proper RAML of simple type.");
-                return null;
+        return nextPage;
+    }
+
+    public int createMultiInstanceSingleResourceWithRAML() {
+        int resCreatedCount = 0;
+        try {
+            multiInstanceResourceSet = Activator
+                    .getDefault()
+                    .getResourceManager()
+                    .createSingleResourceMultiInstances(configFilePath,
+                            resourceCount, progressMonitor);
+            if (null != progressMonitor && progressMonitor.isCanceled()) {
+                try {
+                    Activator.getDefault().getResourceManager()
+                            .removeSingleResources(multiInstanceResourceSet);
+                } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    "There is an error while handling the cancellation request.\n"
+                                            + Utility.getSimulatorErrorString(
+                                                    e, null));
+                }
+                return 0;
             }
+            if (null != multiInstanceResourceSet)
+                resCreatedCount = multiInstanceResourceSet.size();
+        } catch (SimulatorException e) {
+            Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "Failed to create resource(s).\n"
+                                    + Utility.getSimulatorErrorString(e, null));
         }
-        UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage();
-        updatePageRef.setResName(resource.getResourceName());
-        updatePageRef.setResURI(resource.getResourceURI());
-        return updatePageRef;
+        return resCreatedCount;
     }
 
     public String getConfigFilePath() {
@@ -350,4 +462,12 @@ public class LoadRamlPage extends WizardPage {
     public void setResource(Resource resource) {
         this.resource = resource;
     }
+
+    public Set<SingleResource> getMultiInstanceResourceSet() {
+        return multiInstanceResourceSet;
+    }
+
+    public void setMultiInstanceResourceSet(Set<SingleResource> resource) {
+        multiInstanceResourceSet = resource;
+    }
 }
\ No newline at end of file
index df8b03d..cf5514c 100644 (file)
@@ -58,6 +58,8 @@ public class ResourceWizardDialog extends WizardDialog {
             LoadRamlPage loadRamlPage = createWizard.getLoadRamlPage();
             UpdatePropertiesPage updatePropPage = createWizard
                     .getUpdatePropPage();
+            UpdateMultiInstanceCreationPropertiesPage updateMultiInstanceCreationPropPage = createWizard
+                    .getUpdateMultiInstanceCreationPropPage();
 
             IWizardPage curPage = wizard.getContainer().getCurrentPage();
             IWizardPage prevPage = null;
@@ -65,8 +67,10 @@ public class ResourceWizardDialog extends WizardDialog {
             if (curPage == loadRamlPage
                     || curPage == simpleResourceBasicDetailsPage) {
                 prevPage = mainPage;
-            } else if (curPage == updatePropPage) {
+            } else if (curPage == updatePropPage
+                    || curPage == updateMultiInstanceCreationPropPage) {
                 loadRamlPage.setResource(null);
+                loadRamlPage.setMultiInstanceResourceSet(null);
                 prevPage = loadRamlPage;
             } else if (curPage == simpleResourceAddAttributesPage) {
                 prevPage = simpleResourceBasicDetailsPage;
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateMultiInstanceCreationPropertiesPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateMultiInstanceCreationPropertiesPage.java
new file mode 100644 (file)
index 0000000..6365916
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Copyright 2016 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 org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import oic.simulator.serviceprovider.utils.Constants;
+
+public class UpdateMultiInstanceCreationPropertiesPage extends WizardPage {
+
+    private Text   resNameTxt;
+    private Text   resTypeTxt;
+
+    private String resName;
+    private String resType;
+
+    protected UpdateMultiInstanceCreationPropertiesPage() {
+        super("Update Properties");
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        setPageComplete(true);
+        setTitle(Constants.UPDATE_PROP_PAGE_TITLE);
+        setMessage(Constants.UPDATE_PROP_PAGE_MESSAGE);
+
+        Composite comp = new Composite(parent, SWT.NONE);
+        GridLayout gridLayout = new GridLayout();
+        comp.setLayout(gridLayout);
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        comp.setLayoutData(gd);
+
+        Group grp = new Group(comp, SWT.NONE);
+        gridLayout = new GridLayout(2, false);
+        grp.setLayout(gridLayout);
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        grp.setLayoutData(gd);
+
+        Label resNameLbl = new Label(grp, SWT.NULL);
+        resNameLbl.setText("Resource Name");
+        gd = new GridData();
+        gd.verticalIndent = 20;
+        resNameLbl.setLayoutData(gd);
+
+        resNameTxt = new Text(grp, SWT.BORDER);
+        resNameTxt.setFocus();
+        gd = new GridData();
+        gd.widthHint = 300;
+        gd.verticalIndent = 20;
+        resNameTxt.setLayoutData(gd);
+
+        Label resTypeLbl = new Label(grp, SWT.NULL);
+        resTypeLbl.setText("Resource Type");
+        gd = new GridData();
+        gd.verticalIndent = 10;
+        resTypeLbl.setLayoutData(gd);
+
+        resTypeTxt = new Text(grp, SWT.BORDER);
+        gd = new GridData();
+        gd.widthHint = 300;
+        gd.verticalIndent = 10;
+        resTypeTxt.setLayoutData(gd);
+
+        Label descLbl = new Label(comp, SWT.NONE);
+        descLbl.setText("Description:");
+        gd = new GridData();
+        descLbl.setLayoutData(gd);
+
+        final Text text = new Text(comp, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER
+                | SWT.WRAP | SWT.V_SCROLL);
+        text.setText("All resource instances will be configured with the same resource name and type.\n"
+                + "These properties can be changed later from properties view.");
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        text.setLayoutData(gd);
+
+        addUIListeners();
+
+        // Initialize data
+        if (resNameTxt.getText().length() < 1 && null != resName) {
+            resNameTxt.setText(resName);
+        }
+        if (resTypeTxt.getText().length() < 1 && null != resType) {
+            resTypeTxt.setText(resType);
+        }
+
+        setControl(comp);
+    }
+
+    private void addUIListeners() {
+        resNameTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e) {
+                resName = resNameTxt.getText();
+                setPageComplete(isSelectionDone());
+            }
+        });
+
+        resTypeTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e) {
+                resType = resTypeTxt.getText();
+                if (null == resType) {
+                    return;
+                }
+
+                setPageComplete(isSelectionDone());
+            }
+        });
+    }
+
+    @Override
+    public boolean canFlipToNextPage() {
+        return false;
+    }
+
+    public boolean isSelectionDone() {
+        boolean done = false;
+        if (null != resName && resName.trim().length() > 0 && null != resType
+                && resType.trim().length() > 0) {
+            done = true;
+        }
+        return done;
+    }
+
+    @Override
+    public IWizardPage getNextPage() {
+        return null;
+    }
+
+    public void setResName(String resName) {
+        if (null == resName) {
+            resName = "";
+        }
+
+        this.resName = resName;
+        if (null != resName && !resNameTxt.isDisposed())
+            resNameTxt.setText(resName);
+    }
+
+    public void setResType(String resType) {
+        if (null == resType) {
+            resType = "";
+        }
+
+        this.resType = resType;
+        if (null != resType && !resTypeTxt.isDisposed())
+            resTypeTxt.setText(resType);
+    }
+
+    public String getResName() {
+        return resName;
+    }
+
+    public String getResType() {
+        return resType;
+    }
+}
index b7628a6..af6b582 100644 (file)
@@ -34,9 +34,11 @@ public class UpdatePropertiesPage extends WizardPage {
 
     private Text   resNameTxt;
     private Text   resUriTxt;
+    private Text   resTypeTxt;
 
     private String resName;
     private String resURI;
+    private String resType;
 
     protected UpdatePropertiesPage() {
         super("Update Properties");
@@ -85,6 +87,18 @@ public class UpdatePropertiesPage extends WizardPage {
         gd.verticalIndent = 10;
         resUriTxt.setLayoutData(gd);
 
+        Label resTypeLbl = new Label(grp, SWT.NULL);
+        resTypeLbl.setText("Resource Type");
+        gd = new GridData();
+        gd.verticalIndent = 10;
+        resTypeLbl.setLayoutData(gd);
+
+        resTypeTxt = new Text(grp, SWT.BORDER);
+        gd = new GridData();
+        gd.widthHint = 300;
+        gd.verticalIndent = 10;
+        resTypeTxt.setLayoutData(gd);
+
         Label descLbl = new Label(comp, SWT.NONE);
         descLbl.setText("Description:");
         gd = new GridData();
@@ -105,6 +119,9 @@ public class UpdatePropertiesPage extends WizardPage {
         if (resNameTxt.getText().length() < 1 && null != resName) {
             resNameTxt.setText(resName);
         }
+        if (resTypeTxt.getText().length() < 1 && null != resType) {
+            resTypeTxt.setText(resType);
+        }
 
         setControl(comp);
     }
@@ -129,6 +146,18 @@ public class UpdatePropertiesPage extends WizardPage {
                 setPageComplete(isSelectionDone());
             }
         });
+
+        resTypeTxt.addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e) {
+                resType = resTypeTxt.getText();
+                if (null == resType) {
+                    return;
+                }
+
+                setPageComplete(isSelectionDone());
+            }
+        });
     }
 
     @Override
@@ -139,7 +168,8 @@ public class UpdatePropertiesPage extends WizardPage {
     public boolean isSelectionDone() {
         boolean done = false;
         if (null != resName && resName.trim().length() > 0 && null != resURI
-                && resURI.trim().length() > 0) {
+                && resURI.trim().length() > 0 && null != resType
+                && resType.trim().length() > 0) {
             done = true;
         }
         return done;
@@ -151,17 +181,35 @@ public class UpdatePropertiesPage extends WizardPage {
     }
 
     public void setResName(String resName) {
+        if (null == resName) {
+            resName = "";
+        }
+
         this.resName = resName;
-        if (!resNameTxt.isDisposed())
+        if (null != resName && !resNameTxt.isDisposed())
             resNameTxt.setText(resName);
     }
 
     public void setResURI(String resURI) {
+        if (null == resURI) {
+            resURI = "";
+        }
+
         this.resURI = resURI;
-        if (!resUriTxt.isDisposed())
+        if (null != resUriTxt && !resUriTxt.isDisposed())
             resUriTxt.setText(resURI);
     }
 
+    public void setResType(String resType) {
+        if (null == resType) {
+            resType = "";
+        }
+
+        this.resType = resType;
+        if (null != resType && !resTypeTxt.isDisposed())
+            resTypeTxt.setText(resType);
+    }
+
     public String getResName() {
         return resName;
     }
@@ -169,4 +217,8 @@ public class UpdatePropertiesPage extends WizardPage {
     public String getResURI() {
         return resURI;
     }
+
+    public String getResType() {
+        return resType;
+    }
 }
index 15bc6ff..061f872 100644 (file)
@@ -177,22 +177,6 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
         resourceModel.remove("resourceType");\r
     }\r
 \r
-    // Construct resource type from uri\r
-    if(resourceType.empty())\r
-    {\r
-        std::ostringstream rtString;\r
-        rtString << "oic.r.";\r
-\r
-        size_t pos = resourceURI.rfind("/");\r
-        if (pos == std::string::npos)\r
-            pos = -1;\r
-\r
-        std::string rtName = resourceURI.substr(pos+1);\r
-        std::transform(rtName.begin(), rtName.end(), rtName.begin(), ::tolower);\r
-        rtString << rtName;\r
-        resourceType = rtString.str();\r
-    }\r
-\r
     // Extracting interface type.\r
     std::vector<std::string> interfaceTypes;\r
     if (resourceModel.contains("if"))\r
@@ -236,7 +220,8 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
             new SimulatorCollectionResourceImpl());\r
 \r
         collectionRes->setName(resourceName);\r
-        collectionRes->setResourceType(resourceType);\r
+        if(!resourceType.empty())\r
+            collectionRes->setResourceType(resourceType);\r
         if (interfaceTypes.size() > 0)\r
             collectionRes->setInterface(interfaceTypes);\r
         collectionRes->setURI(ResourceURIFactory::getInstance()->makeUniqueURI(resourceURI));\r
@@ -254,7 +239,8 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
             new SimulatorSingleResourceImpl());\r
 \r
         singleRes->setName(resourceName);\r
-        singleRes->setResourceType(resourceType);\r
+        if(!resourceType.empty())\r
+            singleRes->setResourceType(resourceType);\r
         if (interfaceTypes.size() > 0)\r
             singleRes->setInterface(interfaceTypes);\r
         singleRes->setURI(ResourceURIFactory::getInstance()->makeUniqueURI(resourceURI));\r