return resource;
}
public static ResourceImpl deserializeResourceAndAddToPool(ResourceData resourceData,ResourcePool resourcePool,Session reindex,Map enterpriseResources) throws IOException, ClassNotFoundException{
EnterpriseResourceData enterpriseResourceData=resourceData.getEnterpriseResource();
EnterpriseResource enterpriseResource;
if (enterpriseResources==null){
enterpriseResource =(EnterpriseResource)deserialize(enterpriseResourceData,reindex);
enterpriseResource.setUserAccount(enterpriseResourceData.getUserAccount());
}else{
EnterpriseResourceData e=(EnterpriseResourceData)enterpriseResources.get(new Long(enterpriseResourceData.getUniqueId()));
if (e==null) return null; //TODO handle this
enterpriseResource =(EnterpriseResource)deserialize(e,reindex);
enterpriseResource.setUserAccount(e.getUserAccount());
}
enterpriseResource.setGlobalWorkVector(enterpriseResourceData.getGlobalWorkVector());
enterpriseResource.setMaster(resourcePool.isMaster());
ResourceImpl resource=(resourceData.getSerialized()==null)?
createResourceFromEnterpriseResource(enterpriseResource):
(ResourceImpl)deserialize(resourceData,reindex);
resource.setGlobalResource(enterpriseResource);
setRoles(resource, resourceData);
// to ensure older projects import correctly
WorkingCalendar cal = (WorkingCalendar) enterpriseResource.getWorkCalendar();
if (cal==null)
enterpriseResource.setWorkCalendar(WorkingCalendar.getInstanceBasedOn(resourcePool.getDefaultCalendar()));
else {
try {
// cal.setBaseCalendar(CalendarService.findBaseCalendar(cal.getBaseCalendar().getName()));// avoids multiple instances
WorkCalendar baseCal=CalendarService.findBaseCalendar(cal.getBaseCalendar().getName());
//TODO verification in case the name isn't found, import problem