}
});
}
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);