@Inject
  public VertexiumUserRepository(
      Configuration configuration,
      SimpleOrmSession simpleOrmSession,
      AuthorizationRepository authorizationRepository,
      Graph graph,
      OntologyRepository ontologyRepository,
      UserSessionCounterRepository userSessionCounterRepository,
      WorkQueueRepository workQueueRepository,
      UserNotificationRepository userNotificationRepository,
      LockRepository lockRepository) {
    super(
        configuration,
        simpleOrmSession,
        userSessionCounterRepository,
        workQueueRepository,
        userNotificationRepository,
        lockRepository);
    this.authorizationRepository = authorizationRepository;
    this.graph = graph;

    authorizationRepository.addAuthorizationToGraph(VISIBILITY_STRING);
    authorizationRepository.addAuthorizationToGraph(VisalloVisibility.SUPER_USER_VISIBILITY_STRING);

    Concept userConcept =
        ontologyRepository.getOrCreateConcept(null, USER_CONCEPT_IRI, "visalloUser", null);
    userConceptId = userConcept.getIRI();

    Set<String> authorizationsSet = new HashSet<>();
    authorizationsSet.add(VISIBILITY_STRING);
    authorizationsSet.add(VisalloVisibility.SUPER_USER_VISIBILITY_STRING);
    this.authorizations = graph.createAuthorizations(authorizationsSet);
  }
Exemplo n.º 2
0
  @Handle
  public void handle(
      @Required(name = "concept") String conceptIRI,
      @Required(name = "displayName") String displayName,
      @Required(name = "color") String color,
      @Required(name = "displayType") String displayType,
      @Required(name = "titleFormula") String titleFormula,
      @Required(name = "subtitleFormula") String subtitleFormula,
      @Required(name = "timeFormula") String timeFormula,
      @Required(name = "addRelatedConceptWhiteList[]") String[] addRelatedConceptWhiteListArg,
      @Required(name = "intents[]") String[] intents,
      @Optional(name = "searchable", defaultValue = "true") boolean searchable,
      @Optional(name = "addable", defaultValue = "true") boolean addable,
      @Optional(name = "userVisible", defaultValue = "true") boolean userVisible,
      User user,
      Authorizations authorizations,
      VisalloResponse response)
      throws Exception {
    HashSet<String> addRelatedConceptWhiteList =
        new HashSet<>(Arrays.asList(addRelatedConceptWhiteListArg));

    Concept concept = ontologyRepository.getConceptByIRI(conceptIRI);
    if (concept == null) {
      response.respondWithNotFound("concept " + conceptIRI + " not found");
      return;
    }

    if (displayName.length() != 0) {
      concept.setProperty(
          OntologyProperties.DISPLAY_NAME.getPropertyName(), displayName, authorizations);
    }

    if (color.length() != 0) {
      concept.setProperty(OntologyProperties.COLOR.getPropertyName(), color, authorizations);
    }

    JSONArray whiteList = new JSONArray();
    for (String whitelistIri : addRelatedConceptWhiteList) {
      whiteList.put(whitelistIri);
    }
    concept.setProperty(
        OntologyProperties.ADD_RELATED_CONCEPT_WHITE_LIST.getPropertyName(),
        whiteList.toString(),
        authorizations);

    concept.setProperty(
        OntologyProperties.DISPLAY_TYPE.getPropertyName(), displayType, authorizations);
    concept.setProperty(
        OntologyProperties.SEARCHABLE.getPropertyName(), searchable, authorizations);
    concept.setProperty(OntologyProperties.ADDABLE.getPropertyName(), addable, authorizations);
    concept.setProperty(
        OntologyProperties.USER_VISIBLE.getPropertyName(), userVisible, authorizations);

    if (titleFormula.length() != 0) {
      concept.setProperty(
          OntologyProperties.TITLE_FORMULA.getPropertyName(), titleFormula, authorizations);
    } else {
      concept.removeProperty(OntologyProperties.TITLE_FORMULA.getPropertyName(), authorizations);
    }

    if (subtitleFormula.length() != 0) {
      concept.setProperty(
          OntologyProperties.SUBTITLE_FORMULA.getPropertyName(), subtitleFormula, authorizations);
    } else {
      concept.removeProperty(OntologyProperties.SUBTITLE_FORMULA.getPropertyName(), authorizations);
    }

    if (timeFormula.length() != 0) {
      concept.setProperty(
          OntologyProperties.TIME_FORMULA.getPropertyName(), timeFormula, authorizations);
    } else {
      concept.removeProperty(OntologyProperties.TIME_FORMULA.getPropertyName(), authorizations);
    }

    concept.updateIntents(StringArrayUtil.removeNullOrEmptyElements(intents), authorizations);

    ontologyRepository.clearCache();

    response.respondWithSuccessJson();
  }