1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.fit.core.reference;
20
21 import java.util.Optional;
22 import org.apache.syncope.common.lib.Attr;
23 import org.apache.syncope.common.lib.request.AnyObjectCR;
24 import org.apache.syncope.common.lib.to.AnyObjectTO;
25 import org.apache.syncope.common.lib.to.RealmTO;
26 import org.apache.syncope.core.logic.AnyObjectLogic;
27 import org.apache.syncope.core.logic.RealmLogic;
28 import org.apache.syncope.core.provisioning.api.macro.Command;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.transaction.annotation.Propagation;
33 import org.springframework.transaction.annotation.Transactional;
34
35 public class TestCommand implements Command<TestCommandArgs> {
36
37 private static final Logger LOG = LoggerFactory.getLogger(TestCommand.class);
38
39 @Autowired
40 private RealmLogic realmLogic;
41
42 @Autowired
43 private AnyObjectLogic anyObjectLogic;
44
45 private Optional<RealmTO> getRealm(final String fullPath) {
46 return realmLogic.search(null, fullPath, -1, -1).getRight().stream().
47 filter(realm -> fullPath.equals(realm.getFullPath())).findFirst();
48 }
49
50 @Transactional(propagation = Propagation.NOT_SUPPORTED)
51 @Override
52 public String run(final TestCommandArgs args) {
53
54 RealmTO realm = new RealmTO();
55 realm.setName(args.getRealmName());
56 realm.setParent(getRealm(args.getParentRealm()).map(RealmTO::getKey).orElse(null));
57 realm = realmLogic.create(args.getParentRealm(), realm).getEntity();
58 LOG.info("Realm created: {}", realm.getFullPath());
59
60
61 AnyObjectTO anyObject = anyObjectLogic.create(
62 new AnyObjectCR.Builder(realm.getFullPath(), "PRINTER", args.getPrinterName()).
63 plainAttr(new Attr.Builder("location").value("location").build()).
64 build(),
65 false).getEntity();
66 LOG.info("PRINTER created: {}", anyObject.getName());
67
68 return "Realm created: " + realm.getFullPath() + "; PRINTER created: " + anyObject.getName();
69 }
70 }