Search in sources :

Example 6 with RootXmlResource

use of org.eclipse.sapphire.modeling.xml.RootXmlResource 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 7 with RootXmlResource

use of org.eclipse.sapphire.modeling.xml.RootXmlResource 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)

Example 8 with RootXmlResource

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

the class NewWorkflowDefinitionOpMethods method execute.

public static Status execute(NewWorkflowDefinitionOp op, ProgressMonitor monitor) {
    try {
        ReferenceValue<String, IProject> referProject = op.getProject();
        IProject project = referProject.target();
        Value<Path> opFolder = op.getFolder();
        Path projectPath = opFolder.content();
        IContainer folder = null;
        if (projectPath != null) {
            folder = project.getFolder(projectPath.toPortableString());
        } else {
            folder = project;
        }
        if (!folder.exists()) {
            folder = folder.getParent();
        }
        Value<String> opName = op.getName();
        String name = opName.content();
        String lowerCaseName = name.toLowerCase();
        String[] segments = lowerCaseName.split("\\s+");
        StringBuilder newName = new StringBuilder();
        for (String segment : segments) {
            StringBuilder segNewName = newName.append(segment);
            segNewName.append('-');
        }
        String fileNameBase = newName.toString() + "definition";
        String extension = ".xml";
        String fileName = fileNameBase + extension;
        IPath proRelativePath = folder.getProjectRelativePath();
        IFile newDefinitionFile = project.getFile(proRelativePath.append(fileName));
        int count = 1;
        while (newDefinitionFile.exists()) {
            fileName = fileNameBase + " (" + count + ")" + extension;
            newDefinitionFile = project.getFile(proRelativePath.append(fileName));
            count++;
        }
        newDefinitionFile.create(new ByteArrayInputStream("".getBytes()), true, null);
        Value<ScriptLanguageType> scLanguageType = op.getDefaultScriptLanguage();
        newDefinitionFile.setPersistentProperty(KaleoCore.DEFAULT_SCRIPT_LANGUAGE_KEY, scLanguageType.text(true));
        Value<TemplateLanguageType> deTemplateLanguage = op.getDefaultTemplateLanguage();
        newDefinitionFile.setPersistentProperty(KaleoCore.DEFAULT_TEMPLATE_LANGUAGE_KEY, deTemplateLanguage.text(true));
        RootXmlResource rootXmlResource = new RootXmlResource(new XmlResourceStore(new WorkspaceFileResourceStore(newDefinitionFile)));
        WorkflowDefinition workflowDefinition = WorkflowDefinition.TYPE.instantiate(rootXmlResource);
        workflowDefinition.setName(name);
        workflowDefinition.setVersion("1");
        Value<String> initStateName = op.getInitialStateName();
        String initialStateName = initStateName.content(true);
        ElementList<State> workflowState = workflowDefinition.getStates();
        State state = workflowState.insert();
        state.setName(initialStateName);
        state.setInitial(true);
        Value<String> initTaskName = op.getInitialTaskName();
        String initialTaskName = initTaskName.content(true);
        ElementList<Task> workflowTask = workflowDefinition.getTasks();
        Task task = workflowTask.insert();
        task.setName(initialTaskName);
        KaleoModelUtil.changeTaskAssignments(task, op);
        ElementList<Transition> transitions = state.getTransitions();
        Transition transition = transitions.insert();
        transition.setName(initialTaskName);
        transition.setTarget(initialTaskName);
        Value<String> opFinalName = op.getFinalStateName();
        String finalStateName = opFinalName.content(true);
        ElementList<State> states = workflowDefinition.getStates();
        State finalState = states.insert();
        finalState.setName(finalStateName);
        finalState.setEnd(true);
        ElementList<Action> actions = finalState.getActions();
        Action finalAction = actions.insert();
        finalAction.setName("approve");
        finalAction.setExecutionType(ExecutionType.ON_ENTRY);
        finalAction.setScriptLanguage(ScriptLanguageType.JAVASCRIPT);
        String updateStatus = "Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus";
        String workflowConstants = "(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.";
        String toStatus = "toStatus(\"approved\"), workflowContext);";
        finalAction.setScript(updateStatus + workflowConstants + toStatus);
        ElementList<Transition> taskTransitions = task.getTransitions();
        Transition taskTransition = taskTransitions.insert();
        taskTransition.setName(finalStateName);
        taskTransition.setTarget(finalStateName);
        ElementHandle<WorkflowNodeMetadata> wfMetadata = state.getMetadata();
        WorkflowNodeMetadata stateMetadata = wfMetadata.content();
        Position statePosition = stateMetadata.getPosition();
        statePosition.setX(100);
        statePosition.setY(50);
        ElementList<TransitionMetadata> transitionMetadata = stateMetadata.getTransitionsMetadata();
        TransitionMetadata insertTransitionMetadata = transitionMetadata.insert();
        insertTransitionMetadata.setName(initialTaskName);
        ElementHandle<WorkflowNodeMetadata> taskWorkflow = task.getMetadata();
        WorkflowNodeMetadata taskMetadata = taskWorkflow.content();
        Position taskPosition = taskMetadata.getPosition();
        taskPosition.setX(300);
        taskPosition.setY(35);
        ElementList<TransitionMetadata> transitionTask = taskMetadata.getTransitionsMetadata();
        TransitionMetadata transitionTaskMetadata = transitionTask.insert();
        transitionTaskMetadata.setName(finalStateName);
        ElementHandle<WorkflowNodeMetadata> finalMetadata = finalState.getMetadata();
        WorkflowNodeMetadata finalStateMetadata = finalMetadata.content();
        Position finalStatePosition = finalStateMetadata.getPosition();
        finalStatePosition.setX(520);
        finalStatePosition.setY(50);
        /*
			 * Document document = rootXmlResource.getDomDocument(); Element
			 * docElement = document.getDocumentElement(); Attr schemaLocation =
			 * docElement.getAttributeNode( "xsi:schemaLocation" ); =
			 * schemaLocation.getNodeValue(); String nodeValue =
			 * schemaLocation.getNodeValue(); schemaLocation.setNodeValue(
			 * nodeValue.replaceAll( " http://www.w3.org/XML/1998/namespace ",
			 * "" ) );
			 */
        rootXmlResource.save();
        IPath fullPath = newDefinitionFile.getFullPath();
        op.setNewFilePath(fullPath.toPortableString());
        return Status.createOkStatus();
    } catch (Exception e) {
        KaleoCore.logError("Error creating new kaleo workflow file.", e);
        return Status.createErrorStatus("Error creating new kaleo workflow file.", e);
    }
}
Also used : Task(com.liferay.ide.kaleo.core.model.Task) Action(com.liferay.ide.kaleo.core.model.Action) IFile(org.eclipse.core.resources.IFile) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) WorkspaceFileResourceStore(org.eclipse.sapphire.workspace.WorkspaceFileResourceStore) TemplateLanguageType(com.liferay.ide.kaleo.core.model.TemplateLanguageType) IContainer(org.eclipse.core.resources.IContainer) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IPath(org.eclipse.core.runtime.IPath) Position(com.liferay.ide.kaleo.core.model.Position) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) State(com.liferay.ide.kaleo.core.model.State) Transition(com.liferay.ide.kaleo.core.model.Transition)

Example 9 with RootXmlResource

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

the class StructuresTests method getElementFromFile.

protected Element getElementFromFile(IProject project, IPath filePath, ElementType type) throws Exception {
    final String filePathValue = filePath.toOSString();
    final IFile file = createFile(project, filePathValue, this.getClass().getResourceAsStream(filePathValue));
    assertEquals(file.getFullPath().lastSegment(), filePath.lastSegment());
    final InputStream contents = file.getContents();
    final Element element = type.instantiate(new RootXmlResource(new XmlResourceStore(contents)));
    contents.close();
    return element;
}
Also used : IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) DynamicElement(com.liferay.ide.portal.core.structures.model.DynamicElement) Element(org.eclipse.sapphire.Element) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource)

Aggregations

RootXmlResource (org.eclipse.sapphire.modeling.xml.RootXmlResource)9 XmlResourceStore (org.eclipse.sapphire.modeling.xml.XmlResourceStore)7 IFile (org.eclipse.core.resources.IFile)5 IProject (org.eclipse.core.resources.IProject)3 Element (org.eclipse.sapphire.Element)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 Matcher (java.util.regex.Matcher)2 IFolder (org.eclipse.core.resources.IFolder)2 IPath (org.eclipse.core.runtime.IPath)2 Resource (org.eclipse.sapphire.Resource)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