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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations