/** * Updates {@link GroupAnnc} resource. * * @param requestIndication - The generic request to handle. * @return The generic returned response. */ public ResponseConfirm doUpdate(RequestIndication requestIndication) { // Link: (updateReq NP) (response M) // accessRightID: (updateReq O) (response O) // searchStrings: (updateReq M) (response M) // expirationTime: (updateReq O) (response M*) // Id: (updateReq NP) (response M*) ResponseConfirm errorResponse = new ResponseConfirm(); GroupAnnc groupAnnc = DAOFactory.getGroupAnncDAO().find(requestIndication.getTargetID()); // Check resource Existence if (groupAnnc == null) { return new ResponseConfirm( new ErrorInfo( StatusCode.STATUS_NOT_FOUND, requestIndication.getTargetID() + " does not exist in DataBase")); } // Check AccessRight errorResponse = checkAccessRight( groupAnnc.getAccessRightID(), requestIndication.getRequestingEntity(), Constants.AR_WRITE); if (errorResponse != null) { return errorResponse; } // Check Resource Representation if (requestIndication.getRepresentation() == null) { return new ResponseConfirm( new ErrorInfo(StatusCode.STATUS_BAD_REQUEST, "Resource Representation is EMPTY")); } // Check XML Validity errorResponse = checkMessageSyntax(requestIndication.getRepresentation(), "groupAnnc.xsd"); if (errorResponse != null) { return errorResponse; } // Checks on attributes GroupAnnc groupAnncNew = (GroupAnnc) XmlMapper.getInstance().xmlToObject(requestIndication.getRepresentation()); // The Update of the Id is NP if (groupAnncNew.getId() != null) { return new ResponseConfirm( new ErrorInfo(StatusCode.STATUS_BAD_REQUEST, "GroupAnncId UPDATE is Not Permitted")); } // Check ExpirationTime if (groupAnncNew.getExpirationTime() != null && !checkExpirationTime(groupAnncNew.getExpirationTime())) { return new ResponseConfirm( new ErrorInfo(StatusCode.STATUS_BAD_REQUEST, "Expiration Time UPDATE is Out of Date")); } // Link Must be NP if (groupAnncNew.getLink() != null) { return new ResponseConfirm( new ErrorInfo(StatusCode.STATUS_BAD_REQUEST, "Link attribute UPDATE is Mandatory")); } // SearchStrings Attribute is mandatory if (groupAnncNew.getSearchStrings() == null) { return new ResponseConfirm( new ErrorInfo( StatusCode.STATUS_BAD_REQUEST, "searchStrings attribute UPDATE is Mandatory")); } // Storage // Set Expiration Time if (groupAnncNew.getExpirationTime() != null) { groupAnnc.setExpirationTime(groupAnncNew.getExpirationTime()); } // Set accessRightID if it exists if (DAOFactory.getAccessRightDAO().find(groupAnncNew.getAccessRightID()) != null) { groupAnnc.setAccessRightID(groupAnncNew.getAccessRightID()); } // Set searchStrings groupAnnc.setSearchStrings(groupAnncNew.getSearchStrings()); // Notify the subscribers Notifier.notify(StatusCode.STATUS_OK, groupAnnc); // Store DAOFactory.getGroupAnncDAO().update(groupAnnc); // Response return new ResponseConfirm(StatusCode.STATUS_OK, groupAnnc); }