Skip to content

Commit

Permalink
MID-9626 upload full processing for resource fix
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Apr 17, 2024
1 parent a8f7f26 commit 8d00e17
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,14 @@ public String modify(MidPointObject object, List<String> opts) throws IOExceptio
}

Map<String, Object> options = new HashMap<>();
opts.forEach(o -> options.put("options", o));

MidPointObject toBeModified;
try {
toBeModified = get(ObjectTypes.OBJECT.getClassDefinition(), object.getOid(), GetOperationOptions.createRawCollection());
options.put("options", opts);

if (toBeModified == null) {
throw new ObjectNotFoundException("Couldn't fetch object before modification to find out proper type");
}
} catch (IOException | ObjectNotFoundException ex) {
throw new ClientException("Couldn't fetch object before modification to find out proper type", ex);
ObjectTypes type = object.getType();
if (type == null) {
type = getObjectType(object.getOid());
}

String path = "/" + ObjectTypes.getRestTypeFromClass(toBeModified.getType().getClassDefinition()) + "/" + object.getOid();
String path = "/" + ObjectTypes.getRestTypeFromClass(type.getClassDefinition()) + "/" + object.getOid();

Request req = context.build(path, options)
.patch(RequestBody.create(object.getContent(), ServiceContext.APPLICATION_XML))
Expand All @@ -197,6 +191,21 @@ public String modify(MidPointObject object, List<String> opts) throws IOExceptio
}
}

private ObjectTypes getObjectType(String oid) {
MidPointObject toBeModified;
try {
toBeModified = get(ObjectTypes.OBJECT.getClassDefinition(), oid, GetOperationOptions.createRawCollection());

if (toBeModified == null) {
throw new ObjectNotFoundException("Couldn't fetch object before modification to find out proper type");
}
} catch (IOException | ObjectNotFoundException | AuthenticationException ex) {
throw new ClientException("Couldn't fetch object before modification to find out proper type", ex);
}

return toBeModified.getType();
}

@Override
public String add(MidPointObject object) throws IOException, AuthenticationException {
return add(object, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import com.evolveum.midpoint.studio.action.transfer.ProcessObjectResult;
import com.evolveum.midpoint.studio.client.MidPointObject;
import com.evolveum.midpoint.studio.impl.Environment;
import com.evolveum.midpoint.studio.impl.configuration.MidPointConfiguration;
import com.evolveum.midpoint.studio.impl.configuration.MidPointService;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -35,7 +39,7 @@ protected UploadFullProcessingTask(

@Override
protected ProcessObjectResult processObject(MidPointObject object) throws Exception {
OperationResult result = UploadTaskMixin.uploadExecute(client, object, buildUploadOptions(object));
OperationResult result = UploadTaskMixin.uploadExecute(client, object, buildUploadOptions(getProject(), object));

ProcessObjectResult por = validateOperationResult(OPERATION_UPLOAD, result, object.getName());

Expand All @@ -61,13 +65,18 @@ protected ProcessObjectResult processObject(MidPointObject object) throws Except
return validateOperationResult(OPERATION_TEST_CONNECTION, testConnectionResult, object.getName());
}

public static List<String> buildUploadOptions(MidPointObject object) {
public static List<String> buildUploadOptions(Project project, MidPointObject object) {
List<String> options = new ArrayList<>();
options.add("isImport");
options.add(ModelExecuteOptionsType.F_IS_IMPORT.getLocalPart());

ObjectTypes type = object.getType();
if (type != ObjectTypes.TASK && type != ObjectTypes.SYSTEM_CONFIGURATION) {
options.add("raw");
options.add(ModelExecuteOptionsType.F_RAW.getLocalPart());
}

MidPointConfiguration settings = MidPointService.get(project).getSettings();
if (settings.isUpdateOnUpload()) {
options.add(ModelExecuteOptionsType.F_REEVALUATE_SEARCH_FILTERS.getLocalPart());
}

return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExpressionPipelineType;
Expand All @@ -32,11 +33,11 @@ public interface UploadTaskMixin {

static List<String> buildUploadOptions(MidPointObject object) {
List<String> options = new ArrayList<>();
options.add("isImport");
options.add(ModelExecuteOptionsType.F_IS_IMPORT.getLocalPart());

ObjectTypes type = object.getType();
if (type != ObjectTypes.TASK && type != ObjectTypes.SYSTEM_CONFIGURATION) {
options.add("raw");
options.add(ModelExecuteOptionsType.F_RAW.getLocalPart());
}

return options;
Expand Down

0 comments on commit 8d00e17

Please sign in to comment.