use of com.zimbra.soap.mail.type.ModifyGroupMemberOperation in project zm-mailbox by Zimbra.
the class CreateContact method parseContactMergeMode.
static ParsedContact parseContactMergeMode(Element cn, ZimbraSoapContext zsc, OperationContext octxt, Contact existing) throws ServiceException {
Mailbox mbox = getRequestedMailbox(zsc);
ParsedContact.FieldDeltaList deltaList = new ParsedContact.FieldDeltaList();
List<Attachment> attachments = new ArrayList<Attachment>();
boolean isContactGroup = false;
for (Element elt : cn.listElements(MailConstants.E_ATTRIBUTE)) {
String name = elt.getAttribute(MailConstants.A_ATTRIBUTE_NAME);
if (name.trim().equals(""))
throw ServiceException.INVALID_REQUEST("at least one contact field name is blank", null);
Attachment attach = parseAttachment(elt, name, zsc, octxt, existing);
if (attach == null) {
String opStr = elt.getAttribute(MailConstants.A_OPERATION, null);
ParsedContact.FieldDelta.Op op = FieldDelta.Op.fromString(opStr);
String value = elt.getText();
deltaList.addAttrDelta(name, value, op);
if (ContactConstants.A_type.equals(name) && ContactConstants.TYPE_GROUP.equals(value) && ParsedContact.FieldDelta.Op.REMOVE != op) {
isContactGroup = true;
}
} else {
attachments.add(attach);
}
}
boolean discardExistingMembers = false;
for (Element elt : cn.listElements(MailConstants.E_CONTACT_GROUP_MEMBER)) {
if (!isContactGroup && !existing.isGroup()) {
throw ServiceException.INVALID_REQUEST(MailConstants.E_CONTACT_GROUP_MEMBER + " is only allowed for contact group", null);
}
String opStr = elt.getAttribute(MailConstants.A_OPERATION);
ModifyGroupMemberOperation groupMemberOp = ModifyGroupMemberOperation.fromString(opStr);
if (ModifyGroupMemberOperation.RESET.equals(groupMemberOp)) {
discardExistingMembers = true;
} else {
ParsedContact.FieldDelta.Op op = FieldDelta.Op.fromString(opStr);
ContactGroup.Member.Type memberType = ContactGroup.Member.Type.fromSoap(elt.getAttribute(MailConstants.A_CONTACT_GROUP_MEMBER_TYPE, null));
String memberValue = elt.getAttribute(MailConstants.A_CONTACT_GROUP_MEMBER_VALUE, null);
if (memberType == null) {
throw ServiceException.INVALID_REQUEST("missing member type", null);
}
if (StringUtil.isNullOrEmpty(memberValue)) {
throw ServiceException.INVALID_REQUEST("missing member value", null);
}
// bug 98526: remove account ID from item ID when it references the local account
String contactId = memberValue;
if (memberType == ContactGroup.Member.Type.CONTACT_REF) {
ItemId iid = new ItemId(memberValue, mbox.getAccountId());
if (!iid.getAccountId().equals(mbox.getAccountId())) {
contactId = memberValue;
} else {
contactId = String.valueOf(iid.getId());
}
}
deltaList.addGroupMemberDelta(memberType, contactId, op);
}
}
return new ParsedContact(existing).modify(deltaList, attachments, discardExistingMembers);
}
Aggregations