-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mailService): added mail service
- Loading branch information
1 parent
f22d010
commit 69af79e
Showing
13 changed files
with
404 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 BMW Group AG | ||
* Copyright (c) 2021, 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 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Mailing.Service; | ||
|
||
public interface IRoleBaseMailService | ||
{ | ||
public Task RoleBaseSendMail(IEnumerable<UserRoleConfig> receiverRoles, IDictionary<string, string> parameters, IEnumerable<string> template, Guid companyId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- | ||
- Copyright (c) 2021, 2023 BMW Group AG | ||
- Copyright (c) 2021, 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 | ||
--> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\portalbackend\PortalBackend.DBAccess\PortalBackend.DBAccess.csproj" /> | ||
<ProjectReference Include="..\..\portalbackend\PortalBackend.PortalEntities\PortalBackend.PortalEntities.csproj" /> | ||
<ProjectReference Include="..\..\framework\Framework.Models\Framework.Models.csproj" /> | ||
<ProjectReference Include="..\Mailing.SendMail\Mailing.SendMail.csproj" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.Mailing.Service</AssemblyName> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 BMW Group AG | ||
* Copyright (c) 2021, 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 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; | ||
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; | ||
using Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Mailing.Service; | ||
|
||
public class RoleBaseMailService : IRoleBaseMailService | ||
{ | ||
|
||
private readonly IPortalRepositories _portalRepositories; | ||
private readonly IMailingService _mailingService; | ||
|
||
public RoleBaseMailService(IPortalRepositories portalRepositories, IMailingService mailingService) | ||
{ | ||
_portalRepositories = portalRepositories; | ||
_mailingService = mailingService; | ||
} | ||
public async Task RoleBaseSendMail(IEnumerable<UserRoleConfig> receiverRoles, IDictionary<string, string> parameters, IEnumerable<string> template, Guid companyId) | ||
{ | ||
var receiverUserRoles = receiverRoles; | ||
var userRolesRepository = _portalRepositories.GetInstance<IUserRolesRepository>(); | ||
var roleData = await userRolesRepository | ||
.GetUserRoleIdsUntrackedAsync(receiverUserRoles) | ||
.ToListAsync() | ||
.ConfigureAwait(false); | ||
if (roleData.Count < receiverUserRoles.Sum(clientRoles => clientRoles.UserRoleNames.Count())) | ||
{ | ||
throw new ConfigurationException( | ||
$"invalid configuration, at least one of the configured roles does not exist in the database: {string.Join(", ", receiverUserRoles.Select(clientRoles => $"client: {clientRoles.ClientId}, roles: [{string.Join(", ", clientRoles.UserRoleNames)}]"))}"); | ||
} | ||
|
||
var companyUserWithRoleIdForCompany = _portalRepositories.GetInstance<IUserRepository>() | ||
.GetCompanyUserEmailForCompanyAndRoleId(roleData, companyId); | ||
await foreach (var (receiver, firstName, lastName) in companyUserWithRoleIdForCompany) | ||
{ | ||
var userName = string.Join(" ", new[] { firstName, lastName }.Where(item => !string.IsNullOrWhiteSpace(item))); | ||
|
||
if (!string.IsNullOrWhiteSpace(userName) && parameters.Keys.Contains("offerProviderName")) | ||
{ | ||
parameters["offerProviderName"] = userName; | ||
} | ||
|
||
await _mailingService.SendMails(receiver, parameters, template).ConfigureAwait(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.