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);
long requiredSize = size - replacedSize;
requiredSize = requiredSize < 0 ? 0 : requiredSize;
checkRequiredSize(md, requiredSize);
}
LOGGER.debug("removing "+dbmd.getModuleInfoAsString());
removeModuleDescriptor(uak, String.valueOf(dbmd.getId()));
} else {
if (Visibility.PRIVATE.equals(md.getVisibility())) {
checkRequiredSize(md, size);
}
}
md.setSize(size);
LOGGER.debug("adding "+md.getModuleInfoAsString());
addModuleDescriptor(uak, zip, md);
LOGGER.info("Module: " + md + " replaced.");
} catch (IOException e) {
status.setRollbackOnly();
LOGGER.info("Cannot replace module for zip file : " + zip, e);