List of usage examples for org.apache.commons.lang3 SerializationUtils clone
public static <T extends Serializable> T clone(final T object)
Deep clone an Object using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:org.apache.syncope.core.persistence.jpa.dao.AbstractAnySearchDAO.java
protected Triple<PlainSchema, PlainAttrValue, AnyCond> check(final AnyCond cond, final AnyTypeKind kind) { AnyCond condClone = SerializationUtils.clone(cond); AnyUtils attrUtils = anyUtilsFactory.getInstance(kind); // Keeps track of difference between entity's getKey() and JPA @Id fields if ("key".equals(condClone.getSchema())) { condClone.setSchema("id"); }/*from w ww . ja va 2 s . c o m*/ Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), condClone.getSchema()); if (anyField == null) { LOG.warn("Ignoring invalid schema '{}'", condClone.getSchema()); throw new IllegalArgumentException(); } PlainSchema schema = new JPAPlainSchema(); schema.setKey(anyField.getName()); for (AttrSchemaType attrSchemaType : AttrSchemaType.values()) { if (anyField.getType().isAssignableFrom(attrSchemaType.getType())) { schema.setType(attrSchemaType); } } // Deal with any Integer fields logically mapping to boolean values boolean foundBooleanMin = false; boolean foundBooleanMax = false; if (Integer.class.equals(anyField.getType())) { for (Annotation annotation : anyField.getAnnotations()) { if (Min.class.equals(annotation.annotationType())) { foundBooleanMin = ((Min) annotation).value() == 0; } else if (Max.class.equals(annotation.annotationType())) { foundBooleanMax = ((Max) annotation).value() == 1; } } } if (foundBooleanMin && foundBooleanMax) { schema.setType(AttrSchemaType.Boolean); } // Deal with any fields representing relationships to other entities if (anyField.getType().getAnnotation(Entity.class) != null) { Method relMethod = null; try { relMethod = ClassUtils.getPublicMethod(anyField.getType(), "getKey", new Class<?>[0]); } catch (Exception e) { LOG.error("Could not find {}#getKey", anyField.getType(), e); } if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType())) { condClone.setSchema(condClone.getSchema() + "_id"); schema.setType(AttrSchemaType.String); } } PlainAttrValue attrValue = attrUtils.newPlainAttrValue(); if (condClone.getType() != AttributeCond.Type.LIKE && condClone.getType() != AttributeCond.Type.ILIKE && condClone.getType() != AttributeCond.Type.ISNULL && condClone.getType() != AttributeCond.Type.ISNOTNULL) { try { ((JPAPlainSchema) schema).validator().validate(condClone.getExpression(), attrValue); } catch (ValidationException e) { LOG.error("Could not validate expression '" + condClone.getExpression() + "'", e); throw new IllegalArgumentException(); } } return Triple.of(schema, attrValue, condClone); }
From source file:org.apache.syncope.core.provisioning.java.AuditEntry.java
private Object filterUserPassword(final Object object) { Object filtered;/*from ww w. j a va 2s.c o m*/ if (object instanceof UserTO) { UserTO user = SerializationUtils.clone((UserTO) object); user.setPassword(null); filtered = user; } else { filtered = object; } return filtered; }
From source file:org.apache.syncope.core.provisioning.java.ConnectorManager.java
@Override public ConnInstance buildConnInstanceOverride(final ConnInstance connInstance, final Set<ConnConfProperty> confOverride, final Set<ConnectorCapability> capabilitiesOverride) { ConnInstance override = SerializationUtils.clone(connInstance); Map<String, ConnConfProperty> overridable = new HashMap<>(); Set<ConnConfProperty> conf = new HashSet<>(); for (ConnConfProperty prop : override.getConf()) { if (prop.isOverridable()) { overridable.put(prop.getSchema().getName(), prop); } else {//from w ww.j av a 2s .co m conf.add(prop); } } // add overridden properties for (ConnConfProperty prop : confOverride) { if (overridable.containsKey(prop.getSchema().getName()) && !prop.getValues().isEmpty()) { conf.add(prop); overridable.remove(prop.getSchema().getName()); } } // add overridable properties not overridden conf.addAll(overridable.values()); override.setConf(conf); // replace capabilities if (capabilitiesOverride != null) { override.getCapabilities().clear(); override.getCapabilities().addAll(capabilitiesOverride); } return override; }
From source file:org.apache.syncope.core.provisioning.java.MailTemplateTest.java
@Test public void optin() throws IOException { Map<String, Object> ctx = new HashMap<>(); String username = "test" + UUID.randomUUID().toString(); UserTO user = new UserTO(); user.setUsername(username);/*from ww w .j a va 2s . c om*/ user.getPlainAttrs().add(new AttrTO.Builder().schema("firstname").value("John").build()); user.getPlainAttrs().add(new AttrTO.Builder().schema("surname").value("Doe").build()); user.getPlainAttrs().add(new AttrTO.Builder().schema("email").value("john.doe@syncope.apache.org").build()); user.getMemberships() .add(new MembershipTO.Builder().group(UUID.randomUUID().toString(), "a group").build()); ctx.put("user", user); String token = "token " + UUID.randomUUID().toString(); List<String> input = new ArrayList<>(); input.add(token); ctx.put("input", input); UserTO recipient = SerializationUtils.clone(user); recipient.getPlainAttr("email").get().getValues().set(0, "another@syncope.apache.org"); ctx.put("recipients", Collections.singletonList(recipient)); String htmlBody = evaluate(mailTemplateDAO.find("optin").getHTMLTemplate(), ctx); assertNotNull(htmlBody); assertTrue(htmlBody.contains("Hi John Doe,")); assertTrue(htmlBody.contains("Your email address is john.doe@syncope.apache.org.")); assertTrue(htmlBody.contains("<li>another@syncope.apache.org</li>")); assertTrue(htmlBody.contains("<li>a group</li>")); }
From source file:org.apache.syncope.core.rest.data.ResourceDataBinder.java
private AbstractMappingItem getMappingItem(final MappingItemTO itemTO, final AbstractMappingItem prototype) { if (itemTO == null || itemTO.getIntMappingType() == null) { LOG.error("Null mappingTO provided"); return null; }/*from w ww. j ava 2 s. com*/ SyncopeClientCompositeException scce = SyncopeClientException.buildComposite(); SyncopeClientException requiredValuesMissing = SyncopeClientException .build(ClientExceptionType.RequiredValuesMissing); if (itemTO.getIntAttrName() == null) { if (IntMappingType.getEmbedded().contains(itemTO.getIntMappingType())) { itemTO.setIntAttrName(itemTO.getIntMappingType().toString()); } else { requiredValuesMissing.getElements().add("intAttrName"); } } // Throw composite exception if there is at least one element set // in the composing exceptions if (!requiredValuesMissing.isEmpty()) { scce.addException(requiredValuesMissing); } // no mandatory condition implies mandatory condition false if (!JexlUtil.isExpressionValid( itemTO.getMandatoryCondition() == null ? "false" : itemTO.getMandatoryCondition())) { SyncopeClientException invalidMandatoryCondition = SyncopeClientException .build(ClientExceptionType.InvalidValues); invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition()); scce.addException(invalidMandatoryCondition); } if (scce.hasExceptions()) { throw scce; } AbstractMappingItem item = (AbstractMappingItem) SerializationUtils.clone(prototype); BeanUtils.copyProperties(itemTO, item, MAPPINGITEM_IGNORE_PROPERTIES); return item; }
From source file:org.apache.syncope.core.rest.data.ResourceDataBinder.java
public ConnInstance getConnInstance(final ExternalResource resource) { final ConnInstance connInstanceClone = (ConnInstance) SerializationUtils.clone(resource.getConnector()); return getConnInstance(connInstanceClone, resource.getConnInstanceConfiguration()); }
From source file:org.apache.syncope.core.rest.data.ResourceDataBinder.java
public ConnInstance getConnInstance(final ResourceTO resourceTO) { ConnInstance connInstance = connInstanceDAO.find(resourceTO.getConnectorId()); if (connInstance == null) { throw new NotFoundException("Connector '" + resourceTO.getConnectorId() + "'"); }/*from ww w. j a v a2 s. c om*/ final ConnInstance connInstanceClone = (ConnInstance) SerializationUtils.clone(connInstance); return getConnInstance(connInstanceClone, resourceTO.getConnConfProperties()); }
From source file:org.apache.syncope.core.rest.SchemaTestITCase.java
@Test public void issue259() { SchemaTO schemaTO = buildSchemaTO("schema_issue259", AttributeSchemaType.Double); schemaTO.setUniqueConstraint(true);// www.ja va2s .c om schemaTO = createSchema(AttributableType.USER, SchemaType.NORMAL, schemaTO); assertNotNull(schemaTO); UserTO userTO = UserTestITCase.getUniqueSampleTO("issue259@syncope.apache.org"); userTO.getAttrs().add(attributeTO(schemaTO.getName(), "1")); userTO = createUser(userTO); assertNotNull(userTO); UserTO newUserTO = SerializationUtils.clone(userTO); MembershipTO membership = new MembershipTO(); membership.setRoleId(2L); newUserTO.getMemberships().add(membership); UserMod userMod = AttributableOperations.diff(newUserTO, userTO); userTO = userService.update(userMod.getId(), userMod).readEntity(UserTO.class); assertNotNull(userTO); }
From source file:org.apache.syncope.core.rest.VirAttrTestITCase.java
@Test public void issueSYNCOPE397() { ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV); // change mapping of resource-csv MappingTO origMapping = SerializationUtils.clone(csv.getUmapping()); assertNotNull(origMapping);/*from w ww . j ava 2s . c o m*/ for (MappingItemTO item : csv.getUmapping().getItems()) { if ("email".equals(item.getIntAttrName())) { // unset internal attribute mail and set virtual attribute virtualdata as mapped to external email item.setIntMappingType(IntMappingType.UserVirtualSchema); item.setIntAttrName("virtualdata"); item.setPurpose(MappingPurpose.BOTH); item.setExtAttrName("email"); } } resourceService.update(csv.getName(), csv); csv = resourceService.read(RESOURCE_NAME_CSV); assertNotNull(csv.getUmapping()); boolean found = false; for (MappingItemTO item : csv.getUmapping().getItems()) { if ("email".equals(item.getExtAttrName()) && "virtualdata".equals(item.getIntAttrName())) { found = true; } } assertTrue(found); // create a new user UserTO userTO = UserTestITCase.getUniqueSampleTO("syncope397@syncope.apache.org"); userTO.getResources().clear(); userTO.getMemberships().clear(); userTO.getDerAttrs().clear(); userTO.getVirAttrs().clear(); userTO.getDerAttrs().add(attributeTO("csvuserid", null)); userTO.getDerAttrs().add(attributeTO("cn", null)); userTO.getVirAttrs().add(attributeTO("virtualdata", "test@testone.org")); // assign resource-csv to user userTO.getResources().add(RESOURCE_NAME_CSV); // save user UserTO created = createUser(userTO); // make std controls about user assertNotNull(created); assertTrue(RESOURCE_NAME_CSV.equals(created.getResources().iterator().next())); // update user UserTO toBeUpdated = userService.read(created.getId()); UserMod userMod = new UserMod(); userMod.setId(toBeUpdated.getId()); userMod.setPassword("password2"); // assign new resource to user userMod.getResourcesToAdd().add(RESOURCE_NAME_WS2); //modify virtual attribute userMod.getVirAttrsToRemove().add("virtualdata"); userMod.getVirAttrsToUpdate().add(attributeMod("virtualdata", "test@testoneone.com")); // check Syncope change password StatusMod pwdPropRequest = new StatusMod(); pwdPropRequest.setOnSyncope(true); pwdPropRequest.getResourceNames().add(RESOURCE_NAME_WS2); userMod.setPwdPropRequest(pwdPropRequest); toBeUpdated = updateUser(userMod); assertNotNull(toBeUpdated); assertEquals("test@testoneone.com", toBeUpdated.getVirAttrs().get(0).getValues().get(0)); // check if propagates correctly with assertEquals on size of tasks list assertEquals(2, toBeUpdated.getPropagationStatusTOs().size()); // restore mapping of resource-csv csv.setUmapping(origMapping); resourceService.update(csv.getName(), csv); }
From source file:org.apache.syncope.core.workflow.activiti.task.Update.java
@Override protected void doExecute(final String executionId) { User user = runtimeService.getVariable(executionId, ActivitiUserWorkflowAdapter.USER, User.class); UserMod userMod = runtimeService.getVariable(executionId, ActivitiUserWorkflowAdapter.USER_MOD, UserMod.class); // update password internally only if required UserMod updatedMod = SerializationUtils.clone(userMod); String updatedPwd = updatedMod.getPassword(); if (updatedMod.getPwdPropRequest() != null && !updatedMod.getPwdPropRequest().isOnSyncope()) { updatedMod.setPassword(null);/*from w w w . j a va2 s .co m*/ } // update user PropagationByResource propByRes = dataBinder.update(user, updatedMod); updatedMod.setPassword(updatedPwd); // report updated user and propagation by resource as result runtimeService.setVariable(executionId, ActivitiUserWorkflowAdapter.USER, user); runtimeService.setVariable(executionId, ActivitiUserWorkflowAdapter.USER_MOD, updatedMod); runtimeService.setVariable(executionId, ActivitiUserWorkflowAdapter.PROP_BY_RESOURCE, propByRes); }