public Job getImportFileJob() { final Serializer serializer = new Serializer(); final FileImporter importer = this; final Job job = new Job( importer.getJobQueue(), "importFile", Messages.getString("LocalFileImporter.Importing"), true); //$NON-NLS-1$ //$NON-NLS-2$ job.addRunnable( new JobRunnable("Import", 1.0f) { // $NON-NLS-1$ public Object run() throws Exception { // DataUtil serializer=new DataUtil(); System.out.println( "Loading " + importer.getFileName() + "..."); // $NON-NLS-1$ //$NON-NLS-2$ long t1 = System.currentTimeMillis(); ObjectInputStream in = new ObjectInputStream(new FileInputStream(importer.getFileName())); Object obj = in.readObject(); if (obj instanceof String) obj = in.readObject(); // check version in the future projectData = (ProjectData) obj; projectData.setMaster(false); projectData.setLocal(false); long t2 = System.currentTimeMillis(); System.out.println( "Loading...Done in " + (t2 - t1) + " ms"); // $NON-NLS-1$ //$NON-NLS-2$ Collection<ResourceData> rs = (Collection<ResourceData>) projectData.getResources(); List<EnterpriseResourceData> ers = new ArrayList<EnterpriseResourceData>(rs.size()); for (ResourceData r : rs) { ers.add(r.getEnterpriseResource()); } ((ServerFileImporter) importer).prepareResources(ers, null, false); renumberProject(); setProgress(1.0f); return null; } }); job.addSwingRunnable( new JobRunnable("Import resources", 1.0f) { // $NON-NLS-1$ public Object run() throws Exception { ResourceMappingForm form = getResourceMapping(); if (form != null && form .isLocal()) // if form==null we are in a case were have no server access. popup // not needed if (!job.okCancel( Messages.getString("Message.ServerUnreacheableReadOnlyProject"), true)) { //$NON-NLS-1$ setProgress(1.0f); throw new Exception(ABORT); } if (!importResources()) { setProgress(1.0f); throw new JobCanceledException(ABORT); } setProgress(1f); return null; } }); job.addRunnable( new JobRunnable("Import", 1.0f) { // $NON-NLS-1$ public Object run() throws Exception { System.out.println("Deserializing..."); // $NON-NLS-1$ long t1 = System.currentTimeMillis(); ResourceMappingForm form = getResourceMapping(); // // project=serializer.deserializeProject(projectData,false,true,resourceMap); // DEF165936: Projity: .pod file import fails mapped to resource with modified calendar // pass the map into the serializer so it can grab the original impls // serializer.SetStuffForPODDeserialization(form.getExistingProject(), // _localResourceMap); //claur Project project = serializer.deserializeProject(projectData, false, null, null, null, false); if (project != null && !Environment.getStandAlone()) project.setAllDirty(); importer.setProject(project); long t2 = System.currentTimeMillis(); System.out.println( "Deserializing...Done in " + (t2 - t1) + " ms"); // $NON-NLS-1$ //$NON-NLS-2$ // project.setDistributionMap(null); project.setGroupDirty(!Environment.getStandAlone()); /*if (!Environment.isNoPodServer())*/ project.setTemporaryLocal(true); project.setAccessControlPolicy(form.getAccessControlType()); project.resetRoles(form.getAccessControlType() == 0); if (form.isLocal()) project.setLocal(true); // project.setWasImported(true); setProgress(1.0f); return null; } }); return job; }
public static void clear(boolean graphic) { ProjectFactory.getInstance() .setPromptDisabled(true); // prevent remove projects job from prompting to save Job job = ProjectFactory.getInstance().getPortfolio().getRemoveAllProjectsJob(null, false, null); SessionFactory.getInstance().getLocalSession().schedule(job); try { job.waitResult(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if (graphic) { GraphicManager gm = GraphicManager.getInstance(); if (gm != null) ((DefaultFrameManager) gm.getFrameManager()).cleanUp(false); } ProjectFactory.getInstance().getPortfolio().getObjectEventManager().removeAll(); ProjectFactory.getInstance().setPromptDisabled(false); // enable prompting again // Singletons, most of them can cause problems when it re-used. // Other singletons shouldn't be problem but have a cleanUp method just in case SessionFactory.cleanUp(); ProjectFactory.cleanUp(); ResourcePoolFactory.cleanUp(); UniqueIdPool.cleanUp(); MainFrame.cleanUp(); GraphicManager.cleanUpStatic(); StartupFactory.cleanUpStatic(); CalendarCatalog.cleanUp(); CalendarDefinition.cleanUp(); CalendarService.cleanUp(); WorkingCalendar.cleanUp(); AdvancedOption.cleanUp(); CalculationOption.cleanUp(); CalendarOption.cleanUp(); EditOption.cleanUp(); GanttOption.cleanUp(); GeneralOption.cleanUp(); ScheduleOption.cleanUp(); TimesheetOption.cleanUp(); FieldConverter.cleanUp(); ActionLists.cleanUp(); CellStyles.cleanUp(); Configuration.cleanUp(); Dictionary.cleanUp(); Factory.cleanUp(); ImportedCalendarService.cleanUp(); // remove dep NotAssignmentFilter.cleanUp(); NotVoidFilter.cleanUp(); HelpUtil.cleanUp(); ZeroFunctor.cleanUp(); NameCellComponent.cleanUp(); ScheduleService.cleanUp(); PageSizes.cleanUp(); ContextStore.cleanUp(); CustomFieldsMapper.cleanUp(); // remove dep }