private boolean _saveRelationship(ActionForm form,ActionRequest req, ActionResponse res)
{
try
{
RelationshipForm relationshipForm = (RelationshipForm) form;
Relationship relationship = (Relationship) req.getAttribute(WebKeys.Relationship.RELATIONSHIP_EDIT);
Structure parentStructure = null;
Structure childStructure = null;
if(InodeUtils.isSet(relationshipForm.getParentStructureInode()) ||
InodeUtils.isSet(relationshipForm.getChildStructureInode())){
parentStructure = StructureCache.getStructureByInode(relationshipForm.getParentStructureInode());
childStructure = StructureCache.getStructureByInode(relationshipForm.getChildStructureInode());
}
if(parentStructure!=null && childStructure!=null){
if(!relationship.isFixed()){
String relationshipTypeValue = relationshipForm.getParentRelationName().replaceAll("\\s", "_").replaceAll("[^a-zA-Z0-9\\_]", "") +
"-" + relationshipForm.getChildRelationName().replaceAll("\\s", "_").replaceAll("[^a-zA-Z0-9\\_]", "");
String lastRelationshipTypeValue = relationship.getRelationTypeValue();
//Preserve old tree relationship if the relation name be changed
if (InodeUtils.isSet(relationship.getInode()) && !relationshipTypeValue.equals(lastRelationshipTypeValue)) {
DotConnect dc = new DotConnect ();
dc.setSQL("update tree set relation_type = '" + relationshipTypeValue +
"' where relation_type = '" + lastRelationshipTypeValue + "'");
dc.getResult();
}
//Copy properties from the form
BeanUtils.copyProperties(relationship,relationshipForm);
if (!relationshipTypeValue.equals(relationship.getRelationTypeValue())) {
Relationship oRel = RelationshipFactory.getRelationshipByRelationTypeValue(relationshipTypeValue);
if (InodeUtils.isSet(oRel.getInode()) && !oRel.getInode().equalsIgnoreCase(relationship.getInode())) {
String message = "error.relationship.same.relation.exist";
SessionMessages.add(req, "error",message);
return false;
}
List<Tree> treesToUpdate = TreeFactory.getTreesByRelationType(relationshipForm.getRelationTypeValue());
for (Tree theTree : treesToUpdate) {
theTree.setRelationType(relationshipTypeValue);
}
relationship.setRelationTypeValue(relationshipTypeValue);
}