Package org.jayasoft.woj.server.data

Examples of org.jayasoft.woj.server.data.ModuleDescriptorDao



  private void unThreadedUpdate(final File zip) {
    LOGGER.info(" - Updating from ZIP");
    WOJServer server = WOJServer.getInstance();
    ModuleDescriptorDao mDao = server.getDataService().getModuleDescriptorDao();
    try {
     
      // Unzip file
      LOGGER.debug(" -- Extracting zip : " + zip.getName());
      ZipHelper.extract(zip, "", getFileContentService().getBaseDir());
      LOGGER.debug(" -- Extraction done");
     
      // Get dmp file
      File dir = new File(getFileContentService().getBaseDir());
      File[] dumps = dir.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
          return name.endsWith(".dmp");
        }
      });
      if (dumps.length != 0) {
        File dumpFile = dumps[0];
        LOGGER.debug(" -- Parsing dump file : " + dumpFile.getName());
        String dump = IOHelper.readEntirely(dumpFile);
        String[] sqlLines = dump.split(";\n");
        for (int i = 0; i < sqlLines.length; i++) {
          String sqlLine = sqlLines[i];
          // Replacing query params bu server id if necessary
          sqlLine = SQLUtil.setValues(sqlLine, new Object[] {new Long(server.getId())});
          try {
            mDao.getJdbcTemplate().execute(sqlLine);
          } catch (DataIntegrityViolationException e) {
            LOGGER.warn(" -- Update file contains modules already updated, skipping it.", e);
          }
        }
        dumpFile.delete();
View Full Code Here


        setLastUsedMrid(getConfiguration().getLong(MODULE_ID_LAST_USED, -1));
        setReservedUntil(getConfiguration().getLong(MODULE_ID_RESERVED_UNTIL, -1));
    }
   
    public ModuleDescriptor getModuleDescriptor(UAK uak, Visibility v, String org, String mod, String rev) {
        final ModuleDescriptorDao dao = WOJServer.getInstance().getDataService().getModuleDescriptorDao();
        ModuleDescriptorImpl moduleDescriptor = (ModuleDescriptorImpl)dao.getModuleDescriptor(org, mod, rev, uak.getUserId(), uak.getGroups(), v);
        if (moduleDescriptor == null) {
            return null;
        }
        moduleDescriptor.setSize(WOJServer.getInstance().getContentService().getUsedSpace(moduleDescriptor));
        return moduleDescriptor;
View Full Code Here

        moduleDescriptor.setSize(WOJServer.getInstance().getContentService().getUsedSpace(moduleDescriptor));
        return moduleDescriptor;
    }
   
    public void updateModuleDescriptors(final ModuleDescriptor[] mds) {
        final ModuleDescriptorDao dao = WOJServer.getInstance().getDataService().getModuleDescriptorDao();
        TransactionTemplate tt = dao.getTransactionTemplate();
        tt.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                for (int i = 0; i < mds.length; i++) {
                    if (mds[i].isDeleted()) {
                        LOGGER.debug("updating "+mds[i]+": deleting");
                        try {
                            dao.removeModuleDescriptor(mds[i]);
                        } catch (Exception ex) {
                            // this can be normal if the module were not previously in our db
                            LOGGER.debug("module not deleted: "+mds[i]+": message="+ ex.getMessage());
                        }
                    } else {
                        LOGGER.debug("updating "+mds[i]);
                        dao.fullUpdateModule(mds[i]);
                    }
                }
            }
        });
    }
View Full Code Here

            }
        });
    }
 
    public void addModuleDescriptor(final File zip, final UAK uak) {
        final ModuleDescriptorDao dao = WOJServer.getInstance().getDataService().getModuleDescriptorDao();
        TransactionTemplate tt = dao.getTransactionTemplate();
        tt.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                try {
                    LOGGER.debug("Adding Module from zip file: "+zip);
                    checkZipFile(zip);
View Full Code Here

            }
        });
    }

    public void replaceModule(final File zip, final UAK uak) {
        final ModuleDescriptorDao dao = WOJServer.getInstance().getDataService().getModuleDescriptorDao();
        TransactionTemplate tt = dao.getTransactionTemplate();
        tt.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                try {
                    LOGGER.debug("Replacing Module from zip file: "+zip);
                    checkZipFile(zip);
                    LOGGER.debug("Zip file successfully checked");
                    URL contentUrl = new URL("jar:"+zip.toURL()+"!/"+Parameters.MODULE_DESCRIPTOR_FILE_NAME);
                    String xmlContent = IOHelper.readEntirely(new BufferedReader(new InputStreamReader(contentUrl.openStream())));
                    LOGGER.debug("Xml descriptor entirely read");
                    ModuleDescriptorImpl md = (ModuleDescriptorImpl)ServiceProvider.getDefault().getEncodingService().decode(xmlContent);
                    LOGGER.debug("Xml descriptor decoded in a ModuleDescriptor: "+md.getModuleInfoAsString());
                    checkModuleDescriptor(md);
                    LOGGER.debug("ModuleDescriptor successfully checked");
                    // check if user has right to publish at given visibility
                    if (uak.getPublishVisibilityRight().getId() < md.getVisibility().getId()) {
                        LOGGER.error("Impossible to publish to visibility: "+md.getVisibility()+" for user: " +uak.getUserName());
                        throw new UnauthorizedException(uak, "publish to visibility "+md.getVisibility());
                    }

                    ModuleDescriptorDao dao = WOJServer.getInstance().getDataService().getModuleDescriptorDao();
                    ModuleDescriptor dbmd = dao.getModuleDescriptor(md.getOrganisation(), md.getModule(), md.getRevision(), uak.getUserId(), uak.getGroups(), md.getVisibility());
                    long size = computeModuleSize(zip);
                    if (dbmd != null) {
                        if (Visibility.PRIVATE.equals(md.getVisibility())) {
                            //TODO: mutex to avoid unauthorized adding
                            long replacedSize = WOJServer.getInstance().getContentService().getUsedSpace(dbmd);
View Full Code Here

        registerModule(WOJServer.getInstance().getServer(), md);
  }

    protected void insertModuleDescriptor(UAK uak, ModuleDescriptor md) {
        // DB add
        ModuleDescriptorDao dao= WOJServer.getInstance().getDataService().getModuleDescriptorDao();
        String[] md5s = (String[])md.getMD5s().toArray(new String[md.getMD5s().size()]);
        String[] sha1s = (String[])md.getSHA1s().toArray(new String[md.getSHA1s().size()]);
        boolean inserted = false;
        int attempt = 0;
        do {
            try {
                dao.insert(uak, md, md5s, sha1s);
                inserted = true;
            } catch (RuntimeException ex) {
                if (ex.getMessage().indexOf("Duplicate entry '"+md.getId()+"' for key 1") != -1) {
                    attempt++;
                    if (attempt > 10) {
View Full Code Here

      String mod_rev,
      Long creator_id,
      List all_groups,
      int visibility) {
   
        ModuleDescriptorDao dao= WOJServer.getInstance().getDataService().getModuleDescriptorDao();
        ModuleDescriptor result = dao.getModuleDescriptor(mod_org, mod_name, mod_rev, creator_id, all_groups, Visibility.fromInt(visibility));
        if (result == null) {
            result = newModuleDescriptor(uak, mod_org, mod_name, mod_rev, creator_id, visibility);
        }
        return result;
  }
View Full Code Here

        }
        return result;
  }

    private ModuleDescriptor newModuleDescriptor(UAK uak, String mod_org, String mod_name, String mod_rev, Long creator_id, int visibility) {
        ModuleDescriptorDao dao = WOJServer.getInstance().getDataService().getModuleDescriptorDao();
        long mrid = getNewMrid(uak);
        return (ModuleDescriptor)dao.create(mrid, creator_id, mod_org, mod_name, mod_rev, Visibility.fromInt(visibility));
    }
View Full Code Here

    }

    public void promoteModuleDescriptorVisibility(String mdId, String visibility) {
        LOGGER.debug("Asking promotion of module: " + mdId + " to " + visibility);
    Visibility newVisibility = Visibility.fromString(visibility);
    ModuleDescriptorDao dao = WOJServer.getInstance().getDataService().getModuleDescriptorDao();
    ModuleDescriptor md = dao.getModule(mdId);
    Visibility oldVisibility = md.getVisibility();
    Long oldAccessorId = md.getAccessorId();
    if (oldVisibility != Visibility.SANDBOX) {
      String msg = md.getModuleInfoAsString() + "cannot be promoted it's not in SANDBOX visibility, it may already have been promoted";
      LOGGER.warn(msg);
      throw new IllegalArgumentException(msg);
    } else {
      dao.promoteModuleDescriptorVisibility(md, newVisibility);
      WOJServer.getInstance().getContentService().refreshContentForModuleDescriptorVisibilityPromotion(md, oldAccessorId, oldVisibility);
     
      // Notification
      notifyModulePromoted(WOJServer.getInstance(), md, newVisibility);
          LOGGER.info("Module: " + md.getModuleInfoAsString() + "has been promoted to " + newVisibility);
View Full Code Here

  protected abstract void notifyModulePromoted(WOJServer instance, ModuleDescriptor md, Visibility newVisibility);

  public void removeModuleDescriptor(UAK uak, String mdId) {
        LOGGER.debug("Asking deletion of module: " + mdId);
    ModuleDescriptorDao dao = WOJServer.getInstance().getDataService().getModuleDescriptorDao();
    ModuleDescriptor md = dao.getModule(mdId);
    if (md != null) {
            if (!isVisibleFor(md, uak) && !uak.isAdmin()) {
                LOGGER.info("can't remove module: " + md.getModuleInfoAsString()+": not visible for "+uak);
                throw new UnauthorizedException(uak, "delete "+md.getModuleInfoAsString());
            }
            if (uak.getPublishVisibilityRight().getId() < md.getVisibility().getId()) {
                LOGGER.info("can't remove module: " + md.getModuleInfoAsString()+": no sufficient rights");
                throw new UnauthorizedException(uak, "delete "+md.getModuleInfoAsString());
            }
      dao.removeModuleDescriptor(md);
      WOJServer.getInstance().getContentService().refrechContentForModuleDescriptorDeletion(md);
      // Notification
      notifyModuleRemoved(md);
          LOGGER.info("Module: " + md.getModuleInfoAsString() + "has been deleted");
    } else {
View Full Code Here

TOP

Related Classes of org.jayasoft.woj.server.data.ModuleDescriptorDao

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.