Skip to content
Open
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,42 @@
/*
* Copyright (c) 2017-2025 Evolveum
*
* 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.evolveum.midpoint.client.api;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
* @author Z14tk0
*
*/
public abstract class AbstractObjectWebResource<O extends ObjectType> extends AbstractWebResource {

private final Class<O> type;
private final String oid;

public AbstractObjectWebResource(final Service service, final Class<O> type, final String oid) {
super(service);
this.type = type;
this.oid = oid;
}

protected Class<O> getType() {
return type;
}

protected String getOid() {
return oid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2017-2025 Evolveum
*
* 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.evolveum.midpoint.client.api;

/**
* @author Z14tk0
*
*/
public abstract class AbstractWebResource {

private final Service service;

public AbstractWebResource(final Service service) {
super();
this.service = service;
}

protected Service getService() {
return service;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package com.evolveum.midpoint.client.api;

import java.util.List;
import java.io.InputStream;
import java.util.Map;

import com.evolveum.midpoint.client.api.exception.CommonException;
import com.evolveum.midpoint.client.api.exception.SchemaException;
import com.evolveum.midpoint.client.api.verb.Post;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

Expand All @@ -32,6 +32,7 @@ public interface ObjectModifyService <O extends ObjectType> extends Post<ObjectR
ObjectModifyService<O> replace(Map<String, Object> modifications);
ObjectModifyService<O> delete(String path, Object value);
ObjectModifyService<O> delete(Map<String, Object> modifications);
ObjectModifyService<O> setModifications(InputStream inputStream) throws SchemaException;

ExecuteOptionSupport.WithPost<ObjectReference<O>> options();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (c) 2017-2025 Evolveum
*
* 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.evolveum.midpoint.client.impl.prism;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.evolveum.midpoint.client.api.*;
import com.evolveum.midpoint.client.api.exception.CommonException;
import com.evolveum.midpoint.client.api.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.client.api.exception.ObjectNotFoundException;
import com.evolveum.midpoint.client.api.exception.SchemaException;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.ModificationTypeType;

/**
* @author Z14tk0
*/
public class RestPrismObjectModifyService<O extends ObjectType> extends AbstractObjectWebResource<O> implements ObjectModifyService<O> {

private List<ItemDeltaType> modifications;
private List<String> options;

@Override
public ExecuteOptionSupport.WithPost<ObjectReference<O>> options() {
return new ExecuteOptionsBuilder.WithPost<ObjectReference<O>>() {
@Override
public TaskFuture<ObjectReference<O>> apost() throws CommonException {
setOptions(this.optionsAsStringList());
return RestPrismObjectModifyService.this.apost();
}
};
}

public RestPrismObjectModifyService(RestPrismService service, ObjectTypes type, String oid) {
super(service, type.getClassDefinition(), oid);
this.modifications = new ArrayList<>();
}

public RestPrismObjectModifyService<O> setOptions(List<String> options) {
this.options = options;
return this;
}

@Override
public RestPrismObjectModifyService<O> add(String path, Object value){
addModification(path, value, ModificationTypeType.ADD);
return this;
}

@Override
public RestPrismObjectModifyService<O> add(Map<String, Object> modifications){
addModifications(modifications, ModificationTypeType.ADD);
return this;
}

@Override
public RestPrismObjectModifyService<O> replace(String path, Object value){
addModification(path, value, ModificationTypeType.REPLACE);
return this;
}

@Override
public RestPrismObjectModifyService<O> replace(Map<String, Object> modifications){
addModifications(modifications, ModificationTypeType.REPLACE);
return this;
}

@Override
public RestPrismObjectModifyService<O> delete(String path, Object value){
addModification(path, value, ModificationTypeType.DELETE);
return this;
}

@Override
public RestPrismObjectModifyService<O> delete(Map<String, Object> modifications){
addModifications(modifications, ModificationTypeType.DELETE);
return this;
}

@Override
public RestPrismObjectModifyService<O> setModifications(InputStream inputStream) throws SchemaException {
this.modifications.addAll(((ObjectModificationType) ((RestPrismService) getService()).parseObjectModification(inputStream)).getItemDelta());
return this;
}

private void addModification(String path, Object value, ModificationTypeType modificationType){
modifications.add(RestPrismUtils.buildItemDelta(modificationType, path, value));
}

private void addModifications(Map<String, Object> modifications, ModificationTypeType modificationType){
modifications.forEach((path, value) ->
addModification(path, value, modificationType));
}

@Override
public TaskFuture<ObjectReference<O>> apost() throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException {

String oidRes = ((RestPrismService) getService()).modifyObject(ObjectTypes.getObjectType(getType()), RestPrismUtils.buildModifyObject(modifications), options, getOid());

RestPrismObjectReference<O> ref = new RestPrismObjectReference<>((RestPrismService) getService(), oidRes, getType());
return new RestPrismCompletedFuture<>(ref);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,27 @@
*/
package com.evolveum.midpoint.client.impl.prism;

import com.evolveum.midpoint.client.api.AbstractObjectWebResource;
import com.evolveum.midpoint.client.api.ObjectReference;
import com.evolveum.midpoint.client.api.exception.ObjectNotFoundException;
import com.evolveum.midpoint.client.api.exception.SchemaException;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

public class RestPrismObjectReference<O extends ObjectType> implements ObjectReference<O> {
public class RestPrismObjectReference<O extends ObjectType> extends AbstractObjectWebResource<O> implements ObjectReference<O> {

private String oid;
private Class<O> type;
private O object = null;

public RestPrismObjectReference(String oid, Class type) {
public RestPrismObjectReference(String oid, Class<O> type) {
super(null, type, oid);
this.oid = oid;
this.type = type;
}

public RestPrismObjectReference(RestPrismService service, String oid, Class<O> type) {
super(service, type, oid);
this.oid = oid;
this.type = type;
}
Expand All @@ -41,7 +52,7 @@ public Class<O> getType() {

@Override
public O getObject() throws ObjectNotFoundException {
return null;
return object;
}

@Override
Expand All @@ -50,7 +61,10 @@ public boolean containsObject() {
}

@Override
public O get() throws ObjectNotFoundException {
return null;
public O get() throws ObjectNotFoundException, SchemaException {
if (object == null) {
object = ((RestPrismService) getService()).getObject(ObjectTypes.getObjectType(getType()), getOid());
}
return object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public O get(List<String> options, List<String> include, List<String> exclude) t

@Override
public ObjectModifyService<O> modify() throws ObjectNotFoundException, AuthenticationException {
throw new UnsupportedOperationException("Not impelemted yet");
return new RestPrismObjectModifyService<>(getService(), getType(), getOid());
}

@Override
Expand Down
Loading