java/code/src/com/redhat/rhn/domain/config/ConfigContent.java | 34 ++++++++++ java/code/src/com/redhat/rhn/domain/config/ConfigRevision.java | 13 +++ java/code/src/com/redhat/rhn/manager/configuration/ConfigFileBuilder.java | 17 +++-- 3 files changed, 57 insertions(+), 7 deletions(-)
New commits: commit e23d86a2bf8df74a960e5d151d0cbf912f20dac2 Author: Tomas Lestach tlestach@redhat.com Date: Thu Oct 27 17:09:03 2011 +0200
593300 - do not create same revision as the last one
in case the same content gets uploaded using configchannel.createOrUpdatePath API
diff --git a/java/code/src/com/redhat/rhn/domain/config/ConfigContent.java b/java/code/src/com/redhat/rhn/domain/config/ConfigContent.java index e0e5adb..cfd507f 100644 --- a/java/code/src/com/redhat/rhn/domain/config/ConfigContent.java +++ b/java/code/src/com/redhat/rhn/domain/config/ConfigContent.java @@ -18,6 +18,9 @@ import com.redhat.rhn.common.hibernate.HibernateFactory; import com.redhat.rhn.domain.BaseDomainHelper; import com.redhat.rhn.domain.common.Checksum;
+import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + /** * ConfigContent - Class representation of the table rhnConfigContent. * @version $Rev$ @@ -161,4 +164,35 @@ public class ConfigContent extends BaseDomainHelper { public void setDelimEnd(String delimEndIn) { this.delimEnd = delimEndIn; } + + /** + * + * {@inheritDoc} + */ + public int hashCode() { + return new HashCodeBuilder() + .append(this.getChecksum()) + .append(this.getContents()) + .append(this.getDelimStart()) + .append(this.getDelimEnd()) + .append(this.isBinary()) + .toHashCode(); + } + + /** + * + * {@inheritDoc} + */ + public boolean equals(Object object) { + if (object == null || !(object instanceof ConfigContent)) { + return false; + } + ConfigContent that = (ConfigContent) object; + return new EqualsBuilder() + .append(this.getChecksum(), that.getChecksum()) + .append(this.isBinary(), that.isBinary()) + .append(this.getDelimStart(), that.getDelimStart()) + .append(this.getDelimEnd(), that.getDelimEnd()) + .isEquals(); + } } diff --git a/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.java b/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.java index 4007259..48faf5e 100644 --- a/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.java +++ b/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.java @@ -17,7 +17,6 @@ package com.redhat.rhn.domain.config; import com.redhat.rhn.domain.BaseDomainHelper; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.domain.user.UserFactory; - import java.util.Date;
/** @@ -196,4 +195,16 @@ public class ConfigRevision extends BaseDomainHelper { public boolean isSymlink() { return (configFileType != null && configFileType.getLabel().equals("symlink")); } + + /** + * does the revision match to the other config revision + * @param other the other revision + * @return True if matches + */ + public boolean matches(ConfigRevision other) { + return configFile.equals(other.getConfigFile()) && + configContent.equals(other.getConfigContent()) && + configFileType.equals(other.getConfigFileType()) && + configInfo.equals(other.getConfigInfo()); + } } diff --git a/java/code/src/com/redhat/rhn/manager/configuration/ConfigFileBuilder.java b/java/code/src/com/redhat/rhn/manager/configuration/ConfigFileBuilder.java index 06f31e8..3f49b92 100644 --- a/java/code/src/com/redhat/rhn/manager/configuration/ConfigFileBuilder.java +++ b/java/code/src/com/redhat/rhn/manager/configuration/ConfigFileBuilder.java @@ -126,6 +126,7 @@ public class ConfigFileBuilder { ConfigFile cf, boolean onCreate) {
ConfigurationManager manager = ConfigurationManager.getInstance(); + ConfigRevision prevRevision = cf.getLatestConfigRevision(); ConfigRevision revision;
if (onCreate) { @@ -159,8 +160,7 @@ public class ConfigFileBuilder { revision.getConfigContent().setBinary(form.isBinary()); if (form.isBinary()) { // copy delims from the previous revision - ConfigContent prevContent = cf.getLatestConfigRevision(). - getConfigContent(); + ConfigContent prevContent = prevRevision.getConfigContent(); revision.getConfigContent().setDelimStart(prevContent.getDelimStart()); revision.getConfigContent().setDelimEnd(prevContent.getDelimEnd()); } @@ -177,6 +177,10 @@ public class ConfigFileBuilder { revision.setRevision(Long.parseLong(form.getRevNumber())); }
+ if (!onCreate && revision.matches(prevRevision)) { + ConfigurationFactory.removeConfigRevision(revision, user.getOrg().getId()); + return prevRevision; + } // Committing the revision commits the file for us (which commits the // Channel, so everybody's pointers get updated...) ConfigurationFactory.commit(revision); @@ -198,10 +202,11 @@ public class ConfigFileBuilder { throws ValidatorException { form.validatePath(); ValidatorResult result; - if (!form.getType().equals(file.getLatestConfigRevision().getConfigFileType())) { + ConfigRevision latestRevision = file.getLatestConfigRevision(); + if (!form.getType().equals(latestRevision.getConfigFileType())) {
LocalizationService ls = LocalizationService.getInstance(); - String fromType = ls.getMessage(file.getLatestConfigRevision(). + String fromType = ls.getMessage(latestRevision. getConfigFileType().getMessageKey()); String toType = ls.getMessage(form.getType().getMessageKey()); ValidatorException.raiseException("error.config-cannot-change-type", @@ -211,7 +216,7 @@ public class ConfigFileBuilder { try { if (!StringUtils.isBlank(form.getRevNumber())) { Long l = Long.parseLong(form.getRevNumber()); - if (l.longValue() <= file.getLatestConfigRevision().getRevision()) { + if (l.longValue() <= latestRevision.getRevision()) { result = new ValidatorResult(); result.addError(new ValidatorError("error.config.revnum.too-old", form.getPath())); @@ -220,7 +225,7 @@ public class ConfigFileBuilder { } else { form.setRevNumber(String.valueOf( - file.getLatestConfigRevision().getRevision() + 1)); + latestRevision.getRevision() + 1)); } } catch (NumberFormatException nfe) {
spacewalk-commits@lists.fedorahosted.org