Skip to content

Commit

Permalink
Merge pull request #171 from contentful/feature/bulk_actions
Browse files Browse the repository at this point in the history
feat: Buld actions support
  • Loading branch information
rafalniski committed Mar 12, 2024
2 parents 59cd693 + fd418e7 commit ff57142
Show file tree
Hide file tree
Showing 14 changed files with 823 additions and 28 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/contentful/java/cma/CMAClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

//BEGIN TO LONG CODE LINES

import com.contentful.java.cma.gson.CMASystemDeserializer;
import com.contentful.java.cma.gson.EntrySerializer;
import com.contentful.java.cma.gson.FieldTypeAdapter;
import com.contentful.java.cma.gson.LocaleSerializer;
Expand All @@ -38,6 +39,7 @@
import com.contentful.java.cma.model.CMAField;
import com.contentful.java.cma.model.CMALocale;
import com.contentful.java.cma.model.CMASnapshot;
import com.contentful.java.cma.model.CMASystem;
import com.contentful.java.cma.model.CMAWebhookTransformation;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -72,6 +74,8 @@ public class CMAClient {
// Modules
private final ModuleApiKeys moduleApiKeys;
private final ModuleAssets moduleAssets;

private final ModuleBulkActions moduleBulkActions;
private final ModuleContentTypes moduleContentTypes;
private final ModuleEditorInterfaces moduleEditorInterfaces;
private final ModuleEntries moduleEntries;
Expand Down Expand Up @@ -135,6 +139,8 @@ private CMAClient(Builder cmaBuilder) {
configured);
this.moduleAssets = new ModuleAssets(retrofit, callbackExecutor, spaceId, environmentId,
configured);
this.moduleBulkActions = new ModuleBulkActions(retrofit, callbackExecutor,
spaceId, environmentId, configured);
this.moduleContentTypes = new ModuleContentTypes(retrofit, callbackExecutor, spaceId,
environmentId, configured);
this.moduleEditorInterfaces = new ModuleEditorInterfaces(retrofit, callbackExecutor, spaceId,
Expand Down Expand Up @@ -181,6 +187,7 @@ static Gson createGson() {
.registerTypeAdapter(CMASnapshot.class, new SnapshotDeserializer())
.registerTypeAdapter(CMAWebhookTransformation.class, new WebHookBodyDeserializer())
.registerTypeAdapter(CMALocale.class, new LocaleSerializer())
.registerTypeAdapter(CMASystem.class, new CMASystemDeserializer())
.create();
}

Expand Down Expand Up @@ -348,6 +355,13 @@ public ModuleTags tags() {
return moduleTags;
}

/**
* @return the Bulk Actions module.
*/
public ModuleBulkActions bulkActions() {
return moduleBulkActions;
}


/**
* Builder.
Expand Down
221 changes: 221 additions & 0 deletions src/main/java/com/contentful/java/cma/ModuleBulkActions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/*
* Copyright (C) 2021 Contentful GmbH
*
* 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 com.contentful.java.cma;

import com.contentful.java.cma.RxExtensions.DefFunc;
import com.contentful.java.cma.model.CMABulkAction;
import com.contentful.java.cma.model.CMAPayload;
import retrofit2.Retrofit;

import java.util.concurrent.Executor;

/**
* Bulk actions Module.
*/
public class ModuleBulkActions extends AbsModule<ServiceBulkActions> {
final Async async;

/**
* Create bulk actions module.
*
* @param retrofit the retrofit instance to be used to create the service.
* @param callbackExecutor to tell on which thread it should run.
* @param spaceId the space to be used when not given.
* @param environmentId the environment to be used when not given.
* @param environmentIdConfigured internal helper to see if environment was set.
*/
public ModuleBulkActions(
Retrofit retrofit,
Executor callbackExecutor,
String spaceId,
String environmentId,
boolean environmentIdConfigured) {
super(retrofit, callbackExecutor, spaceId, environmentId, environmentIdConfigured);
this.async = new Async();
}

@Override
protected ServiceBulkActions createService(Retrofit retrofit) {
return retrofit.create(ServiceBulkActions.class);
}

/**
* Fetch a bulk action using the given bulkActionId.
*
* @return {@link CMABulkAction} result instance
* @throws IllegalArgumentException if space id is null.
*/
public CMABulkAction fetch(String spaceId,
String environmentId,
String bulkActionId) {
assertNotNull(spaceId, "spaceId");
assertNotNull(bulkActionId, "bulkActionId");

return service.fetch(spaceId, environmentId, bulkActionId).blockingFirst();
}

/**
* Publish a bulk action.
*
* @return {@link CMABulkAction} result instance
* @throws IllegalArgumentException if spaceId's space id is null.
* @throws IllegalArgumentException if payload's id is null.
*/
public CMABulkAction publish(String spaceId,
String environmentId,
CMAPayload payload) {
assertNotNull(spaceId, "spaceId");
assertNotNull(payload, "payload");

return service.publish(spaceId, environmentId, payload).blockingFirst();
}

/**
* Unpublish a bulk action.
*
* @return {@link CMABulkAction} result instance
* @throws IllegalArgumentException if spaceId's space id is null.
* @throws IllegalArgumentException if payload's id is null.
*/
public CMABulkAction unpublish(String spaceId,
String environmentId,
CMAPayload payload) {
assertNotNull(spaceId, "spaceId");
assertNotNull(payload, "payload");

return service.unpublish(spaceId, environmentId, payload).blockingFirst();
}


/**
* Validate a bulk action.
*
* @return {@link CMABulkAction} result instance
* @throws IllegalArgumentException if spaceId's space id is null.
* @throws IllegalArgumentException if payload's id is null.
*/
public CMABulkAction validate(String spaceId,
String environmentId,
CMAPayload payload) {
assertNotNull(spaceId, "spaceId");
assertNotNull(payload, "payload");

return service.validate(spaceId, environmentId, payload).blockingFirst();
}

/**
* @return a module with a set of asynchronous methods.
*/
public Async async() {
return async;
}

/**
* Async module.
*/
public class Async {
/**
* Fetch a bulk action in the configured space.
*
* @param callback Callback
* @return the given CMACallback instance
* @see CMAClient.Builder#setSpaceId(String)
*/
public CMACallback<CMABulkAction> fetch(
String spaceId,
String environmentId,
String bulkActionId,
CMACallback<CMABulkAction> callback) {
return defer(new DefFunc<CMABulkAction>() {
@Override
CMABulkAction method() {
return ModuleBulkActions.this.fetch(spaceId,
environmentId,
bulkActionId);
}
}, callback);
}

/**
* Publish a bulk action in the configured space.
*
* @param callback Callback
* @return the given CMACallback instance
* @see CMAClient.Builder#setSpaceId(String)
*/
public CMACallback<CMABulkAction> publish(
String spaceId,
String environmentId,
CMAPayload payload,
CMACallback<CMABulkAction> callback) {
return defer(new DefFunc<CMABulkAction>() {
@Override
CMABulkAction method() {
return ModuleBulkActions.this.publish(spaceId,
environmentId,
payload);
}
}, callback);
}


/**
* UpPublish a bulk action in the configured space.
*
* @param callback Callback
* @return the given CMACallback instance
* @see CMAClient.Builder#setSpaceId(String)
*/
public CMACallback<CMABulkAction> unpublish(
String spaceId,
String environmentId,
CMAPayload payload,
CMACallback<CMABulkAction> callback) {
return defer(new DefFunc<CMABulkAction>() {
@Override
CMABulkAction method() {
return ModuleBulkActions.this.unpublish(spaceId,
environmentId,
payload);
}
}, callback);
}


/**
* Validate a bulk action in the configured space.
*
* @param callback Callback
* @return the given CMACallback instance
* @see CMAClient.Builder#setSpaceId(String)
*/
public CMACallback<CMABulkAction> validate(
String spaceId,
String environmentId,
CMAPayload payload,
CMACallback<CMABulkAction> callback) {
return defer(new DefFunc<CMABulkAction>() {
@Override
CMABulkAction method() {
return ModuleBulkActions.this.validate(spaceId,
environmentId,
payload);
}
}, callback);
}
}
}
46 changes: 23 additions & 23 deletions src/main/java/com/contentful/java/cma/ModuleTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class ModuleTags extends AbsModule<ServiceContentTags> {
* @param environmentIdConfigured internal helper to see if environment was set.
*/
public ModuleTags(
Retrofit retrofit,
Executor callbackExecutor,
String spaceId,
String environmentId,
boolean environmentIdConfigured) {
Retrofit retrofit,
Executor callbackExecutor,
String spaceId,
String environmentId,
boolean environmentIdConfigured) {
super(retrofit, callbackExecutor, spaceId, environmentId, environmentIdConfigured);
this.async = new Async();
}
Expand Down Expand Up @@ -176,10 +176,10 @@ public CMATag update(String name, String tagId) {
tag.setName(name);
tag.setId(tagId);
return service.update(
spaceId,
environmentId,
tagId,
tag
spaceId,
environmentId,
tagId,
tag
).blockingFirst();
}

Expand Down Expand Up @@ -249,7 +249,7 @@ Integer method() {
* @see CMAClient.Builder#setSpaceId(String)
*/
public CMACallback<CMAArray<CMATag>> fetchAll(
CMACallback<CMAArray<CMATag>> callback) {
CMACallback<CMAArray<CMATag>> callback) {
return defer(new DefFunc<CMAArray<CMATag>>() {
@Override
CMAArray<CMATag> method() {
Expand All @@ -272,10 +272,10 @@ CMAArray<CMATag> method() {
* @throws IllegalArgumentException if space id is null.
*/
public CMACallback<CMAArray<CMATag>> fetchAll(
final String spaceId,
final String environmentId,
final Map<String, String> query,
CMACallback<CMAArray<CMATag>> callback) {
final String spaceId,
final String environmentId,
final Map<String, String> query,
CMACallback<CMAArray<CMATag>> callback) {
return defer(new DefFunc<CMAArray<CMATag>>() {
@Override
CMAArray<CMATag> method() {
Expand All @@ -295,8 +295,8 @@ CMAArray<CMATag> method() {
* @see CMAClient.Builder#setEnvironmentId(String)
*/
public CMACallback<CMATag> fetchOne(
final String tagId,
CMACallback<CMATag> callback) {
final String tagId,
CMACallback<CMATag> callback) {
return defer(new DefFunc<CMATag>() {
@Override
CMATag method() {
Expand All @@ -319,10 +319,10 @@ CMATag method() {
* @throws IllegalArgumentException if environment id is null.
*/
public CMACallback<CMATag> fetchOne(
final String spaceId,
final String environmentId,
final String tagId,
CMACallback<CMATag> callback) {
final String spaceId,
final String environmentId,
final String tagId,
CMACallback<CMATag> callback) {
return defer(new DefFunc<CMATag>() {
@Override
CMATag method() {
Expand All @@ -338,9 +338,9 @@ CMATag method() {
* @return the given CMACallback instance
*/
public CMACallback<CMATag> update(
final String name,
final String tagId,
CMACallback<CMATag> callback) {
final String name,
final String tagId,
CMACallback<CMATag> callback) {
return defer(new DefFunc<CMATag>() {
@Override
CMATag method() {
Expand Down
Loading

0 comments on commit ff57142

Please sign in to comment.