Skip to content

Commit

Permalink
Merge pull request #86 from catenax-ng/CX_R24.03_Policy_hub
Browse files Browse the repository at this point in the history
[feat|sde-backend] : Policy-hub Proxy controller and Policy pojo added
  • Loading branch information
almadigabor authored Feb 16, 2024
2 parents 721cff0 + 4aaa261 commit 0f7b838
Show file tree
Hide file tree
Showing 20 changed files with 867 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] - 2023-02-06
## [Unreleased] - 2023-02-10

### Added

- Policy-Hub service api integration.
- Added New Policy Entities and pojo classes.

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/********************************************************************************
* Copyright (c) 2024 T-Systems International GmbH
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.common.entities;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Transient;
import lombok.Data;

@Data
@MappedSuperclass
@JsonIgnoreProperties(ignoreUnknown = true)
public class CommonPropEntity {

@Transient
@JsonProperty(value = "row_number")
private Integer rowNumber;

@Column(name = "process_id")
@JsonProperty(value = "process_id")
private String processId;

@Column(name = "shell_id")
@JsonProperty(value = "shell_id")
private String shellId;

@Column(name = "sub_model_id")
@JsonProperty(value = "sub_model_id")
private String subModelId;

@Column(name = "usage_policy_id")
@JsonProperty(value = "usage_policy_id")
private String usagePolicyId;

@Column(name = "asset_id")
@JsonProperty(value = "asset_id")
private String assetId;

@Column(name = "access_policy_id")
@JsonProperty(value = "access_policy_id")
private String accessPolicyId;

@Column(name = "contract_defination_id")
@JsonProperty(value = "contract_defination_id")
private String contractDefinationId;

@Column(name = "deleted")
@JsonProperty(value = "deleted")
private String deleted;

@Column(name = "updated")
@JsonProperty(value = "updated")
private String updated;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/********************************************************************************
* Copyright (c) 2024 T-Systems International GmbH
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.sde.common.entities;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class Policies {

private String technicalKey;
private List<String> value;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/********************************************************************************
* Copyright (c) 2024 T-Systems International GmbH
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.common.entities;

import java.time.LocalDateTime;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class PolicyModel {

private String uuid;

@JsonProperty(value = "policy_name")
private String policyName;

@JsonProperty(value = "access_policies")
private List<Policies> accessPolicies;

@JsonProperty(value = "usage_policies")
private List<Policies> usagePolicies;

private LocalDateTime lastUpdatedTime;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/********************************************************************************
* Copyright (c) 2024 T-Systems International GmbH
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.common.entities;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@EqualsAndHashCode(callSuper = true)
public class PolicyTemplateRequest extends PolicyModel {

@Builder.Default
private PolicyTemplateType type = PolicyTemplateType.NONE;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (c) 2024 T-Systems International GmbH
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.common.entities;

public enum PolicyTemplateType {
NONE, EXISTING, NEW
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/********************************************************************************
* Copyright (c) 2024 T-Systems International GmbH
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.sde.common.entities;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.node.ObjectNode;

import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@EqualsAndHashCode(callSuper = true)
public class SubmodelJsonReq extends PolicyTemplateRequest {

@NotEmpty
@JsonProperty(value = "row_data")
private List<ObjectNode> rowData;

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/********************************************************************************
* Copyright (c) 2022 Critical TechWorks GmbH
* Copyright (c) 2022 BMW GmbH
* Copyright (c) 2022, 2023 T-Systems International GmbH
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 T-Systems International GmbH
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -25,5 +25,6 @@
public enum ProgressStatusEnum {
IN_PROGRESS,
COMPLETED,
FAILED
FAILED,
PARTIALLY_FAILED
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2023 T-Systems International GmbH
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 T-Systems International GmbH
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -27,6 +27,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
Expand Down Expand Up @@ -90,7 +91,7 @@ public ResponseEntity<Map<String, String>> handleFeignException(FeignException e
log.error("FeignException JsonProcessingException " + e.getMessage());
}

return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(errorResponse, HttpStatus.valueOf(ex.status()));
}

@ExceptionHandler(ConstraintViolationException.class)
Expand All @@ -111,7 +112,16 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotV
errors.put(fieldName, errorMessage);
});
log.error("MethodArgumentNotValidException " + errors);
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
Map<String, String> errorResponse = prepareErrorResponse(errors.toString());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
HttpHeaders headers, HttpStatusCode status, WebRequest request) {
log.error("HandleHttpMessageNotReadable " + ex.getMessage());
Map<String, String> errorResponse = prepareErrorResponse(ex.getMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(AccessDeniedException.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2023 T-Systems International GmbH
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 T-Systems International GmbH
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -32,6 +32,6 @@ public class ServiceException extends Exception {

public ServiceException(String exceptionstr) {
super(exceptionstr);
log.debug(exceptionstr);
log.info(exceptionstr);
}
}
Loading

0 comments on commit 0f7b838

Please sign in to comment.