Search in sources :

Example 16 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class LicensesPortlet method updateWhiteList.

@UsedAsLiferayAction
public void updateWhiteList(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    // we get a list of todoDatabaseIds and Booleans and we have to update the whiteList of each todo if it changed
    String licenseId = request.getParameter(LICENSE_ID);
    String[] whiteList = request.getParameterValues("whiteList");
    // As empty arrays are not passed as parameters
    if (whiteList == null)
        whiteList = new String[0];
    final User user = UserCacheHolder.getUserFromRequest(request);
    String moderationComment = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
    if (moderationComment != null) {
        user.setCommentMadeDuringModerationRequest(moderationComment);
    }
    try {
        LicenseService.Iface client = thriftClients.makeLicenseClient();
        RequestStatus requestStatus = client.updateWhitelist(licenseId, ImmutableSet.copyOf(whiteList), user);
        setSessionMessage(request, requestStatus, "License", "update");
    } catch (TException e) {
        log.error("Error updating whitelist!", e);
    }
    response.setRenderParameter(LICENSE_ID, licenseId);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "Todos");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 17 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class LicensesPortlet method addTodo.

@UsedAsLiferayAction
public void addTodo(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String licenseID = request.getParameter(LICENSE_ID);
    String[] obligationIds = request.getParameterValues("obligations");
    String todoText = request.getParameter("todoText");
    String[] bools = request.getParameterValues("bools");
    Todo todo = new Todo();
    // add temporary id
    todo.setId(TMP_TODO_ID_PREFIX + UUID.randomUUID().toString());
    if (obligationIds != null) {
        for (String obligationId : obligationIds) {
            if (obligationId != null && !obligationId.isEmpty()) {
                todo.addToObligationDatabaseIds(obligationId);
            }
        }
    } else {
        todo.setObligationDatabaseIds(Collections.emptySet());
    }
    todo.setText(todoText);
    User user = UserCacheHolder.getUserFromRequest(request);
    String moderationComment = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
    if (moderationComment != null) {
        user.setCommentMadeDuringModerationRequest(moderationComment);
    }
    todo.addToWhitelist(user.getDepartment());
    if (bools != null) {
        List<String> theBools = Arrays.asList(bools);
        todo.setDevelopment(theBools.contains("development"));
        todo.setDistribution(theBools.contains("distribution"));
    } else {
        todo.setDevelopment(false);
        todo.setDistribution(false);
    }
    try {
        LicenseService.Iface client = thriftClients.makeLicenseClient();
        RequestStatus requestStatus = client.addTodoToLicense(todo, licenseID, user);
        setSessionMessage(request, requestStatus, "License", "update");
    } catch (TException e) {
        log.error("Error updating license details from backend", e);
    }
    response.setRenderParameter(LICENSE_ID, licenseID);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "Todos");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 18 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class ComponentUploadPortlet method updateLicenses.

@UsedAsLiferayAction
public void updateLicenses(ActionRequest request, ActionResponse response) throws PortletException, IOException, TException {
    final HashMap<String, InputStream> inputMap = new HashMap<>();
    User user = UserCacheHolder.getUserFromRequest(request);
    try {
        fillFilenameInputStreamMap(request, inputMap);
        if (ZipTools.isValidLicenseArchive(inputMap)) {
            final LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
            log.debug("Parsing risk categories ...");
            Map<Integer, RiskCategory> riskCategoryMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(RISK_CATEGORY_FILE), RiskCategory.class, Integer.class, user);
            log.debug("Parsing risks ...");
            Map<Integer, Risk> riskMap = getIntegerRiskMap(licenseClient, riskCategoryMap, inputMap.get(RISK_FILE), user);
            log.debug("Parsing obligations ...");
            Map<Integer, Obligation> obligationMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(OBLIGATION_FILE), Obligation.class, Integer.class, user);
            log.debug("Parsing obligation todos ...");
            List<CSVRecord> obligationTodoRecords = readAsCSVRecords(inputMap.get(OBLIGATION_TODO_FILE));
            Map<Integer, Set<Integer>> obligationTodoMapping = convertRelationalTableWithIntegerKeys(obligationTodoRecords);
            log.debug("Parsing license types ...");
            Map<Integer, LicenseType> licenseTypeMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(LICENSETYPE_FILE), LicenseType.class, Integer.class, user);
            log.debug("Parsing todos ...");
            Map<Integer, Todo> todoMap = getTodoMapAndWriteMissingToDatabase(licenseClient, obligationMap, obligationTodoMapping, inputMap.get(TODO_FILE), user);
            if (inputMap.containsKey(CUSTOM_PROPERTIES_FILE)) {
                log.debug("Parsing custom properties ...");
                Map<Integer, PropertyWithValue> customPropertiesMap = getCustomPropertiesWithValuesByIdAndWriteMissingToDatabase(licenseClient, inputMap.get(CUSTOM_PROPERTIES_FILE), user);
                log.debug("Parsing todo custom properties relation ...");
                List<CSVRecord> todoPropertiesRecord = readAsCSVRecords(inputMap.get(TODO_CUSTOM_PROPERTIES_FILE));
                Map<Integer, Set<Integer>> todoPropertiesMap = convertRelationalTableWithIntegerKeys(todoPropertiesRecord);
                todoMap = updateTodoMapWithCustomPropertiesAndWriteToDatabase(licenseClient, todoMap, customPropertiesMap, todoPropertiesMap, user);
            }
            log.debug("Parsing license todos ...");
            List<CSVRecord> licenseTodoRecord = readAsCSVRecords(inputMap.get(LICENSE_TODO_FILE));
            Map<String, Set<Integer>> licenseTodoMap = convertRelationalTable(licenseTodoRecord);
            log.debug("Parsing license risks ...");
            List<CSVRecord> licenseRiskRecord = readAsCSVRecords(inputMap.get(LICENSE_RISK_FILE));
            Map<String, Set<Integer>> licenseRiskMap = convertRelationalTable(licenseRiskRecord);
            log.debug("Parsing licenses ...");
            List<CSVRecord> licenseRecord = readAsCSVRecords(inputMap.get(LICENSE_FILE));
            final List<License> licensesToAdd = ConvertRecord.fillLicenses(licenseRecord, licenseTypeMap, todoMap, riskMap, licenseTodoMap, licenseRiskMap);
            addLicenses(licenseClient, licensesToAdd, log, user);
        } else {
            throw new SW360Exception("Invalid file format");
        }
    } finally {
        for (InputStream inputStream : inputMap.values()) {
            inputStream.close();
        }
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) CSVRecord(org.apache.commons.csv.CSVRecord) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 19 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class LicenseDatabaseHandler method updateWhitelist.

/**
 * Update the whitelisted todos for an organisation
 */
public RequestStatus updateWhitelist(String licenseId, Set<String> whitelistTodos, User user) throws SW360Exception {
    License license = licenseRepository.get(licenseId);
    assertNotNull(license);
    String organisation = user.getDepartment();
    String businessUnit = SW360Utils.getBUFromOrganisation(organisation);
    if (makePermission(license, user).isActionAllowed(RequestedAction.WRITE)) {
        List<Todo> todos = todoRepository.get(license.todoDatabaseIds);
        for (Todo todo : todos) {
            String todoId = todo.getId();
            Set<String> currentWhitelist = todo.whitelist != null ? todo.whitelist : new HashSet<>();
            // Add to whitelist if necessary
            if (whitelistTodos.contains(todoId) && !currentWhitelist.contains(businessUnit)) {
                todo.addToWhitelist(businessUnit);
                todoRepository.update(todo);
            }
            // Remove from whitelist if necessary
            if (!whitelistTodos.contains(todoId) && currentWhitelist.contains(businessUnit)) {
                currentWhitelist.remove(businessUnit);
                todoRepository.update(todo);
            }
        }
        return RequestStatus.SUCCESS;
    } else {
        // add updated whitelists to todos in moderation request, not yet in database
        License licenseForModerationRequest = getLicenseForOrganisationWithOwnModerationRequests(licenseId, user.getDepartment(), user);
        List<Todo> todos = licenseForModerationRequest.getTodos();
        for (Todo todo : todos) {
            String todoId = todo.getId();
            Set<String> currentWhitelist = todo.whitelist != null ? todo.whitelist : new HashSet<>();
            // Add to whitelist if necessary
            if (whitelistTodos.contains(todoId) && !currentWhitelist.contains(businessUnit)) {
                todo.addToWhitelist(businessUnit);
            }
            // Remove from whitelist if necessary
            if (!whitelistTodos.contains(todoId) && currentWhitelist.contains(businessUnit)) {
                currentWhitelist.remove(businessUnit);
            }
        }
        // Only moderators can edit whitelists!
        return moderator.updateLicense(licenseForModerationRequest, user);
    }
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

Example 20 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class LicenseDatabaseHandler method fillLicenseForOrganisation.

private void fillLicenseForOrganisation(String organisation, License license) {
    if (license.isSetTodoDatabaseIds()) {
        license.setTodos(getTodosByIds(license.todoDatabaseIds));
    }
    if (license.isSetTodos()) {
        for (Todo todo : license.getTodos()) {
            // remove other organisations from whitelist of todo
            todo.setWhitelist(SW360Utils.filterBUSet(organisation, todo.whitelist));
            if (todo.isSetObligationDatabaseIds()) {
                todo.setObligations(getObligationsByIds(todo.obligationDatabaseIds));
            }
        }
    }
    if (license.isSetLicenseTypeDatabaseId()) {
        final LicenseType licenseType = licenseTypeRepository.get(license.getLicenseTypeDatabaseId());
        license.setLicenseType(licenseType);
    }
    if (license.isSetRiskDatabaseIds()) {
        license.setRisks(getRisksByIds(license.riskDatabaseIds));
        license.unsetRiskDatabaseIds();
    }
    license.setShortname(license.getId());
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)7 TException (org.apache.thrift.TException)6 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)6 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 Strings (com.google.common.base.Strings)3 java.util (java.util)3 CSVRecord (org.apache.commons.csv.CSVRecord)3 Logger (org.apache.log4j.Logger)3 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)3 ThriftEnumUtils (org.eclipse.sw360.datahandler.common.ThriftEnumUtils)3 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)3 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 org.eclipse.sw360.datahandler.thrift.licenses (org.eclipse.sw360.datahandler.thrift.licenses)3 Todo (org.eclipse.sw360.datahandler.thrift.licenses.Todo)3 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)3 NotNull (org.jetbrains.annotations.NotNull)3 Function (com.google.common.base.Function)2 com.google.common.collect (com.google.common.collect)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2