mirror of
https://git.code.sf.net/p/projectlibre/code
synced 2024-11-01 03:21:46 +01:00
Fix issues when importing old POD file
This commit is contained in:
parent
a95477e35c
commit
a4f188f474
8 changed files with 156 additions and 40 deletions
|
@ -69,6 +69,7 @@ import com.projectlibre1.pm.task.ProjectFactory;
|
|||
public abstract class FileImporter /*implements Runnable*/ {
|
||||
protected JobQueue jobQueue=null;
|
||||
protected String fileName;
|
||||
protected InputStream fileInputStream;
|
||||
protected Project project;
|
||||
protected ResourceMappingForm resourceMapping;
|
||||
protected ProjectFactory projectFactory=null;
|
||||
|
@ -136,6 +137,14 @@ public abstract class FileImporter /*implements Runnable*/ {
|
|||
public void setResourceMapping(ResourceMappingForm resourceMapping) {
|
||||
this.resourceMapping = resourceMapping;
|
||||
}
|
||||
|
||||
public InputStream getFileInputStream() {
|
||||
return fileInputStream;
|
||||
}
|
||||
|
||||
public void setFileInputStream(InputStream fileInputStream) {
|
||||
this.fileInputStream = fileInputStream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,8 @@ import java.io.ObjectOutputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import com.projectlibre1.grouping.core.model.DefaultNodeModel;
|
||||
import com.projectlibre1.job.Job;
|
||||
import com.projectlibre1.job.JobRunnable;
|
||||
|
@ -76,6 +78,7 @@ import com.projectlibre1.pm.resource.ResourcePoolFactory;
|
|||
import com.projectlibre1.pm.task.Project;
|
||||
import com.projectlibre1.server.data.DataUtil;
|
||||
import com.projectlibre1.server.data.DocumentData;
|
||||
import com.projectlibre1.session.LoadOptions;
|
||||
import com.projectlibre1.session.LocalSession;
|
||||
import com.projectlibre1.session.SessionFactory;
|
||||
import com.projectlibre1.strings.Messages;
|
||||
|
@ -88,6 +91,7 @@ import com.projectlibre1.util.Alert;
|
|||
public class LocalFileImporter extends FileImporter {
|
||||
public static final String VERSION="1.0.0"; //$NON-NLS-1$
|
||||
private static final String PROJECT_LIBRE_FILE_SEPARATOR="@@@@@@@@@@ProjectLibreSeparator_MSXML@@@@@@@@@@";
|
||||
private static final String OLD_FILE="com.projity.server.data.ProjectData";
|
||||
private static final String XML_FILE_START="<?xml";
|
||||
/**
|
||||
*
|
||||
|
@ -104,36 +108,43 @@ public class LocalFileImporter extends FileImporter {
|
|||
File f=new File(getFileName());
|
||||
FileInputStream fin=new FileInputStream(f);
|
||||
Exception ex=null;
|
||||
try {
|
||||
DataUtil serializer=new DataUtil();
|
||||
System.out.println("Loading "+getFileName()+"..."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
long t1=System.currentTimeMillis();
|
||||
ObjectInputStream in=new ObjectInputStream(fin);
|
||||
Object obj=in.readObject();
|
||||
if (obj instanceof String) obj=in.readObject(); //check version in the future
|
||||
DocumentData projectData=(DocumentData)obj;
|
||||
projectData.setMaster(true);
|
||||
projectData.setLocal(true);
|
||||
long t2=System.currentTimeMillis();
|
||||
System.out.println("Loading...Done in "+(t2-t1)+" ms"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
|
||||
System.out.println("Deserializing..."); //$NON-NLS-1$
|
||||
t1=System.currentTimeMillis();
|
||||
// project=serializer.deserializeProject(projectData,false,true,resourceMap);
|
||||
setProject(serializer.deserializeLocalDocument(projectData));
|
||||
t2=System.currentTimeMillis();
|
||||
System.out.println("Deserializing...Done in "+(t2-t1)+" ms"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (Exception e) {
|
||||
ex=e;
|
||||
|
||||
if (/*findString(fin, OLD_FILE)*/false) {
|
||||
System.out.println("Old file: ignoring binary content");
|
||||
project=null;
|
||||
}finally{
|
||||
try {
|
||||
fin.close();
|
||||
}else {
|
||||
try {
|
||||
DataUtil serializer=new DataUtil();
|
||||
System.out.println("Loading "+getFileName()+"..."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
long t1=System.currentTimeMillis();
|
||||
ObjectInputStream in=new ObjectInputStream(fin);
|
||||
Object obj=in.readObject();
|
||||
if (obj instanceof String) obj=in.readObject(); //check version in the future
|
||||
DocumentData projectData=(DocumentData)obj;
|
||||
projectData.setMaster(true);
|
||||
projectData.setLocal(true);
|
||||
long t2=System.currentTimeMillis();
|
||||
System.out.println("Loading...Done in "+(t2-t1)+" ms"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
|
||||
System.out.println("Deserializing..."); //$NON-NLS-1$
|
||||
t1=System.currentTimeMillis();
|
||||
// project=serializer.deserializeProject(projectData,false,true,resourceMap);
|
||||
setProject(serializer.deserializeLocalDocument(projectData));
|
||||
t2=System.currentTimeMillis();
|
||||
System.out.println("Deserializing...Done in "+(t2-t1)+" ms"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ex=e;
|
||||
project=null;
|
||||
}finally{
|
||||
try {
|
||||
fin.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (project==null){
|
||||
|
@ -207,20 +218,56 @@ public class LocalFileImporter extends FileImporter {
|
|||
if (found || xmlStartFound) {
|
||||
//xml found
|
||||
System.out.println("XML found");
|
||||
FileImporter importer=LocalSession.getImporter("com.projectlibre1.exchange.MicrosoftImporter");
|
||||
final LoadOptions opt=new LoadOptions();
|
||||
opt.setFileName(fileName);
|
||||
opt.setLocal(true);
|
||||
opt.setSync(false);
|
||||
opt.setImporter(LocalSession.MICROSOFT_PROJECT_IMPORTER);
|
||||
opt.setFileInputStream(in);
|
||||
|
||||
ResourcePool resourcePool=null;
|
||||
DataFactoryUndoController undoController=new DataFactoryUndoController();
|
||||
resourcePool = ResourcePoolFactory.getInstance().createResourcePool("",undoController);
|
||||
resourcePool.setLocal(true);
|
||||
project = Project.createProject(resourcePool,undoController);
|
||||
((DefaultNodeModel)project.getTaskOutline()).setDataFactory(project);
|
||||
importer.setProject(project);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
projectFactory.openProject(opt);
|
||||
|
||||
}
|
||||
});
|
||||
// project=projectFactory.openProject(opt);
|
||||
|
||||
|
||||
importer.loadProject(in);
|
||||
// FileImporter importer=LocalSession.getImporter("com.projectlibre1.exchange.MicrosoftImporter");
|
||||
//
|
||||
// ResourcePool resourcePool=null;
|
||||
// DataFactoryUndoController undoController=new DataFactoryUndoController();
|
||||
// resourcePool = ResourcePoolFactory.getInstance().createResourcePool("",undoController);
|
||||
// resourcePool.setLocal(true);
|
||||
// project = Project.createProject(resourcePool,undoController);
|
||||
// ((DefaultNodeModel)project.getTaskOutline()).setDataFactory(project);
|
||||
// importer.setProject(project);
|
||||
//
|
||||
// importer.loadProject(in);
|
||||
System.out.println("Recovered with XML");
|
||||
}else{
|
||||
//unable to recover from xml
|
||||
//unable to recover from xml
|
||||
if ( ex!=null &&
|
||||
ex instanceof ClassNotFoundException &&
|
||||
ex.getMessage().equals("com.projity.server.data.ProjectData")) {
|
||||
SwingUtilities.invokeLater(new Runnable(){
|
||||
public void run(){
|
||||
Alert.error(Messages.getString("Message.ImportOldFormatError"));
|
||||
}
|
||||
});
|
||||
}else {
|
||||
SwingUtilities.invokeLater(new Runnable(){
|
||||
public void run(){
|
||||
Alert.error(Messages.getString("Message.ImportError"));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (ex!=null) throw ex;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -237,6 +284,45 @@ public class LocalFileImporter extends FileImporter {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean findString(InputStream fin, String stringToSearch) {
|
||||
BufferedInputStream in=null;
|
||||
try {
|
||||
byte[] keyBuf=stringToSearch.getBytes();
|
||||
int bufSize=100;
|
||||
if (bufSize<keyBuf.length) bufSize=keyBuf.length;
|
||||
byte[] buf= new byte[bufSize];
|
||||
in=new BufferedInputStream(fin); //use default 8192 bytes size
|
||||
|
||||
int keyPos=0;
|
||||
int n;
|
||||
in.mark(bufSize);
|
||||
while ( (n=in.read( buf, 0, bufSize )) != -1 ){
|
||||
for (int i=0; i<n; i++ ){
|
||||
if (keyBuf[keyPos]==buf[i]){
|
||||
if (keyPos==keyBuf.length-1){
|
||||
//found keyword
|
||||
return true;
|
||||
}else{
|
||||
keyPos++;
|
||||
}
|
||||
}else keyPos=0;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in!=null){
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -55,6 +55,8 @@
|
|||
*******************************************************************************/
|
||||
package com.projectlibre1.session;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.collections.Closure;
|
||||
|
||||
import com.projectlibre1.exchange.ResourceMappingForm;
|
||||
|
@ -65,6 +67,7 @@ public class LoadOptions {
|
|||
protected boolean subproject;
|
||||
protected boolean sync;
|
||||
protected String fileName;
|
||||
protected InputStream fileInputStream;
|
||||
protected String importer;
|
||||
protected boolean openAs;
|
||||
protected ResourceMappingForm resourceMapping;
|
||||
|
@ -123,5 +126,11 @@ public class LoadOptions {
|
|||
public void setEndSwingClosure(Closure endSwingClosure) {
|
||||
this.endSwingClosure = endSwingClosure;
|
||||
}
|
||||
public InputStream getFileInputStream() {
|
||||
return fileInputStream;
|
||||
}
|
||||
public void setFileInputStream(InputStream fileInputStream) {
|
||||
this.fileInputStream = fileInputStream;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -115,6 +115,7 @@ public class LocalSession extends AbstractSession{
|
|||
try {
|
||||
final FileImporter importer = (FileImporter) ClassUtils.forName(opt.getImporter()).newInstance();
|
||||
importer.setFileName(opt.getFileName());
|
||||
importer.setFileInputStream(opt.getFileInputStream());
|
||||
importer.setResourceMapping(opt.getResourceMapping());
|
||||
importer.setProjectFactory(ProjectFactory.getInstance());//used?
|
||||
importer.setJobQueue(jobQueue);
|
||||
|
|
|
@ -632,6 +632,7 @@ LookupDialog.Type=Type:
|
|||
LookupDialog.UnableToContactServer=Unable to contact server.
|
||||
LookupField.LookupAValue=Lookup a Value
|
||||
Message.ImportError=Failed to read file
|
||||
Message.ImportOldFormatError=Failed to read file. The file is in a deprecated format. \nTo convert it, please open the file with ProjectLibre version 1.8 then save it to xml or pod format. \nThe new file will be readable by new ProjectLibre versions.
|
||||
Message.allowDeleteActuals=The selected item(s) have actual values already. Are you sure you wish to delete them?
|
||||
Message.allowDistrbutedStartBeforeProjectStart=The value will cause the task to start before the project start. Is this OK?
|
||||
Message.allowDistrbutedStartBeforeTaskStart=The value is before the task's start. Is this OK?
|
||||
|
|
|
@ -115,7 +115,7 @@ public class VersionUtils {
|
|||
String localVersion = pref.get("PODVersion","0");
|
||||
boolean updated = !localVersion.equals(version);
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
System.out.println("POD Version: "+version + " local version " + localVersion + " updated=" + updated + " java version=" + javaVersion);
|
||||
System.out.println("ProjectLibre Version: "+version + " local version " + localVersion + " updated=" + updated + " java version=" + javaVersion);
|
||||
|
||||
|
||||
pref.put("JavaVersion",javaVersion);
|
||||
|
|
|
@ -148,7 +148,8 @@ public class MspImporter {
|
|||
|
||||
public void parseProject(InputStream in, String extension) throws Exception {
|
||||
try {
|
||||
if (extension.equals("xml")){
|
||||
if (extension.equals("xml")
|
||||
|| extension.equals("pod")){
|
||||
reader=new ImprovedMSPDIReader();
|
||||
state.setMspdi(true);
|
||||
} else if (extension.equals("mpp"))
|
||||
|
|
|
@ -230,13 +230,22 @@ public class MicrosoftImporter extends ServerFileImporter{
|
|||
|
||||
|
||||
MspImporter plImporter=new MspImporter();
|
||||
plProject=plImporter.importProject(fileName, new MspImporter.ProgressClosure() {
|
||||
if (fileInputStream==null)
|
||||
plProject=plImporter.importProject(fileName, new MspImporter.ProgressClosure() {
|
||||
@Override
|
||||
public void updateProgress(float progress, String label) {
|
||||
setProgress(progress*0.1f);
|
||||
|
||||
}
|
||||
});
|
||||
else plProject=plImporter.importProject(fileInputStream, "xml", new MspImporter.ProgressClosure() {
|
||||
@Override
|
||||
public void updateProgress(float progress, String label) {
|
||||
setProgress(progress*0.1f);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
log.info(plProject.toString());
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue