if(dir.getComment()!=null||(dir.getComment()==null&&!"".equals(newDesc)))
dir.setComment(newDesc);
//set word net
SscfDomain domain = SscfDomain.getSscfDomain(dir.getResource().toString());
List<ThesaurusEntry> oldWnClass = domain.getWordNetClassification();
List<ThesaurusEntry> finalWnClass = new ArrayList<ThesaurusEntry>();
List<ThesaurusEntry> removedWnClass = new ArrayList<ThesaurusEntry>();
//for future use
//domain.setPersonInterest(person, 1);
//Save wordnet
if(thValues!=null&&thValues.size()>0)
{
List<ThesaurusEntry> chosenClassifications = new ArrayList<ThesaurusEntry>();
//Currently we support only wordnet on the client side
/*ThesaurusContext wnContext = Thesauri.getInstance().getContext("http://www.w3.org/2006/03/wn/wn20/");
for(String wc:wnValues) {
try
{
chosenClassifications.add(wnContext.getEntryByUri(wc));
}
catch (Exception e)
{
//ignore
}
}*/
Set<String> thesUris = thValues.keySet();
//List<ThesaurusEntry> taxEntries = new ArrayList<ThesaurusEntry>();
for(String thesUri:thesUris)
{
Collection<String> thesList = thValues.get(thesUri);
ThesaurusContext thesauri = Thesauri.getInstance().getContext(thesUri);
if (thesauri!=null)
{
for(String entry:thesList)
{
ThesaurusEntry thEntry = thesauri.getEntryByUri(entry,null);
chosenClassifications.add(thEntry);
}
}
}
//compare those two classifcations
//removed old has it, new doesn't
for(ThesaurusEntry cl:oldWnClass)
{
if(chosenClassifications.contains(cl)) {
finalWnClass.add(cl);
}
else {
removedWnClass.add(cl);
}
}
//remove things added to finalWnClass from choosenClass
chosenClassifications.removeAll(finalWnClass);
//generate changes information
//removed are in removedWnClass
//new are in choosenClassifications
//others in finalWnClass
if(removedWnClass.size()>0||chosenClassifications.size()>0)
{
change+=ChangeTypes.CHANGED_TEZ.getChangeType();
if(changeValue.length()>0) changeValue.append("||");
changeValue.append(ChangeTypes.CHANGED_TEZ.getChangeType()).append(':');
for(ThesaurusEntry tmpcl:removedWnClass)
{
changeValue.append(tmpcl.getLabel()).append(',');
}
changeValue.append("::");
for(ThesaurusEntry tmpcl:chosenClassifications)
{
changeValue.append(tmpcl.getLabel()).append(',');
finalWnClass.add(tmpcl);
}
}
domain.setWordNetClassification(finalWnClass);
}
//Save other classifications.
if(taxValues!=null&&taxValues.size()>0)
{
List<TaxonomyEntry> oldEntries = domain.getClassification();
List<TaxonomyEntry> finalList = new ArrayList<TaxonomyEntry>();
List<TaxonomyEntry> removedList = new ArrayList<TaxonomyEntry>();
Set<String> taxUris = taxValues.keySet();
List<TaxonomyEntry> taxEntries = new ArrayList<TaxonomyEntry>();
for(String taxUri:taxUris)
{
Collection<String> taxList = taxValues.get(taxUri);
TaxonomyContext<TaxonomyEntry> taxonomy = Taxonomies.getInstance().getContext(taxUri);
if (taxonomy!=null)
{
for(String entry:taxList)
{
TaxonomyEntry taxonomyEntry = taxonomy.getEntryByUri(entry,null);
taxEntries.add(taxonomyEntry);
}
}
}
//compare those two classifcations
//removed old has it, new doesn't
for(TaxonomyEntry te:oldEntries)
{
if(taxEntries.contains(te)) {
finalList.add(te);
}
else {
removedList.add(te);
}
}
taxEntries.removeAll(finalList);
//generate changes information
//removed are in removedList
//new are in taxEntries
//others in finalList
if(removedList.size()>0||taxEntries.size()>0)
{
change+=ChangeTypes.CHANGED_TAX.getChangeType();
if(changeValue.length()>0) changeValue.append("||");
changeValue.append(ChangeTypes.CHANGED_TAX.getChangeType()).append(':');
for(TaxonomyEntry tmpte:removedList)
{
changeValue.append(tmpte.getContext().getLabel()).append(" - ").append(tmpte.getLabel()).append(';');
}
changeValue.append("::");
for(TaxonomyEntry tmpte:taxEntries)
{
changeValue.append(tmpte.getContext().getLabel()).append(" - ").append(tmpte.getLabel()).append(';');
finalList.add(tmpte);
}
}
domain.setClassification(finalList);
}
//notify synchronization resource loader that resources of user were changed
ResourcesLoader.setLastChangeDate(view, new Date());