/** * Attempts to create a new user entry in the associated FreeAgent account. * * <p>Will return null if the user instance provided is null or cannot be saved into the account. * * @param user The populated user instance. * @return The updated user instance or null. */ public FreeAgentUser createUser(FreeAgentUser user) { if (user != null) { FreeAgentUserWrapper userWrapper = freeAgentServiceInstance.createUser(new FreeAgentUserWrapper(user)); if (userWrapper != null) { return userWrapper.getUser(); } } return null; }
/** * Attempts to import a new user into the associated FreeAgent account by deserialising the * specified JSON user information and requesting a new user be created. * * <p>NOTE: The import (creation within FreeAgent) will only be actioned if no URL property is * present or if the URL property is not populated. Otherwise null will be returned. * * @param userJSON A string containing user information in FreeAgent friendly format. * @return The newly populated user instance that has been imported into FreeAgent or null. * @throws JsonSyntaxException If the format does not match the FreeAgent V2 User format. */ public FreeAgentUser importUser(String userJSON) throws JsonSyntaxException { if (userJSON == null || userJSON.isEmpty()) { return null; } FreeAgentUser user = buildUser(userJSON); if (user != null && (user.getUrl() == null || user.getUrl().isEmpty())) { FreeAgentUserWrapper userWrapper = freeAgentServiceInstance.createUser(new FreeAgentUserWrapper(user)); if (userWrapper != null) { return userWrapper.getUser(); } } return null; }