sergehuber commented on code in PR #755: URL: https://github.com/apache/unomi/pull/755#discussion_r3253188067
########## tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/dev/commands/goals/GoalCrudCommand.java: ########## @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.unomi.shell.dev.commands.goals; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.unomi.api.Metadata; +import org.apache.unomi.api.PartialList; +import org.apache.unomi.api.goals.Goal; +import org.apache.unomi.api.query.Query; +import org.apache.unomi.api.services.GoalsService; +import org.apache.unomi.persistence.spi.CustomObjectMapper; +import org.apache.unomi.shell.dev.services.BaseCrudCommand; +import org.apache.unomi.shell.dev.services.CrudCommand; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * A command to perform CRUD operations on goals + */ +@Component(service = CrudCommand.class, immediate = true) +public class GoalCrudCommand extends BaseCrudCommand { + + private static final ObjectMapper OBJECT_MAPPER = new CustomObjectMapper(); + private static final List<String> PROPERTY_NAMES = List.of( + "itemId", "name", "description", "scope", "campaignId", "enabled" + ); + + @Reference + private GoalsService goalsService; + + @Override + public String getObjectType() { + return "goal"; + } + + @Override + protected String[] getHeadersWithoutTenant() { + return new String[]{"ID", "Name", "Description", "Scope", "Campaign ID", "Enabled"}; + } + + @Override + protected PartialList<?> getItems(Query query) { + // Convert Set<Metadata> to PartialList for consistency + Set<Metadata> metadatas = goalsService.getGoalMetadatas(query); + List<Goal> goals = metadatas.stream() + .map(metadata -> goalsService.getGoal(metadata.getId())) + .filter(goal -> goal != null) + .collect(Collectors.toList()); + return new PartialList<>(goals, goals.size(), 0, goals.size(), null); + } Review Comment: Fixed: PartialList now uses query.getOffset(), goals.size(), and Relation.EQUAL -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
