Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
Merge branch 'Demo_branch' into feature/DCMFOSS-70
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogo12246 authored Nov 15, 2023
2 parents 07cec56 + 115ea41 commit 8979a93
Show file tree
Hide file tree
Showing 42 changed files with 1,065 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* ******************************************************************************
* Copyright (c) 2023 BMW AG
* Copyright (c) 2023 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.demandcapacitymgmt.demandcapacitymgmtbackend.controllers;

import eclipse.tractusx.demand_capacity_mgmt_specification.api.AddressBookApi;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookResponse;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.AddressBookService;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@AllArgsConstructor
public class AddressBookController implements AddressBookApi {

private final AddressBookService service;
private HttpServletRequest request;

@Override
public ResponseEntity<Void> deleteAddressBook(AddressBookRequest addressBookRequest) throws Exception {
if(UserUtil.getUserRole(request).equals(Role.ADMIN)){
service.deleteRecord(addressBookRequest);
return ResponseEntity.status(201).build();
}
return ResponseEntity.status(401).build();

}

@Override
public ResponseEntity<AddressBookResponse> getAddressBook(AddressBookRequest addressBookRequest) throws Exception {
return ResponseEntity.status(200).body(service.getRecord(addressBookRequest));
}

@Override
public ResponseEntity<List<AddressBookResponse>> getAllAddressBooks() throws Exception {
return ResponseEntity.status(200).body(service.getRecords());
}

@Override
public ResponseEntity<AddressBookResponse> postAddressBook(AddressBookRequest addressBookRequest) throws Exception {
return ResponseEntity.status(200).body(service.postRecord(addressBookRequest));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
import eclipse.tractusx.demand_capacity_mgmt_specification.api.CapacityGroupApi;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import lombok.AllArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.CapacityGroupService;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
public class CapacityGroupsController implements CapacityGroupApi {
Expand All @@ -43,7 +45,8 @@ public class CapacityGroupsController implements CapacityGroupApi {
@Override
public ResponseEntity<List<CapacityGroupDefaultViewResponse>> getCapacityGroups() {
String userID = UserUtil.getUserID(request);
List<CapacityGroupDefaultViewResponse> capacityGroupDefaultViewResponses = service.getAll(userID);
Role userRole = UserUtil.getUserRole(request);
List<CapacityGroupDefaultViewResponse> capacityGroupDefaultViewResponses = service.getAll(userID,userRole);
return ResponseEntity.status(HttpStatus.OK).body(capacityGroupDefaultViewResponses);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.controllers;

import eclipse.tractusx.demand_capacity_mgmt_specification.api.UserOperationsApi;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.UserRequest;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.UserOperationsService;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.utils.UserUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
public class UserController implements UserOperationsApi {

private final UserOperationsService service;
private HttpServletRequest request;

@Override
public ResponseEntity<Void> updateAnUser(UserRequest userRequest) throws Exception {
service.updateUser(userRequest);
return ResponseEntity.status(201).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* ******************************************************************************
* Copyright (c) 2023 BMW AG
* Copyright (c) 2023 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.demandcapacitymgmt.demandcapacitymgmtbackend.entities;


import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Entity
@Table(name = "address_book")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AddressBookRecordEntity {

@Id
@GeneratedValue
@Column(columnDefinition = "uuid", updatable = false, name = "id")
private UUID id;

@Column(name = "company_id")
private UUID companyId;

@Column(name = "name")
private String name;

@Column(name = "contact")
private String contact;

@Column(name = "email")
private String email;

@Column(name = "function")
private String function;

@Column(name = "picture")
private byte[] picture;

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class UserEntity {
@Column(name = "username")
private String username;

@Column(name = "company_id")
private UUID companyID;

@Column(name = "role", columnDefinition = "varchar")
@Enumerated(EnumType.STRING)
private Role role;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public enum FavoriteType {
COMPANY_BASE_DATA,
MATERIAL_DEMAND,
EVENT,
ADDRESS_BOOK
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* *******************************************************************************
* Copyright (c) 2023 BMW AG
* Copyright (c) 2023 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.demandcapacitymgmt.demandcapacitymgmtbackend.repositories;

import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface AddressBookRepository extends JpaRepository<AddressBookRecordEntity, UUID> {
List<AddressBookRecordEntity> findByNameOrCompanyId(@NonNull String name, @NonNull UUID companyId);}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* ******************************************************************************
* Copyright (c) 2023 BMW AG
* Copyright (c) 2023 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.demandcapacitymgmt.demandcapacitymgmtbackend.services;

import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookRequest;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.AddressBookResponse;

import java.util.List;

public interface AddressBookService {
AddressBookResponse getRecord(AddressBookRequest request);

List<AddressBookResponse> getRecords();

AddressBookResponse postRecord(AddressBookRequest request);

void deleteRecord(AddressBookRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services;

import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role;

import java.util.List;

public interface CapacityGroupService {
Expand All @@ -31,5 +33,5 @@ public interface CapacityGroupService {
void linkCapacityGroupToMaterialDemand(LinkCGDSRequest linkCGDSRequest, String userID);

SingleCapacityGroup getCapacityGroupById(String CapacityGroupId);
List<CapacityGroupDefaultViewResponse> getAll(String userID);
List<CapacityGroupDefaultViewResponse> getAll(String userID, Role role);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* ******************************************************************************
* Copyright (c) 2023 BMW AG
* Copyright (c) 2023 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.demandcapacitymgmt.demandcapacitymgmtbackend.services;

import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.AddressBookRecordEntity;

public interface GoldenRecordManager {
AddressBookRecordEntity queryGoldenRecord(String recordQuery);

AddressBookRecordEntity createRecord(String query);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services;

import eclipse.tractusx.demand_capacity_mgmt_specification.model.UserRequest;

public interface UserOperationsService {
void updateUser(UserRequest request);
}
Loading

0 comments on commit 8979a93

Please sign in to comment.