Skip to content

Commit

Permalink
modified in storage layer
Browse files Browse the repository at this point in the history
  • Loading branch information
renjingxiao committed Sep 27, 2023
1 parent 87cc209 commit e073fa7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.apicurio.registry.rest.v2;

import com.google.common.hash.Hashing;
Expand Down Expand Up @@ -44,7 +44,6 @@
import io.apicurio.registry.utils.ArtifactIdValidator;
import io.apicurio.registry.utils.IoUtil;
import io.apicurio.registry.utils.JAXRSClientUtil;
import io.apicurio.tenantmanager.api.datamodel.SortBy;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -468,12 +467,7 @@ public void updateArtifactState(String groupId, String artifactId, UpdateState d
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("body.state", data.getState());

ArtifactMetaDataDto metaData = storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);

if (!metaData.getState().equals(data.getState())) {
storage.updateArtifactState(defaultGroupIdToNull(groupId), artifactId, data.getState());
}
storage.updateArtifactState(defaultGroupIdToNull(groupId), artifactId, data.getState());
}

/**
Expand Down Expand Up @@ -665,12 +659,8 @@ public void updateArtifactVersionState(String groupId, String artifactId, String
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);

ArtifactMetaDataDto metaData = storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);

if (!metaData.getState().equals(data.getState())) {
storage.updateArtifactState(defaultGroupIdToNull(groupId), artifactId, version, data.getState());
}
storage.updateArtifactState(defaultGroupIdToNull(groupId), artifactId, version, data.getState());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,15 @@ public void updateArtifactState(String groupId, String artifactId, String versio
/**
* IMPORTANT: Private methods can't be @Transactional. Callers MUST have started a transaction.
*/
private void updateArtifactVersionStateRaw(long globalId, ArtifactState oldState, ArtifactState newState)
throws VersionNotFoundException {
private void updateArtifactVersionStateRaw(long globalId, ArtifactState oldState, ArtifactState newState){
handles.withHandleNoException(handle -> {
if (oldState != newState) {
artifactStateEx.applyState(s -> {
int rowCount = handle.createUpdate(sqlStatements.updateArtifactVersionState())
handle.createUpdate(sqlStatements.updateArtifactVersionState())
.bind(0, s.name())
.bind(1, tenantContext.tenantId())
.bind(2, globalId)
.execute();
if (rowCount == 0) {
throw new VersionNotFoundException(globalId);
}
}, oldState, newState);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@

import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.rest.client.exception.RuleViolationException;
import io.apicurio.registry.rest.v1.beans.UpdateState;
import io.apicurio.registry.rest.v2.beans.ArtifactOwner;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
Expand All @@ -74,7 +73,6 @@
import io.apicurio.registry.rest.v2.beans.UpdateState;
import io.apicurio.registry.rest.v2.beans.VersionMetaData;
import io.apicurio.registry.rules.compatibility.jsonschema.diff.DiffType;
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
import io.apicurio.registry.storage.impl.sql.SqlUtil;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.ReferenceType;
Expand Down Expand Up @@ -677,7 +675,7 @@ public void testUpdateArtifactState() throws Exception {
.put("/registry/v2/groups/{groupId}/artifacts/{artifactId}/state")
.then()
.statusCode(204);

// Update the artifact state to DEPRECATED again.
given()
.when()
Expand All @@ -688,7 +686,7 @@ public void testUpdateArtifactState() throws Exception {
.put("/registry/v2/groups/{groupId}/artifacts/{artifactId}/state")
.then()
.statusCode(204);

// Send a GET request to check if the artifact state is DEPRECATED.
given()
.when()
Expand All @@ -709,7 +707,7 @@ public void testUpdateArtifactVersionState() throws Exception {
UpdateState updateState = new UpdateState();
updateState.setState(ArtifactState.DEPRECATED);

// Make sure we can get the artifact content
// Update the artifact state to DEPRECATED.
given()
.when()
.contentType(CT_JSON)
Expand All @@ -720,7 +718,7 @@ public void testUpdateArtifactVersionState() throws Exception {
.put("/registry/v2/groups/{groupId}/artifacts/{artifactId}/versions/{versionId}/state")
.then()
.statusCode(204);

// Update the artifact state to DEPRECATED again.
given()
.when()
Expand All @@ -732,7 +730,7 @@ public void testUpdateArtifactVersionState() throws Exception {
.put("/registry/v2/groups/{groupId}/artifacts/{artifactId}/versions/{versionId}/state")
.then()
.statusCode(204);

// Send a GET request to check if the artifact state is DEPRECATED.
given()
.when()
Expand Down

0 comments on commit e073fa7

Please sign in to comment.