use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class SQLPatternComposite method addReferencedSQLTemplate.
private void addReferencedSQLTemplate(List<IRepositoryViewObject> list, Project project) {
try {
Context ctx = CorePlugin.getContext();
if (ctx == null) {
return;
}
String parentBranch = ProjectManager.getInstance().getMainProjectBranch(project);
List<ProjectReference> referencedProjects = project.getEmfProject().getReferencedProjects();
for (ProjectReference referenced : referencedProjects) {
if (referenced.getBranch() != null && !parentBranch.equals(referenced.getBranch())) {
continue;
}
org.talend.core.model.properties.Project referencedEmfProject = referenced.getReferencedProject();
EList refeInRef = referencedEmfProject.getReferencedProjects();
Project newProject = new Project(referencedEmfProject);
if (refeInRef != null && refeInRef.size() > 0) {
addReferencedSQLTemplate(list, newProject);
}
List<IRepositoryViewObject> refList;
refList = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAll(newProject, ERepositoryObjectType.SQLPATTERNS, false);
for (IRepositoryViewObject repositoryObject : refList) {
Item item = repositoryObject.getProperty().getItem();
if (item instanceof SQLPatternItem) {
if (!((SQLPatternItem) item).isSystem()) {
list.add(repositoryObject);
sqlPatternAndProject.put((SQLPatternItem) item, project);
}
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class Problems method computePropertyMaxInformationLevel.
/**
* See also AbstractEMFRepositoryFactory.computePropertyMaxInformationLevel
*
* @param property
*/
public static void computePropertyMaxInformationLevel(Property property, boolean allowUpdateProperty) {
EList<Information> informations = property.getInformations();
InformationLevel maxLevel = null;
for (int i = 0; i < informations.size(); i++) {
Information information = informations.get(i);
if (i == 0) {
maxLevel = information.getLevel();
continue;
}
int value = information.getLevel().getValue();
if (maxLevel == null || value > maxLevel.getValue()) {
maxLevel = information.getLevel();
}
}
// TDI-22098
// after run the job , if the modified the property ,should be save .
InformationLevel propertyMaxLevel = property.getMaxInformationLevel();
boolean isModified = false;
if (maxLevel != null) {
if (!maxLevel.equals(propertyMaxLevel)) {
property.setMaxInformationLevel(maxLevel);
isModified = true;
}
} else if (!InformationLevel.DEBUG_LITERAL.equals(propertyMaxLevel)) {
property.setMaxInformationLevel(InformationLevel.DEBUG_LITERAL);
isModified = true;
}
// save the property
if (isModified && allowUpdateProperty) {
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
Item item = property.getItem();
try {
factory.save(item, false);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
use of org.talend.commons.exception.PersistenceException 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();
}
use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class JSONUtil method changeJsonToXml.
public static String changeJsonToXml(String jsonPath) {
Project project = ProjectManager.getInstance().getCurrentProject();
IProject fsProject = null;
try {
fsProject = ResourceUtils.getProject(project);
} catch (PersistenceException e2) {
ExceptionHandler.process(e2);
}
if (fsProject == null) {
return jsonPath;
}
String temPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "jsonwizard" + File.separator;
ConvertJSONString convertJSON = new ConvertJSONString();
de.odysseus.staxon.json.JsonXMLConfig jsonConfig = new de.odysseus.staxon.json.JsonXMLConfigBuilder().multiplePI(false).build();
de.odysseus.staxon.json.JsonXMLInputFactory jsonXMLInputFactory = new de.odysseus.staxon.json.JsonXMLInputFactory(jsonConfig);
javax.xml.stream.XMLOutputFactory xmlOutputFactory = javax.xml.stream.XMLOutputFactory.newInstance();
java.io.ByteArrayOutputStream outStream = new java.io.ByteArrayOutputStream();
InputStream inStream = null;
File file = new File(jsonPath);
// String filename = file.getName().replaceAll("\\.", "_");
// filename = "tempTest";
boolean isFromUrl = false;
boolean illegalURL = false;
InputStream input = null;
if (file.exists()) {
if (file.isDirectory()) {
return "";
}
try {
input = new FileInputStream(file);
} catch (FileNotFoundException e) {
ExceptionHandler.process(e);
}
} else {
isFromUrl = true;
try {
input = new URL(jsonPath).openStream();
} catch (MalformedURLException e) {
illegalURL = true;
} catch (IOException e) {
illegalURL = true;
}
if (illegalURL) {
return "";
}
}
try {
String jsonStr = IOUtils.toString(input);
convertJSON.setJsonString(jsonStr);
convertJSON.generate();
jsonStr = convertJSON.getJsonString4XML();
inStream = new ByteArrayInputStream(jsonStr.getBytes());
javax.xml.stream.XMLEventReader xmlEventReader = jsonXMLInputFactory.createXMLEventReader(inStream);
javax.xml.stream.XMLEventWriter xmLEventWriter = xmlOutputFactory.createXMLEventWriter(outStream);
xmLEventWriter.add(xmlEventReader);
String xmlStr = outStream.toString();
File xmlFolder = new File(temPath);
if (!xmlFolder.exists()) {
xmlFolder.mkdirs();
}
temPath = temPath + TMP_JSON_FILE;
FileWriter writer = new FileWriter(temPath);
writer.write(xmlStr);
writer.flush();
writer.close();
xmLEventWriter.close();
xmlEventReader.close();
if (isFromUrl) {
tempJSONXsdPath = temPath;
}
} catch (java.lang.Exception e) {
ExceptionHandler.process(e);
} finally {
try {
outStream.close();
if (inStream != null) {
inStream.close();
}
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
return temPath;
}
use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.
the class JSONUtil method deleteWizardTempFiles.
public static void deleteWizardTempFiles() {
tempJSONXsdPath = null;
Project project = ProjectManager.getInstance().getCurrentProject();
IProject fsProject = null;
try {
fsProject = ResourceUtils.getProject(project);
} catch (PersistenceException e2) {
ExceptionHandler.process(e2);
}
if (fsProject == null) {
return;
}
String tempPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "wizard";
File tempWizardDir = new File(tempPath);
tempWizardDir.delete();
String tempjsonPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "jsonwizard";
File tempjsonWizardDir = new File(tempjsonPath);
if (tempjsonWizardDir.exists()) {
tempjsonWizardDir.delete();
}
}
Aggregations