Methods Summary |
---|
private void | buildDynamicFeedElements(GDataRequest request, com.google.gdata.data.BaseFeed feed)
feed.setGenerator(generator);
feed.setItemsPerPage(request.getItemsPerPage());
feed.setStartIndex(request.getStartIndex());
feed.setId(request.getContextPath());
List<Link> links = feed.getLinks();
links.add(
buildLink(Link.Rel.SELF, Link.Type.ATOM, request.getSelfId()));
links.add(
buildLink(Link.Rel.NEXT, XMLMIME, request.getNextId()));
String prevLink = request.getPreviousId();
if(prevLink != null)
links.add(buildLink(Link.Rel.PREVIOUS,XMLMIME,prevLink));
|
private org.apache.lucene.gdata.data.ServerBaseEntry | buildEntry(GDataRequest request, GDataResponse response)
try {
ServerBaseEntry entry = new ServerBaseEntry(GDataEntityBuilder
.buildEntry(request));
return entry;
} catch (ParseException e) {
ServiceException ex = new ServiceException(
"Could not parse entry from incoming request", e, GDataResponse.BAD_REQUEST);
ex.setStackTrace(e.getStackTrace());
throw ex;
} catch (IOException e) {
ServiceException ex = new ServiceException(
"Could not read or open input stream", e, GDataResponse.BAD_REQUEST);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
|
private com.google.gdata.data.Link | buildLink(java.lang.String rel, java.lang.String type, java.lang.String href)
Link retVal = new Link();
retVal.setHref(href);
retVal.setRel(rel);
retVal.setType(type);
return retVal;
|
public void | close()
this.storage.close();
|
public com.google.gdata.data.BaseEntry | createEntry(GDataRequest request, GDataResponse response)
if (LOG.isInfoEnabled())
LOG.info("create Entry for feedId: " + request.getFeedId());
ServerBaseEntry entry = buildEntry(request, response);
entry.setFeedId(request.getFeedId());
entry.setServiceConfig(request.getConfigurator());
BaseEntry tempEntry = entry.getEntry();
tempEntry.setPublished(getCurrentDateTime());
tempEntry.setUpdated(getCurrentDateTime());
BaseEntry retVal = null;
removeDynamicElements(entry.getEntry());
try {
retVal = this.storage.storeEntry(entry);
} catch (Exception e) {
ServiceException ex = new ServiceException("Could not store entry",
e,GDataResponse.SERVER_ERROR);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
this.entryEventMediator.entryAdded(entry);
return retVal;
|
public com.google.gdata.data.BaseEntry | deleteEntry(GDataRequest request, GDataResponse response)
ServerBaseEntry entry = new ServerBaseEntry();
entry.setServiceConfig(request.getConfigurator());
entry.setFeedId(request.getFeedId());
entry.setId(request.getEntryId());
setVersionId(entry,request,response);
if (entry.getId() == null)
throw new ServiceException(
"entry id is null -- can not delete null entry",GDataResponse.SERVER_ERROR);
try {
this.storage.deleteEntry(entry);
} catch (ResourceNotFoundException e) {
ServiceException ex = new ServiceException(
"Could not delete entry", e,GDataResponse.BAD_REQUEST);
ex.setStackTrace(e.getStackTrace());
throw ex;
}catch (ModificationConflictException e) {
ServiceException ex = new ServiceException(
"Could not delete entry - version conflict",e, GDataResponse.CONFLICT);
ex.setStackTrace(e.getStackTrace());
throw ex;
}catch (StorageException e) {
ServiceException ex = new ServiceException(
"Could not delete entry", e,GDataResponse.SERVER_ERROR);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
this.entryEventMediator.entryDeleted(entry);
//TODO change ret value
return null;
|
private void | dynamicElementEntryStragey(com.google.gdata.data.BaseEntry entry, GDataRequest request)
setSelfLink(entry, request.getContextPath());
|
protected void | dynamicElementFeedStragey(com.google.gdata.data.BaseFeed feed, GDataRequest request)
buildDynamicFeedElements(request, feed);
List<BaseEntry> entryList = feed.getEntries();
for (BaseEntry entry : entryList) {
String id = new StringBuilder(request.getContextPath()).append(entry.getId()).append("/").toString();
setSelfLink(entry, id);
}
|
protected com.google.gdata.data.DateTime | getCurrentDateTime()
return new DateTime(System.currentTimeMillis(),0);
|
public java.util.Date | getEntryLastModified(java.lang.String entryId, java.lang.String feedId)
try {
return new Date(this.storage.getEntryLastModified(entryId, feedId));
} catch (StorageException e) {
ServiceException ex = new ServiceException(
"Could not get Last update for entry -- "+entryId, e, GDataResponse.SERVER_ERROR);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
|
public com.google.gdata.data.BaseFeed | getFeed(GDataRequest request, GDataResponse response)
ServerBaseFeed feed = new ServerBaseFeed();
feed.setId(request.getFeedId());
feed.setStartIndex(request.getStartIndex());
feed.setItemsPerPage(request.getItemsPerPage());
feed.setServiceConfig(request.getConfigurator());
try {
/*
* the strategy executes either a search or a direct access.
*/
BaseFeed retVal = this.storage.getFeed(feed);
dynamicElementFeedStragey(retVal, request);
return retVal;
/*
* Resource not found will be detected in Gdata request.
* the request queries the storage for the feed to get the service for the feed
*/
} catch (StorageException e) {
ServiceException ex = new ServiceException("Could not get feed", e,GDataResponse.NOT_FOUND);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
|
public java.util.Date | getFeedLastModified(java.lang.String feedId)
try {
return new Date(this.storage.getFeedLastModified(feedId));
} catch (StorageException e) {
ServiceException ex = new ServiceException(
"Could not get Last update for feed -- "+feedId, e, GDataResponse.SERVER_ERROR);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
|
public com.google.gdata.data.BaseEntry | getSingleEntry(GDataRequest request, GDataResponse response)
try {
ServerBaseEntry entry = new ServerBaseEntry();
entry.setServiceConfig(request.getConfigurator());
entry.setFeedId(request.getFeedId());
entry.setId(request.getEntryId());
if(entry.getId() == null){
throw new ServiceException("entry is null can't get entry", GDataResponse.BAD_REQUEST);
}
BaseEntry retVal = null;
retVal = this.storage.getEntry(entry);
dynamicElementEntryStragey(retVal, request);
return retVal;
} catch (ResourceNotFoundException e) {
ServiceException ex = new ServiceException(
"Could not get entry", e, GDataResponse.BAD_REQUEST);
ex.setStackTrace(e.getStackTrace());
throw ex;
} catch (StorageException e) {
ServiceException ex = new ServiceException("Could not get entry", e, GDataResponse.SERVER_ERROR);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
|
private void | removeDynamicElements(com.google.gdata.data.BaseEntry entry)
Link selfLink = entry.getSelfLink();
if(selfLink != null)
entry.getLinks().remove(selfLink);
Link editLink = entry.getEditLink();
if(editLink != null)
entry.getLinks().remove(editLink);
|
private com.google.gdata.data.BaseEntry | setSelfLink(com.google.gdata.data.BaseEntry entry, java.lang.String id)
Link self = buildLink(Link.Rel.SELF, XMLMIME, id);
StringBuilder builder = new StringBuilder(id);
builder.append(entry.getVersionId());
Link edit = buildLink(Link.Rel.ENTRY_EDIT,XMLMIME,builder.toString());
List<Link> list = entry.getLinks();
list.add(edit);
list.add(self);
return entry;
|
private org.apache.lucene.gdata.data.ServerBaseEntry | setVersionId(org.apache.lucene.gdata.data.ServerBaseEntry entry, GDataRequest request, GDataResponse response)
try{
entry.setVersion(Integer.parseInt(request.getEntryVersion()));
return entry;
}catch (Exception e) {
LOG.error("Can not parse entry version -- version is not an integer -- versionid: "+request.getEntryVersion(),e);
throw new ServiceException("Can not parse entry version -- version is not an integer -- versionid: "+request.getEntryVersion(),e, GDataResponse.BAD_REQUEST);
}
|
public com.google.gdata.data.BaseEntry | updateEntry(GDataRequest request, GDataResponse response)
ServerBaseEntry entry = buildEntry(request, response);
entry.setFeedId(request.getFeedId());
setVersionId(entry,request,response);
entry.setServiceConfig(request.getConfigurator());
if (LOG.isInfoEnabled())
LOG.info("update Entry" + entry.getId() + " for feedId: "
+ request.getFeedId());
if (entry.getId() == null) {
throw new ServiceException("Entry id is null can not update entry",GDataResponse.BAD_REQUEST);
}
if (!entry.getId().equals(request.getEntryId())) {
if (LOG.isInfoEnabled())
LOG
.info("Entry id in the entry xml does not match the requested resource -- XML-ID:"
+ entry.getId()
+ "; Requested resource: "
+ request.getEntryId());
throw new ServiceException(
"Entry id in the entry xml does not match the requested resource",GDataResponse.BAD_REQUEST);
}
BaseEntry tempEntry = entry.getEntry();
tempEntry.setUpdated(getCurrentDateTime());
removeDynamicElements(entry.getEntry());
BaseEntry retVal = null;
try {
retVal = this.storage.updateEntry(entry);
} catch (ResourceNotFoundException e) {
ServiceException ex = new ServiceException(
"Could not update entry", e,GDataResponse.BAD_REQUEST);
ex.setStackTrace(e.getStackTrace());
throw ex;
}catch (ModificationConflictException e) {
ServiceException ex = new ServiceException(
"Could not update entry - version conflict", e,GDataResponse.CONFLICT);
ex.setStackTrace(e.getStackTrace());
throw ex;
}catch (StorageException e) {
ServiceException ex = new ServiceException(
"Could not update entry", e,GDataResponse.SERVER_ERROR);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
this.entryEventMediator.entryUpdated(entry);
return retVal;
|