Projects >> deepamehta >>6a7295cd1ff99f1f7658108bf10b3b1f4e40d639

Chunk
Conflicting content
import javax.ws.rs.POST;
import javax.ws.rs.DELETE;
import javax.ws.rs.Consumes;
<<<<<<< HEAD
import javax.ws.rs.PathParam;
=======
import javax.ws.rs.CookieParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
>>>>>>> 6870789a4a1353d214dd2307d53d22170e72f2c4
import javax.ws.rs.core.Context;

import static java.util.Arrays.asList;
Solution content
import javax.ws.rs.POST;
import javax.ws.rs.DELETE;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import static java.util.Arrays.asList;
File
AccessControlPlugin.java
Developer's decision
Combination
Kind of conflict
Import
Chunk
Conflicting content
    }

    @Override
<<<<<<< HEAD
    public void createACLEntry(DeepaMehtaObject object, Role role, Permissions permissions) {
        TopicModel aclEntry = aclEntryModel(role, permissions);
        facetsService.updateFacets(object, "dm4.accesscontrol.acl_facet", asList(aclEntry), null, null);
=======
    public void createACLEntry(Topic topic, Role role, Permissions permissions) {
        TopicModel aclEntry = createAclEntryModel(role, permissions);
        // Note: acl_facet is a multi-facet. So we must pass a (one-element) list.
        facetsService.updateFacets(topic, "dm4.accesscontrol.acl_facet", asList(aclEntry), null, null);
>>>>>>> 6870789a4a1353d214dd2307d53d22170e72f2c4
    }

    // ---
Solution content
    }

    @Override
    public void createACLEntry(DeepaMehtaObject object, Role role, Permissions permissions) {
        TopicModel aclEntry = createAclEntryModel(role, permissions);
        // Note: acl_facet is a multi-facet. So we must pass a (one-element) list.
        facetsService.updateFacets(object, "dm4.accesscontrol.acl_facet", asList(aclEntry), null, null);
    }

    // ---
File
AccessControlPlugin.java
Developer's decision
Combination
Kind of conflict
Comment
Method invocation
Method signature
Variable
Chunk
Conflicting content
    // ---

<<<<<<< HEAD
    /**
     * Prerequisite: username is not null.
     */
    private Topic getUserAccount(Topic username) {
        Topic userAccount = username.getRelatedTopic("dm4.core.composition", "dm4.core.part", "dm4.core.whole",
            "dm4.accesscontrol.user_account", true, false, null);  // fetchComposite=true, fetchRelatingComposite=false
        if (userAccount == null) {
            throw new RuntimeException("Data inconsistency: there is no User Account topic for username \"" +
                username.getSimpleValue() + "\" (username=" + username + ")");
        }
        return userAccount;
    }

    // ---

    /**
     * Retrieves the "Username" topic for the specified username.
     *
     * @return  The retrieved Username (a Topic of type "Username" / dm4.accesscontrol.username),
     *          or null if no such Username topic exists.
     */
    private Topic getUsername(String username) {
        return dms.getTopic("dm4.accesscontrol.username", new SimpleValue(username), false, null);
    }

    private Topic getUsername(HttpSession session) {
        Topic username = (Topic) session.getAttribute("username");
        if (username == null) {
            throw new RuntimeException("Session data inconsistency: \"username\" attribute is missing");
        }
        return username;
    }

    // ---

    /**
     * Retrieves the "Username" topic for the "admin" user.
     * If the "admin" user doesn't exist an exception is thrown.
     *
     * @return  The retrieved Username (a Topic of type "Username" / dm4.accesscontrol.username).
     */
    private Topic getAdminUser() {
        Topic username = getUsername(DEFAULT_USERNAME);
        if (username == null) {
            throw new RuntimeException("The \"" + DEFAULT_USERNAME + "\" user doesn't exist");
        }
        return username;
    }

    // ---

    /**
     * Assigns the logged in user as the creator of the specified object.
     * If no user is logged in, the default user ("admin") is assigned.
     */
    private void assignCreator(DeepaMehtaObject object) {
        Topic username = getUsername();
        //
        if (username == null) {
            logger.fine("Assigning a creator to " + info(object) + " failed (no user is logged in). " +
                "The default user (\"admin\") is assigned instead.");
            username = getAdminUser();
=======
    private void setCreator(Topic topic) {
        Topic username = getUsername();
        //
        if (username == null) {
            logger.fine("Assigning a creator to " + info(topic) + " failed " +
                "(no user is logged in). Assigning user \"admin\" instead.");
            username = fetchAdminUser();
>>>>>>> 6870789a4a1353d214dd2307d53d22170e72f2c4
        }
        //
        assignCreator(object, username.getId());
Solution content
    // ---

    /**
     * Assigns the logged in user as the creator of the specified object.
     * If no user is logged in, the default user ("admin") is assigned.
     */
    private void assignCreator(DeepaMehtaObject object) {
        Topic username = getUsername();
        //
        if (username == null) {
            logger.fine("Assigning a creator to " + info(object) + " failed (no user is logged in). " +
                "The default user (\"admin\") is assigned instead.");
            username = fetchAdminUser();
        }
        //
        assignCreator(object, username.getId());
File
AccessControlPlugin.java
Developer's decision
Combination
Kind of conflict
Comment
If statement
Method declaration
Method invocation
Method signature
Variable
Chunk
Conflicting content
        assignCreator(object, username.getId());
    }

<<<<<<< HEAD
    /**
     * Assigns the specified user as the creator of the specified object.
     */
    private void assignCreator(DeepaMehtaObject object, long usernameId) {
        facetsService.updateFacet(object, "dm4.accesscontrol.creator_facet", creatorModel(usernameId), null, null);
=======
    private void setCreator(Topic topic, long usernameId) {
        facetsService.updateFacet(topic, "dm4.accesscontrol.creator_facet", createCreatorModel(usernameId), null, null);
>>>>>>> 6870789a4a1353d214dd2307d53d22170e72f2c4
    }

    // ---
Solution content
        assignCreator(object, username.getId());
    }

    /**
     * Assigns the specified user as the creator of the specified object.
     */
    private void assignCreator(DeepaMehtaObject object, long usernameId) {
        TopicModel creatorValue = createCreatorModel(usernameId);
        facetsService.updateFacet(object, "dm4.accesscontrol.creator_facet", creatorValue, null, null);
    }

    // ---
File
AccessControlPlugin.java
Developer's decision
Manual
Kind of conflict
Comment
Method invocation
Method signature
Chunk
Conflicting content
     * @param   username    the logged in user (a Topic of type "Username" / dm4.accesscontrol.username),
     *                      or null if no user is logged in.
     */
<<<<<<< HEAD
    private boolean hasPermission(Topic username, Operation operation, DeepaMehtaObject object) {
        logger.fine("Determining permission for " + userInfo(username) + " to " + operation + " " + info(object));
        for (RelatedTopic aclEntry : getACLEntries(object)) {
=======
    private boolean hasPermission(Topic username, Operation operation, Topic topic) {
        logger.fine("Determining permission for " + userInfo(username) + " to " + operation + " " + info(topic));
        for (RelatedTopic aclEntry : fetchACLEntries(topic)) {
>>>>>>> 6870789a4a1353d214dd2307d53d22170e72f2c4
            String roleUri = aclEntry.getCompositeValue().getTopic("dm4.accesscontrol.role").getUri();
            logger.fine("There is an ACL entry for role \"" + roleUri + "\"");
            boolean allowedForRole = allowed(aclEntry, operation);
Solution content
     * @param   username    the logged in user (a Topic of type "Username" / dm4.accesscontrol.username),
     *                      or null if no user is logged in.
     */
    private boolean hasPermission(Topic username, Operation operation, DeepaMehtaObject object) {
        logger.fine("Determining permission for " + userInfo(username) + " to " + operation + " " + info(object));
        for (RelatedTopic aclEntry : fetchACLEntries(object)) {
            String roleUri = aclEntry.getCompositeValue().getTopic("dm4.accesscontrol.role").getUri();
            logger.fine("There is an ACL entry for role \"" + roleUri + "\"");
            boolean allowedForRole = allowed(aclEntry, operation);
File
AccessControlPlugin.java
Developer's decision
Manual
Kind of conflict
For statement
Method invocation
Method signature
Chunk
Conflicting content
    // ---

<<<<<<< HEAD
    /**
     * Retrieves all ACL entries of the specified object.
     */
    private Set getACLEntries(DeepaMehtaObject object) {
        return facetsService.getFacets(object, "dm4.accesscontrol.acl_facet");
    }

    /**
     * For the specified ACL entry: reads out the "allowed" value for the specified operation.
     * If no "allowed" value is set for that operation false is returned.
     */
    private boolean allowed(Topic aclEntry, Operation operation) {
        for (TopicModel permission : aclEntry.getCompositeValue().getTopics("dm4.accesscontrol.permission")) {
            if (permission.getCompositeValue().getTopic("dm4.accesscontrol.operation").getUri().equals(operation.uri)) {
                return permission.getCompositeValue().getBoolean("dm4.accesscontrol.allowed");
            }
        }
        return false;
    }

    // ---

=======
>>>>>>> 6870789a4a1353d214dd2307d53d22170e72f2c4
    /**
     * Retrieves the creator of an object, or null if no creator is set.
     *
Solution content
    // ---

    /**
     * Retrieves the creator of an object, or null if no creator is set.
     *
File
AccessControlPlugin.java
Developer's decision
Version 2
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
    private void enrichWithPermissions(DeepaMehtaObject object, boolean write) {
        // Note: we must extend/override possibly existing permissions.
        // Consider a type update: directive UPDATE_TOPIC_TYPE is followed by UPDATE_TOPIC, both on the same object.
<<<<<<< HEAD
        CompositeValue permissions = getPermissions(object);
=======
        CompositeValue permissions = permissions(topic);
>>>>>>> 6870789a4a1353d214dd2307d53d22170e72f2c4
        permissions.put(Operation.WRITE.uri, write);
    }
Solution content
    private void enrichWithPermissions(DeepaMehtaObject object, boolean write) {
        // Note: we must extend/override possibly existing permissions.
        // Consider a type update: directive UPDATE_TOPIC_TYPE is followed by UPDATE_TOPIC, both on the same object.
        CompositeValue permissions = permissions(object);
        permissions.put(Operation.WRITE.uri, write);
    }
File
AccessControlPlugin.java
Developer's decision
Manual
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
    // ---

<<<<<<< HEAD
    private CompositeValue getPermissions(DeepaMehtaObject object) {
=======
    private CompositeValue permissions(Topic topic) {
>>>>>>> 6870789a4a1353d214dd2307d53d22170e72f2c4
        // Note: "dm4.accesscontrol.permissions" is a contrived URI. There is no such type definition.
        // Permissions are transient data, not stored in DB, recalculated for each request.
        TopicModel permissionsTopic = object.getCompositeValue().getTopic("dm4.accesscontrol.permissions", null);
Solution content
    // ---

    private CompositeValue permissions(DeepaMehtaObject object) {
        // Note: "dm4.accesscontrol.permissions" is a contrived URI. There is no such type definition.
        // Permissions are transient data, not stored in DB, recalculated for each request.
        TopicModel permissionsTopic = object.getCompositeValue().getTopic("dm4.accesscontrol.permissions", null);
File
AccessControlPlugin.java
Developer's decision
Manual
Kind of conflict
Method signature