@Override
 public boolean hasData() {
   try {
     return !this.docStore.search(DATA_RETRIEVE_QUERY, 1, 0, this.context.get()).isEmpty();
   } catch (XWikiException ex) {
     this.logger.warn(
         "Failed to search for deleted attachments in the database trash: {}", ex.getMessage());
     return false;
   }
 }
 @Override
 public Iterator<EntityReference> listData() {
   try {
     List<Object[]> data = this.docStore.search(DATA_REFERENCE_QUERY, 0, 0, this.context.get());
     return new ReferenceIterator(data);
   } catch (XWikiException ex) {
     this.logger.warn("Failed to list the database deleted attachments: {}", ex.getMessage());
     return Collections.emptyIterator();
   }
 }
예제 #3
0
 /**
  * Trigger a BaseObject job (execute it now).
  *
  * @param object the BaseObject Job to be triggered
  * @return true on success, false on failure.
  */
 public boolean triggerJob(BaseObject object) {
   try {
     getProtectedPlugin().triggerJob(object, this.context);
     LOGGER.debug("Trigger Job: [{}]", object.getStringValue("jobName"));
     return true;
   } catch (XWikiException e) {
     this.context.put("error", e.getMessage());
     return false;
   }
 }
 public void addWriter(String spaceName, String userName, boolean allowDowngrade) {
   if (hasProgrammingRights()) {
     try {
       getWorkspacesManager().addWriter(spaceName, userName, allowDowngrade, context);
     } catch (XWikiException e) {
       context.put("haserror", "1");
       context.put("lasterror", e.getMessage());
     }
   }
 }
 /** Remove a reader from a workspace, removing him as a member too */
 public void removeReader(String spaceName, String userName) {
   if (hasProgrammingRights()) {
     try {
       getWorkspacesManager().removeReader(spaceName, userName, context);
     } catch (XWikiException e) {
       context.put("haserror", "1");
       context.put("lasterror", e.getMessage());
     }
   }
 }
 @Override
 public Iterator<DeletedAttachment> getData() {
   try {
     List<Long> data = this.docStore.search(DATA_RETRIEVE_QUERY, 0, 0, this.context.get());
     this.logger.debug("Found [{}] deleted attachments in the database trash", data.size());
     return new DeletedAttachmentIterator(data);
   } catch (XWikiException ex) {
     this.logger.warn(
         "Failed to get the list of database deleted attachments: {}", ex.getMessage());
     return Collections.emptyIterator();
   }
 }
 /**
  * Loops over the {@code rightsCombinations} and attaches a new rights object for each combination
  * to the document.
  *
  * @param rightsCombinations the string array containing all the combinations for which there
  *     should be an object created
  * @param rightsObjects the map of existing rights objects
  * @param doc XWikiDocument
  * @param context XWikiContext
  */
 private void createRights(
     List<String> rightsCombinations,
     Map<String, BaseObject> rightsObjects,
     XWikiDocument doc,
     XWikiContext context) {
   for (String rights : rightsCombinations) {
     try {
       BaseObject newRightObject = doc.newXObject(RIGHTS_CLASS, context);
       newRightObject.setStringValue("levels", rights);
       newRightObject.setIntValue("allow", 1);
       rightsObjects.put(rights, newRightObject);
     } catch (XWikiException ex) {
       this.logger.error("Failed to create rights: {}", ex.getMessage(), ex);
     }
   }
 }
 @Override
 public boolean discardAllData() {
   boolean transaction = false;
   try {
     transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get());
     Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get());
     session.createQuery("delete from DeletedAttachment").executeUpdate();
   } catch (XWikiException ex) {
     this.logger.warn(
         "Failed to cleanup all attachments from the database trash: {}", ex.getMessage());
     return false;
   } finally {
     if (transaction) {
       ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction);
     }
   }
   return true;
 }
 @Override
 public boolean discardEntity(DeletedAttachment entity) {
   boolean transaction = false;
   try {
     transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get());
     Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get());
     session.delete(entity);
     this.logger.debug(
         "Deleted deleted attachment [{}@{}#{}] from the database trash",
         entity.getDocName(),
         entity.getFilename(),
         entity.getId());
   } catch (XWikiException ex) {
     this.logger.warn("Failed to cleanup attachment from the database trash: {}", ex.getMessage());
     return false;
   } finally {
     if (transaction) {
       ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction);
     }
   }
   return true;
 }
  @Override
  public Representation represent(Variant variant) throws ResourceException {
    setupXWiki();

    Request request = getRequest();
    String assetName = (String) request.getAttributes().get("assetName");
    String textId = (String) request.getAttributes().get("textId");
    // if (!textId.equals("0")) {
    //    throw error(Status.CLIENT_ERROR_NOT_FOUND, "An asset may only have one viditalk movie");
    // }

    TextAsset asset = null;
    try {
      asset = (TextAsset) plugin.fetchAssetAs(assetName, TextAsset.class);
    } catch (XWikiException e) {
      throw error(Status.CLIENT_ERROR_NOT_FOUND, e.getMessage());
    }
    if (asset == null) {
      throw error(Status.CLIENT_ERROR_NOT_FOUND, "Asset " + assetName + " not found.");
    }

    String content = null;
    String syntax = null;
    try {
      content = asset.getText();
      syntax = asset.getTextSyntax();
    } catch (XWikiException e) {
      throw error(Status.CLIENT_ERROR_NOT_FOUND, "No texts found for " + assetName);
    }

    JSONObject json = new JSONObject();
    json.put("text", content);
    json.put("syntax", syntax);

    return formatJSON(json, variant);
  }