use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class AbstractJSONFileStepForm method getXSDJSONFilePath.
protected String getXSDJSONFilePath() {
if (getConnection().getFileContent() == null || getConnection().getFileContent().length == 0) {
return null;
}
byte[] bytes = getConnection().getFileContent();
Project project = ProjectManager.getInstance().getCurrentProject();
IProject fsProject = null;
try {
fsProject = ResourceUtils.getProject(project);
} catch (PersistenceException e2) {
ExceptionHandler.process(e2);
}
if (fsProject == null) {
return null;
}
//$NON-NLS-1$
String temPath = fsProject.getLocationURI().getPath() + File.separator + "temp";
//$NON-NLS-1$
String fileName = "";
if (getConnection().getJSONFilePath() != null) {
fileName = "tempJSONFile" + '.' + "json";
}
File temfile = new File(temPath + File.separator + fileName);
if (!temfile.exists()) {
try {
temfile.createNewFile();
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
FileOutputStream outStream;
try {
outStream = new FileOutputStream(temfile);
outStream.write(bytes);
outStream.close();
} catch (FileNotFoundException e1) {
ExceptionHandler.process(e1);
} catch (IOException e) {
ExceptionHandler.process(e);
}
String tempJSONXsdPath = temfile.getPath();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection());
tempJSONXsdPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, tempJSONXsdPath));
}
return tempJSONXsdPath;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class AbstractJSONStepForm method revertContext.
/*
* (non-Javadoc)
*
* @see org.talend.repository.ui.swt.utils.AbstractForm#revertContext()
*/
@Override
protected void revertContext() {
if (hasContextBtn() && connectionItem != null) {
if (isContextMode()) {
ContextType contextType = JSONConnectionContextHelper.getContextTypeForContextMode(getShell(), connectionItem.getConnection(), true);
if (contextType != null) {
// choose
JSONConnectionContextHelper.revertPropertiesForContextMode(connectionItem, contextType);
adaptContextModeToReversion();
}
} else {
JSONConnectionContextHelper.openOutConetxtModeDialog();
}
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class ReviseInvalidContextNamesMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
boolean modified = false;
if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
List<ContextType> contextTypes = contextItem.getContext();
for (ContextType contextType : contextTypes) {
List<ContextParameterType> contextParameterTypes = contextType.getContextParameter();
for (ContextParameterType contextParameterType : contextParameterTypes) {
String name = contextParameterType.getName();
if (!ContextParameterUtils.isValidParameterName(name)) {
String newName = ContextParameterUtils.getValidParameterName(name);
contextParameterType.setName(newName);
modified = true;
}
}
}
}
if (modified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class ContextRepositoryReviewDialog method okPressed.
/*
* (non-Javadoc)
*
* @see org.talend.repository.ui.dialog.RepositoryReviewDialog#okPressed()
*/
@SuppressWarnings("unchecked")
@Override
protected void okPressed() {
if (params == null || params.isEmpty()) {
super.okPressed();
}
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (createNewButton.getSelection()) {
if (nameInvalid(contextNameText)) {
//$NON-NLS-1$
MessageDialog.openError(getShell(), "Context", msg);
return;
} else {
item = PropertiesFactory.eINSTANCE.createContextItem();
if (item == null) {
return;
}
Property createProperty = PropertiesFactory.eINSTANCE.createProperty();
createProperty.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
createProperty.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
createProperty.setStatusCode("");
try {
String nextId = factory.getNextId();
createProperty.setId(nextId);
item.setProperty(createProperty);
for (IContext context : contextManager.getListContext()) {
ContextType contextType = TalendFileFactory.eINSTANCE.createContextType();
contextType.setName(context.getName());
item.getContext().add(contextType);
}
item.setDefaultContext(contextManager.getDefaultContext().getName());
item.getProperty().setLabel(contextNameText.getText().trim());
IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory();
try {
boolean nameAvaliabe = repositoryFactory.isNameAvailable(createProperty.getItem(), contextNameText.getText());
if (!nameAvaliabe) {
MessageDialog.openError(getShell(), "Context", //$NON-NLS-1$
Messages.getString(//$NON-NLS-1$
"PropertiesWizardPage.ItemExistsError"));
return;
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
super.okPressed();
}
//$NON-NLS-1$
factory.create(item, new Path(""));
} catch (PersistenceException e) {
ExceptionHandler.process(e);
super.okPressed();
}
}
} else {
IStructuredSelection selection = (IStructuredSelection) getRepositoryTreeViewer().getSelection();
RepositoryNode context = (RepositoryNode) selection.getFirstElement();
try {
// get the item from file
IRepositoryViewObject contextObj = factory.getLastVersion(context.getObject().getProperty().getId());
item = (ContextItem) contextObj.getProperty().getItem();
} catch (PersistenceException e) {
ExceptionHandler.process(e);
super.okPressed();
}
}
super.okPressed();
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method initFileContent.
/*
* same as XmlFileOutputStep2Form.initXmlTreeData()
*/
private String initFileContent(XmlFileConnection connection) throws IOException {
byte[] bytes = connection.getFileContent();
Project project = ProjectManager.getInstance().getCurrentProject();
IProject fsProject = null;
try {
fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
} catch (PersistenceException e2) {
ExceptionHandler.process(e2);
}
if (fsProject == null) {
return null;
}
String temPath = fsProject.getLocationURI().getPath() + File.separator + "temp";
String fileName = "";
String pathStr = connection.getXmlFilePath();
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection, true);
pathStr = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, pathStr));
}
if (pathStr != null && XmlUtil.isXMLFile(pathStr)) {
fileName = StringUtil.TMP_XML_FILE;
} else if (pathStr != null && XmlUtil.isXSDFile(pathStr)) {
fileName = StringUtil.TMP_XSD_FILE;
} else if (pathStr != null && XmlUtil.isWSDLFile(pathStr)) {
fileName = StringUtil.TMP_WSDL_FILE;
} else if (pathStr.contains(".zip")) {
fileName = new Path(pathStr).lastSegment();
} else {
return null;
}
File temfile = new File(temPath + File.separator + fileName);
if (!temfile.exists()) {
temfile.createNewFile();
}
FileOutputStream outStream;
outStream = new FileOutputStream(temfile);
outStream.write(bytes);
outStream.close();
return temfile.getPath();
}
Aggregations