private static long createUser(SCWebApiClient client, EntityBase eb) throws WebApiException { System.out.println("Creating an entity..."); EntityType person = client.readEntityType("person", eb.getKbLabel()); Entity entity = new Entity(); entity.setEntityBase(eb); entity.setEtype(person); Long eid = client.create(entity); System.out.println("Created entity with ID " + eid); System.out.println("Creating a user..."); User user = new User(); user.setName("Test user " + System.currentTimeMillis()); user.setEntityBaseId(eb.getId()); user.setPersonEntityId(eid); long id = client.create(user); System.out.println("New user's ID: " + id); return id; }
/** * checks if social entity is owned by the given user * * @param user user owner of entity * @param entityId social entity id * @return true if entity is owned by the user, false otherwise */ public boolean isOwnedBy(User user, String entityId) { try { Entity entity = socialClient.readEntity(Long.decode(entityId), null); it.unitn.disi.sweb.webapi.model.smartcampus.social.User socialUser = socialClient.readUser(Long.valueOf(user.getSocialId())); return entity.getOwnerId().equals(socialUser.getEntityBaseId()); } catch (NumberFormatException e) { logger.error(String.format("Exception converting in long entityId %s", entityId)); return false; } catch (WebApiException e) { logger.error("Exception invoking socialEngineClient", e); return false; } catch (Exception e) { logger.error("A general exception is occurred", e); return false; } }