View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.persistence.jpa.entity.task;
20  
21  import java.util.Optional;
22  import javax.persistence.Entity;
23  import javax.persistence.Lob;
24  import javax.persistence.ManyToOne;
25  import javax.persistence.OneToOne;
26  import javax.persistence.Table;
27  import org.apache.syncope.common.lib.command.CommandArgs;
28  import org.apache.syncope.common.lib.types.IdRepoImplementationType;
29  import org.apache.syncope.core.persistence.api.entity.Implementation;
30  import org.apache.syncope.core.persistence.api.entity.task.MacroTask;
31  import org.apache.syncope.core.persistence.api.entity.task.MacroTaskCommand;
32  import org.apache.syncope.core.persistence.jpa.entity.AbstractGeneratedKeyEntity;
33  import org.apache.syncope.core.persistence.jpa.entity.JPAImplementation;
34  import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
35  
36  @Entity
37  @Table(name = JPAMacroTaskCommand.TABLE)
38  public class JPAMacroTaskCommand extends AbstractGeneratedKeyEntity implements MacroTaskCommand {
39  
40      private static final long serialVersionUID = -8388668645348044783L;
41  
42      public static final String TABLE = "MacroTaskCommand";
43  
44      private int idx;
45  
46      @ManyToOne(optional = false)
47      private JPAMacroTask macroTask;
48  
49      @OneToOne(optional = false)
50      private JPAImplementation command;
51  
52      @Lob
53      private String args;
54  
55      public void setIdx(final int idx) {
56          this.idx = idx;
57      }
58  
59      @Override
60      public JPAMacroTask getMacroTask() {
61          return macroTask;
62      }
63  
64      @Override
65      public void setMacroTask(final MacroTask macroTask) {
66          checkType(macroTask, JPAMacroTask.class);
67          this.macroTask = (JPAMacroTask) macroTask;
68      }
69  
70      @Override
71      public Implementation getCommand() {
72          return command;
73      }
74  
75      @Override
76      public void setCommand(final Implementation command) {
77          checkType(command, JPAImplementation.class);
78          checkImplementationType(command, IdRepoImplementationType.COMMAND);
79          this.command = (JPAImplementation) command;
80      }
81  
82      @Override
83      public CommandArgs getArgs() {
84          return Optional.ofNullable(args).
85                  map(args -> POJOHelper.deserialize(args, CommandArgs.class)).
86                  orElse(null);
87      }
88  
89      @Override
90      public void setArgs(final CommandArgs args) {
91          this.args = Optional.ofNullable(args).map(POJOHelper::serialize).orElse(null);
92      }
93  }