Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA-15375: Add deletePropertiesBatch method #472

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2002-2022 Jahia Solutions Group SA. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jahia.modules.graphql.provider.dxm.node;

import graphql.annotations.annotationTypes.GraphQLDescription;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import graphql.annotations.annotationTypes.GraphQLNonNull;

@GraphQLName("JCRDeletedProperty")
@GraphQLDescription("GraphQL representation of a deleted JCR property")
public class GqlJcrDeletedPropertyInput {
protected String name;
protected String language;

public GqlJcrDeletedPropertyInput(@GraphQLName("name") @GraphQLNonNull @GraphQLDescription("The name of the property to delete") String name,
@GraphQLName("language") @GraphQLNonNull @GraphQLDescription("The language in which the property will be deleted") String language) {
this.name = name;
this.language = language;
}

@GraphQLField
@GraphQLName("name")
@GraphQLNonNull
@GraphQLDescription("The name of the property to delete")
public String getName() {
return name;
}

@GraphQLField
@GraphQLName("language")
@GraphQLNonNull
@GraphQLDescription("The language in which the property will be deleted")
public String getLanguage() {
return language;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,29 @@ public static List<JCRPropertyWrapper> setProperties(JCRNodeWrapper node, Collec
}
}

/**
* Delete the provided properties to the specified node.
*
* @param node The JCR node to delete properties from
* @param properties the collection of properties to be deleted
* @return Boolean
*/
public static boolean deleteProperties(JCRNodeWrapper node, Collection<GqlJcrDeletedPropertyInput> properties) {
if (properties == null) {
return false;
}

for (GqlJcrDeletedPropertyInput prop : properties) {
try {
NodeHelper.getNodeInLanguage(node, prop.getLanguage()).getProperty(prop.getName()).remove();
gflores-jahia marked this conversation as resolved.
Show resolved Hide resolved
} catch (RepositoryException e) {
throw new DataFetchingException(e);
}
}

return true;
}

/**
* Retrieve the specified JCR node by its path or UUID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ public GqlJcrPropertyMutation mutateProperty(@GraphQLName("name") @GraphQLNonNul
return names.stream().map((String name) -> new GqlJcrPropertyMutation(jcrNode, name)).collect(Collectors.toList());
}

/**
* Performs batch-delete of the specified properties on the JCR node.
*
* @param properties the collection of properties to be deleted
* @return Boolean
* @throws BaseGqlClientException in case of modification errors
*/
@GraphQLField
@GraphQLName("deletePropertiesBatch")
@GraphQLDescription("Deletes a set of properties on the current node")
public Boolean deletePropertiesBatch(@GraphQLName("properties") @GraphQLDescription("The collection of JCR properties: name and language") Collection<GqlJcrDeletedPropertyInput> properties) {
return deleteProperties(jcrNode, properties);
}

/**
* Performs batch-set of the specified properties on the JCR node.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static JCRNodeWrapper getNodeInLanguage(JCRNodeWrapper node, String langu
String workspace = node.getSession().getWorkspace().getName();
if (language == null) {
if (node.getLanguage() != null) {
JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(workspace);
JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(workspace, Locale.forLanguageTag(node.getLanguage()));
return session.getNodeByIdentifier(node.getIdentifier());
}
return node;
Expand Down
Loading