Package org.atomojo.app.client

Examples of org.atomojo.app.client.EntryClient


                  assertTrue(false);
               }
            } else {
               log.info("Updating entry in "+i);
               entry.setTitle("Updated "+entry.getTitle());
               EntryClient entryClient = feedClient.getEntryClient(entry);
               Status status = entryClient.update();
               if (!status.isSuccess()) {
                  log.info("Failure, status="+status.getCode());
               }
               assertTrue(status.isSuccess());
            }
View Full Code Here


                  assertTrue(false);
               }
            } else {
               log.info("Updating entry in "+i);
               entry.setTitle("Updated "+entry.getTitle());
               EntryClient entryClient = feedClient.getEntryClient(entry);
               status = entryClient.update();
               if (!status.isSuccess()) {
                  log.info("Failure, status="+status.getCode());
               }
               assertTrue(status.isSuccess());
            }
View Full Code Here

                     if (entry!=null) {
                        log.info("Updating "+file);
                        // update existing media
                        try {
                           FileInputStream is = new FileInputStream(file);
                           EntryClient client = feedClient.getEntryClient(entry);
                           status = client.updateMedia(new InputRepresentation(is,entry.getMediaContent().getMediaType()));
                           is.close();
                        } catch (IOException ex) {
                           log.log(Level.SEVERE,"Cannot update "+file+" due to I/O exception.",ex);
                        }
                        entries.remove(file.getName());
                     } else {
                        log.info("Creating "+file);
                        // create new media
                        try {
                           FileInputStream is = new FileInputStream(file);
                           int extPos = file.getName().lastIndexOf('.');
                           String ext = extPos<0 ? null : file.getName().substring(extPos+1);
                           Metadata metadata = ext==null ? null : metadataService.getMetadata(ext);
                           MediaType type = metadata==null ? MediaType.APPLICATION_OCTET_STREAM : MediaType.valueOf(metadata.getName());
                           Entry mediaEntry = feedClient.createMedia(file.getName(),new InputRepresentation(is,type));
                           is.close();
                        } catch (StatusException ex) {
                           log.log(Level.SEVERE,"Cannot create media entry from "+file+" due to status "+ex.getStatus().getCode(),ex);
                        } catch (Exception ex) {
                           log.log(Level.SEVERE,"Cannot create media entry from "+file+" due to exception.",ex);
                        }
                     }
                     if (status!=null && !status.isSuccess()) {
                        log.severe("Cannot update/create media entry for "+file+" due to status "+status.getCode());
                     }
                  }
               }
               return false;
            }
         });
         if (exact) {
            for (Entry entry : entries.values()) {
               EntryClient client = feedClient.getEntryClient(entry);
               Status status = client.delete();
               if (!status.isSuccess()) {
                  log.severe("Cannot delete extra entry "+entry.getId()+" due to status "+status.getCode());
               }
            }
         }
View Full Code Here

                  log.severe("Ignoring entry with bad UUID: "+entry.getId());
                  errorCount++;
                  return;
               }
               log.info("Entry: "+entryId);
               EntryClient entryClient = new EntryClient(new Reference(targetClient.getEntryLocation(entryId).toString()),target.getIdentity());
               String src = null;
               Element content = entryDoc.getDocumentElement().getFirstElementNamed(CONTENT_NAME);
               URI baseURI = null;
               MediaType contentType = null;
               if (content!=null) {
                  src = content.getAttributeValue("src");
                  String type = content.getAttributeValue("type");
                  if (type!=null) {
                     contentType = MediaType.valueOf(type);
                  }
                  baseURI = content.getBaseURI();
               }
               if (entries!=null) {
                  entries.add(entryId);
               }
              
               Status exists = null;
               try {
                  exists = entryClient.get();
               } catch (Exception ex) {
                  log.log(Level.SEVERE,"Cannot get entry "+entryClient.getLocation()+", error: "+ex.getMessage(),ex);
                  errorCount++;
                  return;
               }
               if (exists.isSuccess()) {
                  entryClient.getEntry().index();
                  try {
                    
                     Status status = entryClient.update(entryDoc);
                     if (!status.isSuccess()) {
                        log.severe("Cannot update entry "+entryClient.getLocation()+", status="+status.getCode());
                        errorCount++;
                     }
                  } catch (Exception ex) {
                     log.log(Level.SEVERE,"Cannot update entry "+entryClient.getLocation()+", error: "+ex.getMessage(),ex);
                     errorCount++;
                  }
                  if (src!=null) {
                     // update media
                     Reference mediaLocation = new Reference(baseURI.resolve(src).toString());
                     Client client = new Client(mediaLocation.getSchemeProtocol());
                     Request getRequest = new Request(Method.GET,mediaLocation);
                     if (source.getIdentity()!=null) {
                        getRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,source.getUsername(),source.getPassword()));
                     }
                     Response getResponse = client.handle(getRequest);
                     if (getResponse.getStatus().isSuccess()) {
                        Reference targetLocation = new Reference(targetClient.getLocation().resolve(src).toString());
                        Client targetClient = new Client(targetLocation.getSchemeProtocol());
                        Request putRequest = new Request(Method.PUT,targetLocation);
                        if (target.getIdentity()!=null) {
                           putRequest.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,target.getUsername(),target.getPassword()));
                        }
                        Representation rep = getResponse.getEntity();
                        if (contentType!=null) {
                           rep.setMediaType(contentType);
                        }
                        putRequest.setEntity(rep);
                        Response putResponse = targetClient.handle(putRequest);
                        if (!putResponse.getStatus().isSuccess()) {
                           log.severe("Cannot put media update to "+targetLocation+", status="+putResponse.getStatus().getCode());
                        }
                     } else {
                        if (!getResponse.getStatus().isSuccess()) {
                           log.severe("Cannot get media from "+mediaLocation+", status="+getResponse.getStatus().getCode());
                        }
                     }
                  }
               } else if (exists.getCode()==Status.CLIENT_ERROR_NOT_FOUND.getCode()) {
                  if (src==null) {
                     // regular entry
                     try {
                        targetClient.createEntry(entryDoc);
                     } catch (StatusException ex) {
                        log.severe("Cannot create entry "+entryClient.getLocation()+", status="+ex.getStatus().getCode());
                        errorCount++;
                     } catch (Exception ex) {
                        log.log(Level.SEVERE,"Cannot create entry "+entryClient.getLocation()+", error: "+ex.getMessage(),ex);
                        errorCount++;
                     }
                  } else {
                     // media entry
                     Reference mediaLocation = new Reference(baseURI.resolve(src).toString());
                     Client client = new Client(mediaLocation.getSchemeProtocol());
                     Request request = new Request(Method.GET,mediaLocation);
                     if (source.getIdentity()!=null) {
                        request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,source.getUsername(),source.getPassword()));
                     }
                     Response response = client.handle(request);
                     if (response.getStatus().isSuccess()) {
                        try {
                           Representation rep = response.getEntity();
                           if (contentType!=null) {
                              rep.setMediaType(contentType);
                           }
                           Entry mediaEntry = targetClient.createMedia(entryId, src, rep);
                           entryClient.setEntry(mediaEntry);
                           try {
                              Status status = entryClient.update(entryDoc);
                              if (!status.isSuccess()) {
                                 log.severe("Cannot update entry "+entryClient.getLocation()+", status="+status.getCode());
                                 errorCount++;
                              }
                           } catch (Exception ex) {
                              log.log(Level.SEVERE,"Cannot update entry "+entryClient.getLocation()+", error: "+ex.getMessage(),ex);
                              errorCount++;
                           }
                        } catch (StatusException ex) {
                           log.severe("Cannot create media resource "+src+", status="+ex.getStatus().getCode());
                           errorCount++;
                        } catch (Exception ex) {
                           log.log(Level.SEVERE,"Cannot create media resource "+src+", error: "+ex.getMessage(),ex);
                           errorCount++;
                        }
                     } else {
                        log.severe("Cannot get media resource "+mediaLocation+", status="+response.getStatus().getCode());
                        errorCount++;
                     }
                  }
               } else {
                  log.severe("Cannot check entry "+entryClient.getLocation()+", status="+exists.getCode());
                  errorCount++;
               }
            }
            public void onEnd() {
               if (additive || !ok) {
View Full Code Here

TOP

Related Classes of org.atomojo.app.client.EntryClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.