Search in sources :

Example 1 with XmlResourceStore

use of org.eclipse.sapphire.modeling.xml.XmlResourceStore in project liferay-ide by liferay.

the class LiferayHookModelTests method strutsActionPathPossibleValuesService.

/**
 * @throws Exception
 */
@Test
public void strutsActionPathPossibleValuesService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    final NewLiferayPluginProjectOp op = newProjectOp("testPossibleValues");
    op.setPluginType(PluginType.hook);
    final IProject hookProject = createAntProject(op);
    final IFolder webappRoot = LiferayCore.create(IWebProject.class, hookProject).getDefaultDocrootFolder();
    assertNotNull(webappRoot);
    final IFile hookXml = webappRoot.getFile("WEB-INF/liferay-hook.xml");
    assertEquals(true, hookXml.exists());
    final XmlResourceStore store = new XmlResourceStore(hookXml.getContents()) {

        public <A> A adapt(Class<A> adapterType) {
            if (IProject.class.equals(adapterType)) {
                return adapterType.cast(hookProject);
            }
            return super.adapt(adapterType);
        }
    };
    final Hook hook = Hook6xx.TYPE.instantiate(new RootXmlResource(store));
    assertNotNull(hook);
    final StrutsAction strutsAction = hook.getStrutsActions().insert();
    final Value<String> strutsActionPath = strutsAction.getStrutsActionPath();
    final Set<String> values = strutsActionPath.service(StrutsActionPathPossibleValuesService.class).values();
    assertNotNull(values);
    assertTrue(values.size() > 10);
}
Also used : Hook(com.liferay.ide.hook.core.model.Hook) IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) StrutsAction(com.liferay.ide.hook.core.model.StrutsAction) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IProject(org.eclipse.core.resources.IProject) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) StrutsActionPathPossibleValuesService(com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesService) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 2 with XmlResourceStore

use of org.eclipse.sapphire.modeling.xml.XmlResourceStore in project liferay-ide by liferay.

the class UploadWorkflowFileJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    try {
        String errorMsgs = KaleoUtil.checkWorkflowDefinitionForErrors(_workflowFile);
        if (!CoreUtil.empty(errorMsgs)) {
            UIUtil.async(new Runnable() {

                public void run() {
                    MessageDialog.openError(Display.getDefault().getActiveShell(), "Upload Kaleo Workflow", "Unable to upload kaleo workflow:\n\n" + errorMsgs);
                }
            });
            return Status.OK_STATUS;
        }
        JSONObject def = _kaleoConnection.getKaleoDefinitions().getJSONObject(0);
        int companyId = def.getInt("companyId");
        long groupId = def.getLong("groupId");
        long userId = _kaleoConnection.getUserByEmailAddress().getLong("userId");
        RootXmlResource rootXmlResource = new RootXmlResource(new XmlResourceStore(_workflowFile.getContents()));
        WorkflowDefinition workflowDefinition = WorkflowDefinition.TYPE.instantiate(rootXmlResource).nearest(WorkflowDefinition.class);
        String portalLocale = "en_US";
        try {
            portalLocale = _kaleoConnection.getPortalLocale(userId);
        } catch (Exception e) {
        }
        String name = workflowDefinition.getName().content();
        String titleMap = KaleoUtil.createJSONTitleMap(name, portalLocale);
        String content = CoreUtil.readStreamToString(_workflowFile.getContents());
        JSONArray drafts = _kaleoConnection.getKaleoDraftWorkflowDefinitions();
        /*
			 * go through to see if the file that is being uploaded has any
			 * existing drafts
			 */
        JSONObject existingDraft = null;
        if ((drafts != null) && (drafts.length() > 0)) {
            for (int i = 0; i < drafts.length(); i++) {
                JSONObject draft = drafts.getJSONObject(i);
                String draftName = draft.getString("name");
                if ((name != null) && name.equals(draftName)) {
                    if (existingDraft == null) {
                        existingDraft = draft;
                    } else {
                        boolean draftVersion = false;
                        if (draft.getInt("draftVersion") > existingDraft.getInt("draftVersion")) {
                            draftVersion = true;
                        }
                        boolean version = false;
                        if (draft.getInt("version") > existingDraft.getInt("version")) {
                            version = true;
                        }
                        if (draftVersion || version) {
                            existingDraft = draft;
                        }
                    }
                }
            }
        }
        if (existingDraft != null) {
            _kaleoConnection.updateKaleoDraftDefinition(name, titleMap, content, existingDraft.getInt("version"), existingDraft.getInt("draftVersion"), companyId, userId);
        }
        _kaleoConnection.publishKaleoDraftDefinition(name, titleMap, content, companyId + "", userId + "", groupId + "");
    } catch (Exception e) {
        return KaleoUI.createErrorStatus("Error uploading new kaleo workflow file.", e);
    }
    if (_runnable != null) {
        _runnable.run();
    }
    return Status.OK_STATUS;
}
Also used : JSONObject(org.json.JSONObject) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) JSONArray(org.json.JSONArray) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource)

Example 3 with XmlResourceStore

use of org.eclipse.sapphire.modeling.xml.XmlResourceStore in project liferay-ide by liferay.

the class PortletsNode method _getPortletAppModelElement.

private PortletApp _getPortletAppModelElement() {
    if (_modelElement == null) {
        IFile portletXmlFile = ProjectUtil.getPortletXmlFile(this._parent.getProject());
        if ((portletXmlFile != null) && portletXmlFile.exists()) {
            try {
                IStructuredModel portletXmlModel = StructuredModelManager.getModelManager().getModelForRead(portletXmlFile);
                IModelStateListener listener = new IModelStateListener() {

                    public void modelAboutToBeChanged(IStructuredModel model) {
                    }

                    public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
                    }

                    public void modelChanged(IStructuredModel model) {
                        _refresh();
                    }

                    public void modelDirtyStateChanged(IStructuredModel model, boolean dirty) {
                        _refresh();
                    }

                    public void modelReinitialized(IStructuredModel structuredModel) {
                        _refresh();
                    }

                    public void modelResourceDeleted(IStructuredModel model) {
                        _refresh();
                    }

                    public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
                        _refresh();
                    }

                    private void _refresh() {
                        portletXmlModel.removeModelStateListener(this);
                        if (!PortletsNode.this._modelElement.disposed()) {
                            PortletsNode.this._modelElement.dispose();
                        }
                        PortletsNode.this._modelElement = null;
                        PortletsNode.this._parent.refresh();
                    }
                };
                portletXmlModel.addModelStateListener(listener);
                _modelElement = PortletApp.TYPE.instantiate(new RootXmlResource(new XmlResourceStore(portletXmlFile.getContents())));
            } catch (Exception e) {
                PortletUIPlugin.logError(e);
            }
        }
    }
    return _modelElement;
}
Also used : IFile(org.eclipse.core.resources.IFile) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IModelStateListener(org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)

Example 4 with XmlResourceStore

use of org.eclipse.sapphire.modeling.xml.XmlResourceStore in project liferay-ide by liferay.

the class LiferayHookModelTests method strutsActionPathPossibleValuesCacheService.

@Test
public void strutsActionPathPossibleValuesCacheService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    final NewLiferayPluginProjectOp op = newProjectOp("testPossibleValuesCache");
    op.setPluginType(PluginType.hook);
    final IProject hookProject = createAntProject(op);
    final IFolder webappRoot = LiferayCore.create(IWebProject.class, hookProject).getDefaultDocrootFolder();
    assertNotNull(webappRoot);
    final IFile hookXml = webappRoot.getFile("WEB-INF/liferay-hook.xml");
    assertEquals(true, hookXml.exists());
    final Hook hook = Hook6xx.TYPE.instantiate(new RootXmlResource(new XmlResourceStore(hookXml.getContents())));
    assertNotNull(hook);
    final ILiferayProject liferayProject = LiferayCore.create(hookProject);
    final ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
    final IPath strutsConfigPath = portal.getAppServerPortalDir().append("WEB-INF/struts-config.xml");
    final StrutsAction strutsAction = hook.getStrutsActions().insert();
    final Value<String> strutsActionPath = strutsAction.getStrutsActionPath();
    final TreeSet<String> vals1 = strutsActionPath.service(StrutsActionPathPossibleValuesCacheService.class).getPossibleValuesForPath(strutsConfigPath);
    final TreeSet<String> vals2 = strutsActionPath.service(StrutsActionPathPossibleValuesCacheService.class).getPossibleValuesForPath(strutsConfigPath);
    assertTrue(vals1 == vals2);
}
Also used : Hook(com.liferay.ide.hook.core.model.Hook) IFile(org.eclipse.core.resources.IFile) StrutsActionPathPossibleValuesCacheService(com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesCacheService) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) StrutsAction(com.liferay.ide.hook.core.model.StrutsAction) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IProject(org.eclipse.core.resources.IProject) ILiferayProject(com.liferay.ide.core.ILiferayProject) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 5 with XmlResourceStore

use of org.eclipse.sapphire.modeling.xml.XmlResourceStore in project liferay-ide by liferay.

the class ServiceXmlTests method testEntityReferenceService.

@Test
public void testEntityReferenceService() throws Exception {
    ServiceBuilder sb = ServiceBuilder6xx.TYPE.instantiate(new RootXmlResource(new XmlResourceStore(this.getClass().getResourceAsStream("files/entity-reference-test.xml"))));
    Entity foo = sb.getEntities().get(0);
    Entity bar = sb.getEntities().get(1);
    ElementList<Relationship> relationships = sb.getRelationships();
    assertEquals(1, relationships.size());
    Entity to = sb.getRelationships().get(0).getToEntity().target();
    Entity from = sb.getRelationships().get(0).getFromEntity().target();
    assertEquals(to, foo);
    assertEquals(from, bar);
}
Also used : Entity(com.liferay.ide.service.core.model.Entity) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) Relationship(com.liferay.ide.service.core.model.Relationship) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) ServiceBuilder(com.liferay.ide.service.core.model.ServiceBuilder) Test(org.junit.Test)

Aggregations

RootXmlResource (org.eclipse.sapphire.modeling.xml.RootXmlResource)7 XmlResourceStore (org.eclipse.sapphire.modeling.xml.XmlResourceStore)7 IFile (org.eclipse.core.resources.IFile)5 IProject (org.eclipse.core.resources.IProject)3 Test (org.junit.Test)3 IWebProject (com.liferay.ide.core.IWebProject)2 Hook (com.liferay.ide.hook.core.model.Hook)2 StrutsAction (com.liferay.ide.hook.core.model.StrutsAction)2 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)2 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)2 IFolder (org.eclipse.core.resources.IFolder)2 IPath (org.eclipse.core.runtime.IPath)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1 StrutsActionPathPossibleValuesCacheService (com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesCacheService)1 StrutsActionPathPossibleValuesService (com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesService)1 Action (com.liferay.ide.kaleo.core.model.Action)1 Position (com.liferay.ide.kaleo.core.model.Position)1 ScriptLanguageType (com.liferay.ide.kaleo.core.model.ScriptLanguageType)1 State (com.liferay.ide.kaleo.core.model.State)1