mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-07 11:48:02 -05:00
EWS: convert read flag to boolean and noneMatch/etag to detect create or update on items
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1160 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
6ec5d21c1c
commit
cbeff39eaf
@ -135,7 +135,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
HashSet<FieldUpdate> list = new HashSet<FieldUpdate>();
|
HashSet<FieldUpdate> list = new HashSet<FieldUpdate>();
|
||||||
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
||||||
if ("read".equals(entry.getKey())) {
|
if ("read".equals(entry.getKey())) {
|
||||||
list.add(Field.createFieldUpdate("read", entry.getValue()));
|
list.add(Field.createFieldUpdate("read", Boolean.toString("1".equals(entry.getValue()))));
|
||||||
} else if ("junk".equals(entry.getKey())) {
|
} else if ("junk".equals(entry.getKey())) {
|
||||||
list.add(Field.createFieldUpdate("junk", entry.getValue()));
|
list.add(Field.createFieldUpdate("junk", entry.getValue()));
|
||||||
} else if ("flagged".equals(entry.getKey())) {
|
} else if ("flagged".equals(entry.getKey())) {
|
||||||
@ -241,6 +241,9 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get item MIME content.
|
* Get item MIME content.
|
||||||
|
* @param itemId EWS item id
|
||||||
|
* @return item content as byte array
|
||||||
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
protected byte[] getContent(ItemId itemId) throws IOException {
|
protected byte[] getContent(ItemId itemId) throws IOException {
|
||||||
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, itemId, true);
|
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, itemId, true);
|
||||||
@ -700,28 +703,63 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
public ItemResult createOrUpdate() throws IOException {
|
public ItemResult createOrUpdate() throws IOException {
|
||||||
|
ItemResult itemResult = new ItemResult();
|
||||||
|
EWSMethod createOrUpdateItemMethod;
|
||||||
|
|
||||||
EWSMethod.Item item = new EWSMethod.Item();
|
// first try to load existing event
|
||||||
item.type = "Contact";
|
String urlcompname = convertItemNameToEML(itemName);
|
||||||
item.setFieldUpdates(buildProperties());
|
String currentEtag = null;
|
||||||
// TODO: handle etag and noneMatch
|
ItemId currentItemId = null;
|
||||||
CreateItemMethod createItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, getFolderId(folderPath), item);
|
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, EwsExchangeSession.this.equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW);
|
||||||
executeMethod(createItemMethod);
|
if (responses.size() > 0) {
|
||||||
|
EWSMethod.Item response = responses.get(0);
|
||||||
|
currentItemId = new ItemId(response);
|
||||||
|
currentEtag = response.get(Field.get("etag").getResponseName());
|
||||||
|
}
|
||||||
|
if ("*".equals(noneMatch)) {
|
||||||
|
// create requested
|
||||||
|
if (currentItemId != null) {
|
||||||
|
itemResult.status = HttpStatus.SC_PRECONDITION_FAILED;
|
||||||
|
return itemResult;
|
||||||
|
}
|
||||||
|
} else if (etag != null) {
|
||||||
|
// update requested
|
||||||
|
if (currentItemId == null || !etag.equals(currentEtag)) {
|
||||||
|
itemResult.status = HttpStatus.SC_PRECONDITION_FAILED;
|
||||||
|
return itemResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: detect create/update
|
if (currentItemId != null) {
|
||||||
int status = createItemMethod.getStatusCode();
|
// update
|
||||||
if (status == HttpURLConnection.HTTP_OK) {
|
createOrUpdateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
||||||
|
ConflictResolution.AlwaysOverwrite,
|
||||||
|
CalendarItemCreateOrDeleteOperation.SendToNone,
|
||||||
|
currentItemId, buildProperties());
|
||||||
|
} else {
|
||||||
|
// create
|
||||||
|
EWSMethod.Item newItem = new EWSMethod.Item();
|
||||||
|
newItem.type = "Contact";
|
||||||
|
newItem.setFieldUpdates(buildProperties());
|
||||||
|
createOrUpdateItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, getFolderId(folderPath), newItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
executeMethod(createOrUpdateItemMethod);
|
||||||
|
|
||||||
|
itemResult.status = createOrUpdateItemMethod.getStatusCode();
|
||||||
|
if (itemResult.status == HttpURLConnection.HTTP_OK) {
|
||||||
if (etag != null) {
|
if (etag != null) {
|
||||||
|
itemResult.status = HttpStatus.SC_CREATED;
|
||||||
LOGGER.debug("Updated event " + getHref());
|
LOGGER.debug("Updated event " + getHref());
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Overwritten event " + getHref());
|
LOGGER.warn("Overwritten event " + getHref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemResult itemResult = new ItemResult();
|
|
||||||
// TODO
|
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
|
||||||
itemResult.status = HttpStatus.SC_CREATED;
|
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, newItemId, false);
|
||||||
// TODO: get etag
|
executeMethod(getItemMethod);
|
||||||
// itemResult.etag = ???
|
itemResult.etag = getItemMethod.getResponseItem().get(Field.get("etag").getResponseName());
|
||||||
|
|
||||||
return itemResult;
|
return itemResult;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user