⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aligner.java

📁 联合国农粮署牵头开发的geonetwork源代码最新版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						if (localGrpId == null)							log.info("    - Specified group was not found remotely : "+ remoteGroup.name);						else						{							log.debug("    - Setting privileges for group : "+ remoteGroup.name);							addOperations(id, localGrpId, oper);						}					}				}				else				{					//--- group exists locally					if (remoteGroup.policy == Group.CopyPolicy.COPY_TO_INTRANET)					{						log.debug("    - Setting privileges for 'intranet' group");						addOperations(id, "0", oper);					}					else					{						log.debug("    - Setting privileges for group : "+ remoteGroup.name);						addOperations(id, localGrpId, oper);					}				}			}		}	}	//--------------------------------------------------------------------------	private Map<String, Set<String>> buildPrivileges(Element privil)	{		Map<String, Set<String>> map = new HashMap<String, Set<String>>();		for (Object o : privil.getChildren("group"))		{			Element group = (Element) o;			String  name  = group.getAttributeValue("name");			Set<String> set = new HashSet<String>();			map.put(name, set);			for (Object op : group.getChildren("operation"))			{				Element oper = (Element) op;				name = oper.getAttributeValue("name");				set.add(name);			}		}		return map;	}	//--------------------------------------------------------------------------	private void addOperations(String id, String groupId, Set<String> oper) throws Exception	{		for (String opName : oper)		{			int opId = dataMan.getAccessManager().getPrivilegeId(opName);			//--- allow only: view, dynamic, featured			if (opId == 0 || opId == 5 || opId == 6)			{				log.debug("       --> "+ opName);				dataMan.setOperation(dbms, id, groupId, opId +"");			}			else				log.debug("       --> "+ opName +" (skipped)");		}	}	//--------------------------------------------------------------------------	private String createGroup(String name) throws Exception	{		Map<String, String> hm = hmRemoteGroups.get(name);		if (hm == null)			return null;		int id = context.getSerialFactory().getSerial(dbms, "Groups");		dbms.execute("INSERT INTO Groups(id, name) VALUES (?, ?)", id, name);		Lib.local.insert(dbms, "Groups", id, hm, "<"+name+">");		localGroups.add(name, id +"");		return id +"";	}	//--------------------------------------------------------------------------	//---	//--- Private methods : updateMetadata	//---	//--------------------------------------------------------------------------	private void updateMetadata(final RecordInfo ri, final String id) throws Exception	{		final Element md[]     = { null };		final Element thumbs[] = { null };		if (localUuids.getID(ri.uuid) == null)			log.debug("  - Skipped metadata managed by another harvesting node. uuid:"+ ri.uuid +", name:"+ params.name);		else		{			File mefFile = retrieveMEF(ri.uuid);			try			{				MEFLib.visit(mefFile, new MEFVisitor()				{					public void handleMetadata(Element mdata) throws Exception					{						md[0] = mdata;					}					//-----------------------------------------------------------------					public void handleInfo(Element info) throws Exception					{						updateMetadata(ri, id, md[0], info);						thumbs[0] = info.getChild("thumbnails");					}					//-----------------------------------------------------------------					public void handlePublicFile(String file, String changeDate, InputStream is) throws IOException					{						updateFile(id, file, changeDate, is, thumbs[0]);					}					//-----------------------------------------------------------------					public void handlePrivateFile(String file, String changeDate, InputStream is) {}				});			}			catch(Exception e)			{				//--- we ignore the exception here. Maybe the metadata has been removed just now				result.unretrievable++;			}			finally			{				mefFile.delete();			}		}	}	//--------------------------------------------------------------------------	private void updateMetadata(RecordInfo ri, String id, Element md, Element info) throws Exception	{		String date = localUuids.getChangeDate(ri.uuid);		if (!ri.isMoreRecentThan(date))		{			log.debug("  - XML not changed for local metadata with uuid:"+ ri.uuid);			result.unchangedMetadata++;		}		else		{			log.debug("  - Updating local metadata with id="+ id);			dataMan.updateMetadataExt(dbms, id, md, ri.changeDate);			result.updatedMetadata++;		}		dbms.execute("DELETE FROM MetadataCateg WHERE metadataId=?", Integer.parseInt(id));		addCategories(id);		dbms.execute("DELETE FROM OperationAllowed WHERE metadataId=?", Integer.parseInt(id));		addPrivileges(id, info.getChild("privileges"));		dbms.commit();		dataMan.indexMetadata(dbms, id);	}	//--------------------------------------------------------------------------	//--- Public file update methods	//--------------------------------------------------------------------------	private void updateFile(String id, String file, String changeDate, InputStream is,									Element files) throws IOException	{		if (files == null)			log.debug("  - No 'public' element in info.xml. Cannot update public file :"+ file);		else		{			removeOldFile(id, files);			updateChangedFile(id, file, changeDate, is);		}	}	//--------------------------------------------------------------------------	private void removeOldFile(String id, Element infoFiles)	{		File pubDir = new File(Lib.resource.getDir(context, "public", id));		File files[] = pubDir.listFiles();		if (files == null)			log.error("  - Cannot scan directory for public files : "+ pubDir.getAbsolutePath());		else for (File file : files)			if (!existsFile(file.getName(), infoFiles))			{				log.debug("  - Removing old public file with name="+ file.getName());				file.delete();			}	}	//--------------------------------------------------------------------------	private boolean existsFile(String fileName, Element files)	{		List list = files.getChildren("file");		for (int i=0; i<list.size(); i++)		{			Element elem = (Element) list.get(i);			String  name = elem.getAttributeValue("name");			if (fileName.equals(name))				return true;		}		return false;	}	//--------------------------------------------------------------------------	private void updateChangedFile(String id, String file, String changeDate,											 InputStream is) throws IOException	{		String pubDir  = Lib.resource.getDir(context, "public", id);		File   locFile = new File(pubDir, file);		ISODate locIsoDate = new ISODate(locFile.lastModified());		ISODate remIsoDate = new ISODate(changeDate);		if (!locFile.exists() || remIsoDate.sub(locIsoDate) > 0)		{			log.debug("  - Adding remote public file with name:"+ file);			FileOutputStream os = new FileOutputStream(locFile);			BinaryFile.copy(is, os, false, true);			locFile.setLastModified(remIsoDate.getSeconds() * 1000);		}		else		{			log.debug("  - Nothing to do to public file with name:"+ file);		}	}	//--------------------------------------------------------------------------	//---	//--- Private methods	//---	//--------------------------------------------------------------------------	/** Return true if the uuid is present in the remote node */	private boolean exists(Set<RecordInfo> records, String uuid)	{		for(RecordInfo ri : records)			if (uuid.equals(ri.uuid))				return true;		return false;	}	//--------------------------------------------------------------------------	private File retrieveMEF(String uuid) throws IOException	{		request.clearParams();		request.addParam("uuid",   uuid);		request.addParam("format", "partial");		request.setAddress("/"+ params.servlet +"/srv/en/"+ Geonet.Service.MEF_EXPORT);		File tempFile = File.createTempFile("temp-", ".dat");		request.executeLarge(tempFile);		return tempFile;	}	//--------------------------------------------------------------------------	//---	//--- Variables	//---	//--------------------------------------------------------------------------	private Logger         log;	private ServiceContext context;	private Dbms           dbms;	private XmlRequest     request;	private GeonetParams   params;	private DataManager    dataMan;	private GeonetResult   result;	private CategoryMapper localCateg;	private GroupMapper    localGroups;	private UUIDMapper     localUuids;	private HashMap<String, HashMap<String, String>> hmRemoteGroups = new HashMap<String, HashMap<String, String>>();}//=============================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -