diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-03-22 15:33:06 +0000 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-03-24 06:59:47 +0000 |
commit | d378c37fbd1ecec7b43394926f1ca32a695e07de (patch) | |
tree | 5c8a085f8732f980d871d966ac49361644efa698 /openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java | |
parent | a6ae7294ecd336d7e88f915710b08e2658eaee00 (diff) |
Reformat openecomp-be
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3449
Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java')
17 files changed, 253 insertions, 375 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java index ae8e095acb..066acb9370 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java @@ -15,27 +15,31 @@ */ package org.openecomp.sdcrests.item.rest; +import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; +import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG; + import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tags; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdcrests.item.types.ItemActionRequestDto; -import org.springframework.validation.annotation.Validated; - import javax.validation.constraints.NotNull; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - - -import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; -import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG; +import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdcrests.item.types.ItemActionRequestDto; +import org.springframework.validation.annotation.Validated; @Path("/v1.0/items") @Produces(MediaType.APPLICATION_JSON) @@ -57,23 +61,16 @@ public interface Items { @QueryParam("permission") String permissionFilter, @Parameter(description = "Filter by onboarding method", schema = @Schema(type = "string", allowableValues = {"NetworkPackage", "manual"})) @QueryParam("onboardingMethod") String onboardingMethodFilter, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); @GET @Path("/{itemId}") @Operation(description = "Get details of a item") - Response getItem(@PathParam("itemId") String itemId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); + Response getItem(@PathParam("itemId") String itemId, @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); @PUT @Path("/{itemId}/actions") @Operation(description = "Acts on item version") - Response actOn(ItemActionRequestDto request, - @PathParam("itemId") String itemId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); - - + Response actOn(ItemActionRequestDto request, @PathParam("itemId") String itemId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Versions.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Versions.java index edc0596282..0335f894b8 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Versions.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Versions.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -17,28 +17,35 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.item.rest; +import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; +import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG; + import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tags; -import org.openecomp.sdcrests.item.types.*; -import org.springframework.validation.annotation.Validated; - import javax.validation.constraints.NotNull; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - -import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; -import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG; +import org.openecomp.sdcrests.item.types.ActivityLogDto; +import org.openecomp.sdcrests.item.types.VersionActionRequestDto; +import org.openecomp.sdcrests.item.types.VersionDto; +import org.openecomp.sdcrests.item.types.VersionRequestDto; +import org.springframework.validation.annotation.Validated; @Path("/v1.0/items/{itemId}/versions") @Produces(MediaType.APPLICATION_JSON) @@ -47,52 +54,39 @@ import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG @Validated public interface Versions { - @GET - @Path("/") - @Operation(description = "Lists item versions", responses = @ApiResponse(content = @Content(array = @ArraySchema( schema = @Schema(implementation = VersionDto.class))))) - Response list(@PathParam("itemId") String itemId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); + @GET + @Path("/") + @Operation(description = "Lists item versions", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = VersionDto.class))))) + Response list(@PathParam("itemId") String itemId, @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); - @POST - @Path("/{versionId}") - @Operation(description = "Creates a new item version") - Response create(VersionRequestDto request, - @PathParam("itemId") String itemId, - @PathParam("versionId") String versionId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); + @POST + @Path("/{versionId}") + @Operation(description = "Creates a new item version") + Response create(VersionRequestDto request, @PathParam("itemId") String itemId, @PathParam("versionId") String versionId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); - @GET - @Path("/{versionId}") - @Operation(description = "Gets item version", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = VersionDto.class)))) - Response get(@PathParam("itemId") String itemId, - @PathParam("versionId") String versionId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); + @GET + @Path("/{versionId}") + @Operation(description = "Gets item version", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = VersionDto.class)))) + Response get(@PathParam("itemId") String itemId, @PathParam("versionId") String versionId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); - @GET - @Path("/{versionId}/activity-logs") - @Operation(description = "Gets item version activity log", responses = @ApiResponse(content = @Content(array = @ArraySchema( schema = @Schema(implementation = ActivityLogDto.class))))) - Response getActivityLog(@Parameter(description = "Item Id") @PathParam("itemId") String itemId, - @Parameter( description = "Version Id") @PathParam("versionId") String versionId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); + @GET + @Path("/{versionId}/activity-logs") + @Operation(description = "Gets item version activity log", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = ActivityLogDto.class))))) + Response getActivityLog(@Parameter(description = "Item Id") @PathParam("itemId") String itemId, + @Parameter(description = "Version Id") @PathParam("versionId") String versionId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); - @GET - @Path("/{versionId}/revisions") - @Operation(description = "Gets item version revisions", responses = @ApiResponse(content = @Content(array = @ArraySchema( schema = @Schema(implementation = ActivityLogDto.class))))) - Response listRevisions(@PathParam("itemId") String itemId, - @PathParam("versionId") String versionId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); + @GET + @Path("/{versionId}/revisions") + @Operation(description = "Gets item version revisions", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = ActivityLogDto.class))))) + Response listRevisions(@PathParam("itemId") String itemId, @PathParam("versionId") String versionId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); - @PUT - @Path("/{versionId}/actions") - @Operation(description = "Acts on item version") - Response actOn(VersionActionRequestDto request, - @PathParam("itemId") String itemId, - @PathParam("versionId") String versionId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user); + @PUT + @Path("/{versionId}/actions") + @Operation(description = "Acts on item version") + Response actOn(VersionActionRequestDto request, @PathParam("itemId") String itemId, @PathParam("versionId") String versionId, + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapActivityLogEntityToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapActivityLogEntityToDto.java index 307b555720..633da0a92a 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapActivityLogEntityToDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapActivityLogEntityToDto.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.item.rest.mapping; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; @@ -25,17 +24,15 @@ import org.openecomp.sdcrests.item.types.ActivityLogDto; import org.openecomp.sdcrests.item.types.ActivityStatus; import org.openecomp.sdcrests.mapping.MappingBase; -public class MapActivityLogEntityToDto - extends MappingBase<ActivityLogEntity, ActivityLogDto> { - +public class MapActivityLogEntityToDto extends MappingBase<ActivityLogEntity, ActivityLogDto> { - @Override - public void doMapping(ActivityLogEntity source, ActivityLogDto target) { - target.setId(source.getId()); - target.setTimestamp(source.getTimestamp()); - target.setType(source.getType().name()); - target.setComment(source.getComment()); - target.setUser(source.getUser()); - target.setStatus(new ActivityStatus(source.isSuccess(), source.getMessage())); - } + @Override + public void doMapping(ActivityLogEntity source, ActivityLogDto target) { + target.setId(source.getId()); + target.setTimestamp(source.getTimestamp()); + target.setType(source.getType().name()); + target.setComment(source.getComment()); + target.setUser(source.getUser()); + target.setStatus(new ActivityStatus(source.isSuccess(), source.getMessage())); + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java index 68bd9a51fb..3bd8a7fe9f 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.item.rest.mapping; import org.openecomp.sdc.versioning.types.Item; @@ -25,14 +24,15 @@ import org.openecomp.sdcrests.item.types.ItemDto; import org.openecomp.sdcrests.mapping.MappingBase; public class MapItemToDto extends MappingBase<Item, ItemDto> { - @Override - public void doMapping(Item source, ItemDto target) { - target.setId(source.getId()); - target.setType(source.getType()); - target.setName(source.getName()); - target.setDescription(source.getDescription()); - target.setOwner(source.getOwner()); - target.setStatus(source.getStatus().name()); - target.setProperties(source.getProperties()); - } + + @Override + public void doMapping(Item source, ItemDto target) { + target.setId(source.getId()); + target.setType(source.getType()); + target.setName(source.getName()); + target.setDescription(source.getDescription()); + target.setOwner(source.getOwner()); + target.setStatus(source.getStatus().name()); + target.setProperties(source.getProperties()); + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapRevisionToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapRevisionToDto.java index b66b289ce9..13838f794b 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapRevisionToDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapRevisionToDto.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.item.rest.mapping; import org.openecomp.sdc.versioning.dao.types.Revision; @@ -25,11 +24,12 @@ import org.openecomp.sdcrests.item.types.RevisionDto; import org.openecomp.sdcrests.mapping.MappingBase; public class MapRevisionToDto extends MappingBase<Revision, RevisionDto> { - @Override - public void doMapping(Revision source, RevisionDto target) { - target.setId(source.getId()); - target.setMessage(source.getMessage()); - target.setUser(source.getUser()); - target.setTime(source.getTime()); - } + + @Override + public void doMapping(Revision source, RevisionDto target) { + target.setId(source.getId()); + target.setMessage(source.getMessage()); + target.setUser(source.getUser()); + target.setTime(source.getTime()); + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapVersionToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapVersionToDto.java index a29ac8acf6..382b85a761 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapVersionToDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapVersionToDto.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.item.rest.mapping; import org.openecomp.sdc.versioning.dao.types.Version; @@ -25,16 +24,17 @@ import org.openecomp.sdcrests.item.types.VersionDto; import org.openecomp.sdcrests.mapping.MappingBase; public class MapVersionToDto extends MappingBase<Version, VersionDto> { - @Override - public void doMapping(Version source, VersionDto target) { - target.setId(source.getId()); - target.setName(source.getName()); - target.setDescription(source.getDescription()); - target.setBaseId(source.getBaseId()); - target.setStatus(source.getStatus()); - target.setState(source.getState()); - target.setCreationTime(source.getCreationTime()); - target.setModificationTime(source.getModificationTime()); - target.setAdditionalInfo(source.getAdditionalInfo()); - } + + @Override + public void doMapping(Version source, VersionDto target) { + target.setId(source.getId()); + target.setName(source.getName()); + target.setDescription(source.getDescription()); + target.setBaseId(source.getBaseId()); + target.setStatus(source.getStatus()); + target.setState(source.getState()); + target.setCreationTime(source.getCreationTime()); + target.setModificationTime(source.getModificationTime()); + target.setAdditionalInfo(source.getAdditionalInfo()); + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/models/SyncEvent.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/models/SyncEvent.java index c057ecf7e0..716ae8dcf3 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/models/SyncEvent.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/models/SyncEvent.java @@ -55,5 +55,4 @@ public class SyncEvent implements Event { public String getEntityId() { return entityId; } - -}
\ No newline at end of file +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java index 4c1a0fb659..f18de66863 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java @@ -13,10 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services; +import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME; + import com.google.common.annotations.VisibleForTesting; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import javax.annotation.PostConstruct; +import javax.inject.Named; +import javax.ws.rs.core.Response; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.activitylog.dao.type.ActivityType; import org.openecomp.sdc.datatypes.model.ItemType; @@ -42,17 +59,6 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import javax.annotation.PostConstruct; -import javax.inject.Named; -import javax.ws.rs.core.Response; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER; -import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID; -import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME; - @Named @Service("items") @Scope(value = "prototype") @@ -61,26 +67,21 @@ public class ItemsImpl implements Items { private static final String ONBOARDING_METHOD = "onboardingMethod"; private static final Logger LOGGER = LoggerFactory.getLogger(ItemsImpl.class); - private Map<ItemAction, ActionSideAffects> actionSideAffectsMap = new EnumMap<>(ItemAction.class); private ManagersProvider managersProvider; @PostConstruct public void initActionSideAffectsMap() { - actionSideAffectsMap - .put(ItemAction.ARCHIVE, new ActionSideAffects(ActivityType.Archive, NotificationEventTypes.ARCHIVE)); - actionSideAffectsMap - .put(ItemAction.RESTORE, new ActionSideAffects(ActivityType.Restore, NotificationEventTypes.RESTORE)); + actionSideAffectsMap.put(ItemAction.ARCHIVE, new ActionSideAffects(ActivityType.Archive, NotificationEventTypes.ARCHIVE)); + actionSideAffectsMap.put(ItemAction.RESTORE, new ActionSideAffects(ActivityType.Restore, NotificationEventTypes.RESTORE)); } @Override public Response actOn(ItemActionRequestDto request, String itemId, String user) { - Item item = getManagersProvider().getItemManager().get(itemId); if (item == null) { return Response.status(Response.Status.NOT_FOUND).entity(new Exception("Item does not exist.")).build(); } - switch (request.getAction()) { case ARCHIVE: getManagersProvider().getItemManager().archive(item); @@ -90,7 +91,6 @@ public class ItemsImpl implements Items { break; default: } - actionSideAffectsMap.get(request.getAction()).execute(item, user); try { Notifier catalogNotifier = NotifierFactory.getInstance(); @@ -98,81 +98,32 @@ public class ItemsImpl implements Items { } catch (Exception e) { LOGGER.error("Failed to send catalog notification on item {}", itemId, e); } - return Response.ok().build(); } @Override - public Response list(String itemStatusFilter, String versionStatusFilter, String itemTypeFilter, - String permissionFilter, String onboardingMethodFilter, String user) { - - Predicate<Item> itemPredicate = - createItemPredicate(itemStatusFilter, versionStatusFilter, itemTypeFilter, onboardingMethodFilter, - permissionFilter, user); - + public Response list(String itemStatusFilter, String versionStatusFilter, String itemTypeFilter, String permissionFilter, + String onboardingMethodFilter, String user) { + Predicate<Item> itemPredicate = createItemPredicate(itemStatusFilter, versionStatusFilter, itemTypeFilter, onboardingMethodFilter, + permissionFilter, user); GenericCollectionWrapper<ItemDto> results = new GenericCollectionWrapper<>(); MapItemToDto mapper = new MapItemToDto(); getManagersProvider().getItemManager().list(itemPredicate).stream() - .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())) - .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class))); - + .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())) + .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class))); return Response.ok(results).build(); - } @Override public Response getItem(String itemId, String user) { Item item = getManagersProvider().getItemManager().get(itemId); ItemDto itemDto = new MapItemToDto().applyMapping(item, ItemDto.class); - return Response.ok(itemDto).build(); } - private class ActionSideAffects { - - private ActivityType activityType; - private NotificationEventTypes notificationType; - - private ActionSideAffects(ActivityType activityType, NotificationEventTypes notificationType) { - this.activityType = activityType; - this.notificationType = notificationType; - - } - - private Version getLatestVersion(String itemId) { - List<Version> list = getManagersProvider().getVersioningManager().list(itemId); - Optional<Version> max = list.stream().max(Version::compareTo); - - return max.orElse(null); - } - - private void execute(Item item, String user) { - notifyUsers(item.getId(), item.getName(), user, this.notificationType); - getManagersProvider().getActivityLogManager().logActivity( - new ActivityLogEntity(item.getId(), getLatestVersion(item.getId()), this.activityType, user, true, - "", "")); - } - - private void notifyUsers(String itemId, String itemName, String userName, NotificationEventTypes eventType) { - Map<String, Object> eventProperties = new HashMap<>(); - eventProperties.put(ITEM_NAME, itemName == null ? getManagersProvider().getItemManager().get(itemId).getName() : itemName); - eventProperties.put(ITEM_ID, itemId); - - eventProperties.put(PERMISSION_USER, userName); - - Event syncEvent = new SyncEvent(eventType.getEventName(), itemId, eventProperties, itemId); - try { - getManagersProvider().getNotificationPropagationManager().notifySubscribers(syncEvent, userName); - } catch (Exception e) { - LOGGER.error("Failed to send sync notification to users subscribed to item '{}'", itemId, e); - } - } - } - - private Predicate<Item> createItemPredicate(String itemStatusFilter, String versionStatusFilter, - String itemTypeFilter, String onboardingMethodFilter, String permissionsFilter, String user) { + private Predicate<Item> createItemPredicate(String itemStatusFilter, String versionStatusFilter, String itemTypeFilter, + String onboardingMethodFilter, String permissionsFilter, String user) { Predicate<Item> itemPredicate = item -> true; - if (itemStatusFilter != null) { validateItemStatusValue(itemStatusFilter); itemPredicate = itemPredicate.and(createItemStatusPredicate(itemStatusFilter)); @@ -205,8 +156,7 @@ public class ItemsImpl implements Items { } private Predicate<Item> createVersionStatusPredicate(String filterValue) { - Set<VersionStatus> versionStatuses = - Arrays.stream(filterValue.split(",")).map(VersionStatus::valueOf).collect(Collectors.toSet()); + Set<VersionStatus> versionStatuses = Arrays.stream(filterValue.split(",")).map(VersionStatus::valueOf).collect(Collectors.toSet()); return item -> item.getVersionStatusCounters().keySet().stream().anyMatch(versionStatuses::contains); } @@ -215,9 +165,8 @@ public class ItemsImpl implements Items { } private Predicate<Item> createOnboardingMethodPredicate(String filterValue) { - return item -> !ItemType.vsp.name().equals(item.getType()) || ((String) item.getProperties() - .get(ONBOARDING_METHOD)) - .matches(formatFilter(filterValue)); + return item -> !ItemType.vsp.name().equals(item.getType()) || ((String) item.getProperties().get(ONBOARDING_METHOD)) + .matches(formatFilter(filterValue)); } private Predicate<Item> createPermissionsPredicate(String user, String filterValue) { @@ -241,7 +190,6 @@ public class ItemsImpl implements Items { for (String value : values) { VersionStatus.valueOf(value); } - } private void validateItemTypeValue(String itemTypeFilter) { @@ -265,26 +213,59 @@ public class ItemsImpl implements Items { } } - //Do not delete - is in use, duplicates code to prevent dependency on openecomp-sdc-vendor-software-product-api - private enum OnboardingMethod { - NetworkPackage, Manual - } - - @VisibleForTesting - void setManagersProvider(ManagersProvider managersProvider) { - this.managersProvider = managersProvider; - } - @VisibleForTesting Map<ItemAction, ActionSideAffects> getActionSideAffectsMap() { return actionSideAffectsMap; } private ManagersProvider getManagersProvider() { - if (managersProvider == null){ + if (managersProvider == null) { managersProvider = new ManagersProvider(); } return managersProvider; } + @VisibleForTesting + void setManagersProvider(ManagersProvider managersProvider) { + this.managersProvider = managersProvider; + } + + //Do not delete - is in use, duplicates code to prevent dependency on openecomp-sdc-vendor-software-product-api + private enum OnboardingMethod {NetworkPackage, Manual} + + private class ActionSideAffects { + + private ActivityType activityType; + private NotificationEventTypes notificationType; + + private ActionSideAffects(ActivityType activityType, NotificationEventTypes notificationType) { + this.activityType = activityType; + this.notificationType = notificationType; + } + + private Version getLatestVersion(String itemId) { + List<Version> list = getManagersProvider().getVersioningManager().list(itemId); + Optional<Version> max = list.stream().max(Version::compareTo); + return max.orElse(null); + } + + private void execute(Item item, String user) { + notifyUsers(item.getId(), item.getName(), user, this.notificationType); + getManagersProvider().getActivityLogManager() + .logActivity(new ActivityLogEntity(item.getId(), getLatestVersion(item.getId()), this.activityType, user, true, "", "")); + } + + private void notifyUsers(String itemId, String itemName, String userName, NotificationEventTypes eventType) { + Map<String, Object> eventProperties = new HashMap<>(); + eventProperties.put(ITEM_NAME, itemName == null ? getManagersProvider().getItemManager().get(itemId).getName() : itemName); + eventProperties.put(ITEM_ID, itemId); + eventProperties.put(PERMISSION_USER, userName); + Event syncEvent = new SyncEvent(eventType.getEventName(), itemId, eventProperties, itemId); + try { + getManagersProvider().getNotificationPropagationManager().notifySubscribers(syncEvent, userName); + } catch (Exception e) { + LOGGER.error("Failed to send sync notification to users subscribed to item '{}'", itemId, e); + } + } + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ManagersProvider.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ManagersProvider.java index 9d2ca6ef57..8db02f777f 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ManagersProvider.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ManagersProvider.java @@ -37,12 +37,12 @@ import org.openecomp.sdc.versioning.VersioningManagerFactory; @Getter class ManagersProvider { + private PermissionsManager permissionsManager = PermissionsManagerFactory.getInstance().createInterface(); private AsdcItemManager asdcItemManager = AsdcItemManagerFactory.getInstance().createInterface(); private VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface(); private ConflictsManager conflictsManager = ConflictsManagerFactory.getInstance().createInterface(); private ActivityLogManager activityLogManager = ActivityLogManagerFactory.getInstance().createInterface(); - private NotificationPropagationManager notificationPropagationManager = NotificationPropagationManagerFactory - .getInstance().createInterface(); + private NotificationPropagationManager notificationPropagationManager = NotificationPropagationManagerFactory.getInstance().createInterface(); private ItemManager itemManager = ItemManagerFactory.getInstance().createInterface(); } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java index 114a97a039..6e7703cda3 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java @@ -13,29 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services; +import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME; + import com.google.common.annotations.VisibleForTesting; -import org.openecomp.sdc.activitylog.ActivityLogManager; -import org.openecomp.sdc.activitylog.ActivityLogManagerFactory; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.inject.Named; +import javax.ws.rs.core.Response; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.activitylog.dao.type.ActivityType; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.Messages; -import org.openecomp.sdc.conflicts.ConflictsManager; -import org.openecomp.sdc.conflicts.ConflictsManagerFactory; -import org.openecomp.sdc.itempermissions.PermissionsManager; -import org.openecomp.sdc.itempermissions.PermissionsManagerFactory; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.notification.dtos.Event; -import org.openecomp.sdc.notification.factories.NotificationPropagationManagerFactory; -import org.openecomp.sdc.notification.services.NotificationPropagationManager; -import org.openecomp.sdc.versioning.AsdcItemManager; -import org.openecomp.sdc.versioning.AsdcItemManagerFactory; -import org.openecomp.sdc.versioning.VersioningManager; -import org.openecomp.sdc.versioning.VersioningManagerFactory; import org.openecomp.sdc.versioning.dao.types.Revision; import org.openecomp.sdc.versioning.dao.types.SynchronizationState; import org.openecomp.sdc.versioning.dao.types.Version; @@ -47,20 +46,17 @@ import org.openecomp.sdcrests.item.rest.mapping.MapActivityLogEntityToDto; import org.openecomp.sdcrests.item.rest.mapping.MapRevisionToDto; import org.openecomp.sdcrests.item.rest.mapping.MapVersionToDto; import org.openecomp.sdcrests.item.rest.models.SyncEvent; -import org.openecomp.sdcrests.item.types.*; +import org.openecomp.sdcrests.item.types.ActivityLogDto; +import org.openecomp.sdcrests.item.types.CommitRequestDto; +import org.openecomp.sdcrests.item.types.RevisionDto; +import org.openecomp.sdcrests.item.types.RevisionRequestDto; +import org.openecomp.sdcrests.item.types.VersionActionRequestDto; +import org.openecomp.sdcrests.item.types.VersionDto; +import org.openecomp.sdcrests.item.types.VersionRequestDto; import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; -import javax.inject.Named; -import javax.ws.rs.core.Response; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER; -import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.*; - @Named @Service("versions") @Scope(value = "prototype") @@ -68,16 +64,13 @@ public class VersionsImpl implements Versions { private static final String COMMIT_ITEM_ACTION = "Commit_Item"; private static final Logger LOGGER = LoggerFactory.getLogger(VersionsImpl.class); - private ManagersProvider managersProvider; @Override public Response list(String itemId, String user) { GenericCollectionWrapper<VersionDto> results = new GenericCollectionWrapper<>(); MapVersionToDto mapper = new MapVersionToDto(); - - getManagersProvider().getVersioningManager().list(itemId) - .forEach(version -> results.add(mapper.applyMapping(version, VersionDto.class))); + getManagersProvider().getVersioningManager().list(itemId).forEach(version -> results.add(mapper.applyMapping(version, VersionDto.class))); return Response.ok(results).build(); } @@ -86,15 +79,11 @@ public class VersionsImpl implements Versions { Version version = new Version(); version.setBaseId(baseVersionId); version.setDescription(request.getDescription()); - version = getManagersProvider().getVersioningManager() .create(itemId, version, VersionCreationMethod.valueOf(request.getCreationMethod().name())); - VersionDto versionDto = new MapVersionToDto().applyMapping(version, VersionDto.class); - - getManagersProvider().getActivityLogManager().logActivity( - new ActivityLogEntity(itemId, version, ActivityType.Create_Version, user, true, "", "")); - + getManagersProvider().getActivityLogManager() + .logActivity(new ActivityLogEntity(itemId, version, ActivityType.Create_Version, user, true, "", "")); return Response.ok(versionDto).build(); } @@ -109,10 +98,8 @@ public class VersionsImpl implements Versions { public Response getActivityLog(String itemId, String versionId, String user) { GenericCollectionWrapper<ActivityLogDto> results = new GenericCollectionWrapper<>(); MapActivityLogEntityToDto mapper = new MapActivityLogEntityToDto(); - getManagersProvider().getActivityLogManager().listLoggedActivities(itemId, new Version(versionId)) - .forEach(loggedActivity -> results.add(mapper.applyMapping(loggedActivity, ActivityLogDto.class))); - + .forEach(loggedActivity -> results.add(mapper.applyMapping(loggedActivity, ActivityLogDto.class))); return Response.ok(results).build(); } @@ -120,7 +107,6 @@ public class VersionsImpl implements Versions { public Response listRevisions(String itemId, String versionId, String user) { List<Revision> revisions = getManagersProvider().getVersioningManager().listRevisions(itemId, new Version(versionId)); filterRevisions(revisions); - GenericCollectionWrapper<RevisionDto> results = new GenericCollectionWrapper<>(); MapRevisionToDto mapper = new MapRevisionToDto(); revisions.forEach(revision -> results.add(mapper.applyMapping(revision, RevisionDto.class))); @@ -136,8 +122,7 @@ public class VersionsImpl implements Versions { break; case Commit: if (!getManagersProvider().getPermissionsManager().isAllowed(itemId, user, COMMIT_ITEM_ACTION)) { - return Response.status(Response.Status.FORBIDDEN) - .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build(); + return Response.status(Response.Status.FORBIDDEN).entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build(); } commit(request.getCommitRequest(), itemId, version, user); break; @@ -155,10 +140,9 @@ public class VersionsImpl implements Versions { private Version getVersion(String itemId, Version version) { Version retrievedVersion = getManagersProvider().getVersioningManager().get(itemId, version); - if (retrievedVersion.getState().getSynchronizationState() != SynchronizationState.Merging && - // looks for sdc applicative conflicts - getManagersProvider().getConflictsManager().isConflicted(itemId, retrievedVersion)) { + // looks for sdc applicative conflicts + getManagersProvider().getConflictsManager().isConflicted(itemId, retrievedVersion)) { retrievedVersion.getState().setSynchronizationState(SynchronizationState.Merging); } return retrievedVersion; @@ -170,20 +154,17 @@ public class VersionsImpl implements Versions { } private void commit(CommitRequestDto request, String itemId, Version version, String user) { - String message = request == null ? "" : request.getMessage(); - getManagersProvider().getVersioningManager().publish(itemId, version, message); notifyUsers(itemId, version, message, user, NotificationEventTypes.COMMIT); - getManagersProvider().getActivityLogManager().logActivity( - new ActivityLogEntity(itemId, version, ActivityType.Commit, user, true, "", message)); + getManagersProvider().getActivityLogManager() + .logActivity(new ActivityLogEntity(itemId, version, ActivityType.Commit, user, true, "", message)); } private void revert(RevisionRequestDto request, String itemId, String versionId) { if (request.getRevisionId() == null) { throw new CoreException(new RevisionIdNotFoundErrorBuilder().build()); } - getManagersProvider().getVersioningManager().revert(itemId, new Version(versionId), request.getRevisionId()); } @@ -195,26 +176,20 @@ public class VersionsImpl implements Versions { 3- the second revision is in format "Initial <vlm/vsp>: <name of the vlm/vsp>" 4- only if a revision in this format exists we remove the first revision. */ int numOfRevisions = revisions.size(); - if (numOfRevisions > 1 && - - revisions.get(numOfRevisions - 2).getMessage().matches("Initial .*:.*")) { + if (numOfRevisions > 1 && revisions.get(numOfRevisions - 2).getMessage().matches("Initial .*:.*")) { revisions.remove(numOfRevisions - 1); } } - private void notifyUsers(String itemId, Version version, String message, String userName, - NotificationEventTypes eventType) { + private void notifyUsers(String itemId, Version version, String message, String userName, NotificationEventTypes eventType) { Map<String, Object> eventProperties = new HashMap<>(); eventProperties.put(ITEM_NAME, getManagersProvider().getAsdcItemManager().get(itemId).getName()); eventProperties.put(ITEM_ID, itemId); - Version ver = getManagersProvider().getVersioningManager().get(itemId, version); eventProperties.put(VERSION_NAME, ver.getName()); eventProperties.put(VERSION_ID, ver.getId()); - eventProperties.put(SUBMIT_DESCRIPTION, message); eventProperties.put(PERMISSION_USER, userName); - Event syncEvent = new SyncEvent(eventType.getEventName(), itemId, eventProperties, itemId); try { getManagersProvider().getNotificationPropagationManager().notifySubscribers(syncEvent, userName); @@ -223,16 +198,15 @@ public class VersionsImpl implements Versions { } } - @VisibleForTesting - void setManagersProvider(ManagersProvider managersProvider) { - this.managersProvider = managersProvider; - } - private ManagersProvider getManagersProvider() { - if (managersProvider == null){ + if (managersProvider == null) { managersProvider = new ManagersProvider(); } return managersProvider; } + @VisibleForTesting + void setManagersProvider(ManagersProvider managersProvider) { + this.managersProvider = managersProvider; + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/AsyncNotifier.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/AsyncNotifier.java index 872c61e480..acdd1ae5aa 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/AsyncNotifier.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/AsyncNotifier.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services.catalog.notification; import java.util.Collection; @@ -38,21 +37,17 @@ import org.openecomp.sdcrests.item.types.ItemAction; public class AsyncNotifier implements Notifier { private static final ScheduledExecutorService EXECUTOR_SERVICE = Executors.newScheduledThreadPool(1); - private static final int DEFAULT_NUM_OF_RETRIES = 2; private static final long DEFAULT_INTERVAL = 5000; - private final BiFunction<Collection<String>, ItemAction, Callable<NextAction>> taskProducer; private final int numberOfRetries; private final long retryInterval; - AsyncNotifier(BiFunction<Collection<String>, ItemAction, Callable<NextAction>> taskProducer) { this(taskProducer, DEFAULT_NUM_OF_RETRIES, DEFAULT_INTERVAL); } - AsyncNotifier(BiFunction<Collection<String>, ItemAction, Callable<NextAction>> taskProducer, int numOfRetries, - long retryInterval) { + AsyncNotifier(BiFunction<Collection<String>, ItemAction, Callable<NextAction>> taskProducer, int numOfRetries, long retryInterval) { this.taskProducer = taskProducer; this.numberOfRetries = numOfRetries; this.retryInterval = retryInterval; @@ -60,30 +55,22 @@ public class AsyncNotifier implements Notifier { @Override public void execute(Collection<String> itemIds, ItemAction action) { - Callable<AsyncNotifier.NextAction> worker = taskProducer.apply(itemIds, action); - RetryingTask retryingTask = new RetryingTask(worker, numberOfRetries, retryInterval, EXECUTOR_SERVICE); - EXECUTOR_SERVICE.submit(LoggingContext.copyToCallable(retryingTask)); } - public enum NextAction { - RETRY, DONE - } + public enum NextAction {RETRY, DONE} static class RetryingTask implements Callable<Void> { private static final Logger LOGGER = LoggerFactory.getLogger(RetryingTask.class); - private final Callable<AsyncNotifier.NextAction> worker; private final long delay; private final ScheduledExecutorService scheduler; private final AtomicInteger retries; - RetryingTask(Callable<AsyncNotifier.NextAction> worker, int numOfRetries, long delay, - ScheduledExecutorService scheduler) { - + RetryingTask(Callable<AsyncNotifier.NextAction> worker, int numOfRetries, long delay, ScheduledExecutorService scheduler) { this.worker = Objects.requireNonNull(worker); this.retries = new AtomicInteger(requirePositiveRetries(numOfRetries)); this.delay = requirePositiveDelay(delay); @@ -91,38 +78,31 @@ public class AsyncNotifier implements Notifier { } private int requirePositiveRetries(int number) { - if (number < 1) { throw new IllegalArgumentException("Number of retries must be positive"); } - return number; } private long requirePositiveDelay(long number) { - if (number < 1) { throw new IllegalArgumentException("Delay must be positive"); } - return number; } @Override public Void call() throws Exception { - NextAction next = worker.call(); if (next == NextAction.DONE) { LOGGER.debug("Task successful: {}. Not going to retry", worker); return null; } - int attempts = retries.decrementAndGet(); if (attempts < 1) { LOGGER.warn("Exhausted number of retries for task {}, exiting", worker); return null; } - scheduler.schedule(this, delay, TimeUnit.MILLISECONDS); return null; } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/EntryNotConfiguredException.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/EntryNotConfiguredException.java index 070164afe6..53ccac7503 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/EntryNotConfiguredException.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/EntryNotConfiguredException.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services.catalog.notification; /** diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/Notifier.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/Notifier.java index 9143de4212..dae07ebc05 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/Notifier.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/Notifier.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services.catalog.notification; import java.util.Collection; diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/NotifierFactory.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/NotifierFactory.java index 462ffdf00c..f0bb1648dc 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/NotifierFactory.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/NotifierFactory.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services.catalog.notification; import com.fasterxml.jackson.databind.ObjectMapper; @@ -31,29 +30,27 @@ import org.openecomp.sdcrests.item.rest.services.catalog.notification.http.HttpT import org.openecomp.sdcrests.item.types.ItemAction; /** - * Creates an instance of {@link Notifier}, initialized according to current configuration. - * The configuration must be passed via the {@link #CONFIG_FILE_PROPERTY} JVM argument. + * Creates an instance of {@link Notifier}, initialized according to current configuration. The configuration must be passed via the {@link + * #CONFIG_FILE_PROPERTY} JVM argument. */ public class NotifierFactory { private static final Logger LOGGER = LoggerFactory.getLogger(NotifierFactory.class); - private static final String CONFIG_FILE_PROPERTY = "configuration.yaml"; private static final String CONFIG_SECTION = "catalogNotificationsConfig"; - private static final Notifier INSTANCE; - private NotifierFactory() { - // prevent instantiation - } - static { INSTANCE = createInstance(); } + private NotifierFactory() { + // prevent instantiation + } + /** - * Returns a {@link Notifier} instance according to the provided configuration. If no configuration was not - * provided, or the given configuration is incorrect, then an instance with reduced functionality will be returned. + * Returns a {@link Notifier} instance according to the provided configuration. If no configuration was not provided, or the given configuration + * is incorrect, then an instance with reduced functionality will be returned. * * @return available instance of {@link Notifier} */ @@ -62,18 +59,13 @@ public class NotifierFactory { } static Notifier createInstance() { - try { - String file = Objects.requireNonNull(System.getProperty(CONFIG_FILE_PROPERTY), - "Config file location must be specified via system property " + CONFIG_FILE_PROPERTY); - + "Config file location must be specified via system property " + CONFIG_FILE_PROPERTY); Object config = getNotificationConfiguration(file); ObjectMapper mapper = new ObjectMapper(); HttpConfiguration httpConfig = mapper.convertValue(config, HttpConfiguration.class); - return new AsyncNotifier(new HttpTaskProducer(httpConfig)); - } catch (Exception e) { LOGGER.warn("Failed to initialize notifier. Notifications will not be sent", e); return new UnsupportedConfigurationNotifier(); @@ -81,18 +73,15 @@ public class NotifierFactory { } private static Object getNotificationConfiguration(String file) throws IOException { - Map<?, ?> configuration = Objects.requireNonNull(readConfigurationFile(file), "Configuration cannot be empty"); Object notificationConfig = configuration.get(CONFIG_SECTION); if (notificationConfig == null) { throw new EntryNotConfiguredException(CONFIG_SECTION + " section"); } - return notificationConfig; } private static Map<?, ?> readConfigurationFile(String file) throws IOException { - try (InputStream fileInput = new FileInputStream(file)) { YamlUtil yamlUtil = new YamlUtil(); return yamlUtil.yamlToMap(fileInput); diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpConfiguration.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpConfiguration.java index 4403bd840b..e10cd5d8c3 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpConfiguration.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpConfiguration.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services.catalog.notification.http; import lombok.AllArgsConstructor; diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java index c88ac4ecce..1904bb5072 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services.catalog.notification.http; import static org.openecomp.sdcrests.item.rest.services.catalog.notification.AsyncNotifier.NextAction.DONE; @@ -42,8 +41,8 @@ import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdcrests.item.rest.services.catalog.notification.AsyncNotifier; /** - * HTTP client for notifying the Catalog of an action on items. The items are referenced by their IDs. The client can - * run multiple times, in which case only failed IDs will be re-attempted. + * HTTP client for notifying the Catalog of an action on items. The items are referenced by their IDs. The client can run multiple times, in which + * case only failed IDs will be re-attempted. * * @author evitaliy * @since 21 Nov 2018 @@ -52,10 +51,8 @@ import org.openecomp.sdcrests.item.rest.services.catalog.notification.AsyncNotif class HttpNotificationTask implements Callable<AsyncNotifier.NextAction> { private static final Logger LOGGER = LoggerFactory.getLogger(HttpNotificationTask.class); - private static final String APPLICATION_JSON = ContentType.APPLICATION_JSON.getMimeType(); private static final String USER_ID_HEADER_PARAM = "USER_ID"; - private final String endpoint; private final String userId; private volatile Collection<String> itemIds; @@ -68,59 +65,41 @@ class HttpNotificationTask implements Callable<AsyncNotifier.NextAction> { @Override public synchronized AsyncNotifier.NextAction call() { - try (CloseableHttpClient client = HttpClients.createDefault()) { - HttpPost request = createPostRequest(endpoint, itemIds, userId); - try (CloseableHttpResponse response = client.execute(request)) { - StatusLine status = response.getStatusLine(); - - LOGGER.debug("Catalog notification on VSP IDs: {}, endpoint: {}, response: {}", - itemIds, endpoint, status); - + LOGGER.debug("Catalog notification on VSP IDs: {}, endpoint: {}, response: {}", itemIds, endpoint, status); itemIds = getFailedIds(itemIds, response.getEntity()); - - if ((status.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) - && (itemIds != null) && !itemIds.isEmpty()) { - + if ((status.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) && (itemIds != null) && !itemIds.isEmpty()) { LOGGER.debug("Catalog notification on VSP IDs {} failed. Endpoint: {}. Retry", itemIds, endpoint); return RETRY; } - return DONE; } - } catch (Exception e) { LOGGER.error("Catalog notification on VSP IDs {} failed. Endpoint: {}", itemIds, endpoint, e); return DONE; } } - private HttpPost createPostRequest(String postUrl, Collection<String> itemIds, String userId) - throws UnsupportedEncodingException { - + private HttpPost createPostRequest(String postUrl, Collection<String> itemIds, String userId) throws UnsupportedEncodingException { HttpPost request = new HttpPost(postUrl); - request.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON); request.addHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); request.addHeader(USER_ID_HEADER_PARAM, userId); - HttpEntity entity = new StringEntity(JsonUtil.object2Json(itemIds)); request.setEntity(entity); return request; } private Collection<String> getFailedIds(Collection<String> itemIds, HttpEntity responseBody) { - try { NotificationResponse response = JsonUtil.json2Object(responseBody.getContent(), NotificationResponse.class); return response != null ? response.failedIds : null; } catch (Exception e) { LOGGER.error("Error getting failed IDs from response", e); } - return itemIds; } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java index d210dc21af..694aa9241c 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.item.rest.services.catalog.notification.http; import java.util.Collection; @@ -35,11 +34,9 @@ import org.openecomp.sdcrests.item.types.ItemAction; * @author evitaliy * @since 21 Nov 2018 */ -public class HttpTaskProducer - implements BiFunction<Collection<String>, ItemAction, Callable<AsyncNotifier.NextAction>>, Notifier { +public class HttpTaskProducer implements BiFunction<Collection<String>, ItemAction, Callable<AsyncNotifier.NextAction>>, Notifier { private static final Logger LOGGER = LoggerFactory.getLogger(HttpTaskProducer.class); - private static final String CATALOG_HTTP_PROTOCOL = "HTTP"; private static final String CATALOG_HTTPS_PROTOCOL = "HTTPS"; private static final Map<ItemAction, String> ACTION_PATHS; @@ -66,16 +63,13 @@ public class HttpTaskProducer } private static String ensureEntryConfigured(String value, String entryName) { - if (value == null) { throw new EntryNotConfiguredException(entryName); } - return value; } private static String getPortConfiguration(String protocol, HttpConfiguration config) { - if (CATALOG_HTTP_PROTOCOL.equalsIgnoreCase(protocol)) { return ensureEntryConfigured(config.getCatalogBeHttpPort(), "HTTP port"); } else if (CATALOG_HTTPS_PROTOCOL.equalsIgnoreCase(protocol)) { @@ -85,6 +79,14 @@ public class HttpTaskProducer } } + static String getApiPath(ItemAction action) { + String path = ACTION_PATHS.get(action); + if (path == null) { + throw new IllegalArgumentException("Unsupported action: " + action.name()); + } + return path; + } + @Override public Callable<AsyncNotifier.NextAction> apply(Collection<String> itemIds, ItemAction action) { return createNotificationTask(itemIds, action); @@ -97,20 +99,9 @@ public class HttpTaskProducer return new HttpNotificationTask(notificationEndpoint, userId, itemIds); } - static String getApiPath(ItemAction action) { - - String path = ACTION_PATHS.get(action); - if (path == null) { - throw new IllegalArgumentException("Unsupported action: " + action.name()); - } - - return path; - } - @Override public void execute(Collection<String> itemIds, ItemAction action) { HttpNotificationTask task = createNotificationTask(itemIds, action); task.call(); } - } |