ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
resource.setConnector(connector);
SchemaMapping mapping = new SchemaMapping();
mapping.setResource(resource);
mapping.setAccountid(true);
mapping.setIntAttrName("fullname");
mapping.setIntMappingType(IntMappingType.UserSchema);
resource.addMapping(mapping);
mapping = new SchemaMapping();
mapping.setResource(resource);
mapping.setIntAttrName("icon");
mapping.setExtAttrName("icon");
mapping.setIntMappingType(IntMappingType.RoleSchema);
resource.addMapping(mapping);
mapping = new SchemaMapping();
mapping.setResource(resource);
mapping.setIntAttrName("mderiveddata");
mapping.setExtAttrName("mderiveddata");
mapping.setIntMappingType(IntMappingType.MembershipDerivedSchema);
resource.addMapping(mapping);
// save the resource
ExternalResource actual = resourceDAO.save(resource);